Changes in 4.9.137 bcache: fix miss key refill->end in writeback hwmon: (pmbus) Fix page count auto-detection. jffs2: free jffs2_sb_info through jffs2_kill_sb() pcmcia: Implement CLKRUN protocol disabling for Ricoh bridges ipmi: Fix timer race with module unload parisc: Fix address in HPMC IVA parisc: Fix map_pages() to not overwrite existing pte entries ALSA: hda - Add quirk for ASUS G751 laptop ALSA: hda - Fix headphone pin config for ASUS G751 ALSA: hda - Add mic quirk for the Lenovo G50-30 (17aa:3905) ALSA: ca0106: Disable IZD on SB0570 DAC to fix audio pops x86/speculation: Enable cross-hyperthread spectre v2 STIBP mitigation x86/corruption-check: Fix panic in memory_corruption_check() when boot option without value is provided x86/speculation: Support Enhanced IBRS on future CPUs bpf: do not blindly change rlimit in reuseport net selftest Revert "perf tools: Fix PMU term format max value calculation" xfrm: policy: use hlist rcu variants on insert sparc: Fix single-pcr perf event counter management. sparc64: Make proc_id signed. sched/fair: Fix the min_vruntime update logic in dequeue_entity() perf cpu_map: Align cpu map synthesized events properly. x86/fpu: Remove second definition of fpu in __fpu__restore_sig() net: qla3xxx: Remove overflowing shift statement selftests: ftrace: Add synthetic event syntax testcase i2c: rcar: cleanup DMA for all kinds of failure locking/lockdep: Fix debug_locks off performance problem ataflop: fix error handling during setup swim: fix cleanup on setup error tun: Consistently configure generic netdev params via rtnetlink s390/sthyi: Fix machine name validity indication hwmon: (pwm-fan) Set fan speed to 0 on suspend perf tools: Free temporary 'sys' string in read_event_files() perf tools: Cleanup trace-event-info 'tdata' leak perf strbuf: Match va_{add,copy} with va_end mmc: sdhci-pci-o2micro: Add quirk for O2 Micro dev 0x8620 rev 0x01 iwlwifi: pcie: avoid empty free RB queue x86/olpc: Indicate that legacy PC XO-1 platform should not register RTC cpufreq: dt: Try freeing static OPPs only if we have added them Bluetooth: btbcm: Add entry for BCM4335C0 UART bluetooth x86: boot: Fix EFI stub alignment pinctrl: qcom: spmi-mpp: Fix err handling of pmic_mpp_set_mux brcmfmac: fix for proper support of 160MHz bandwidth kprobes: Return error if we fail to reuse kprobe instead of BUG_ON() ACPI / LPSS: Add alternative ACPI HIDs for Cherry Trail DMA controllers pinctrl: qcom: spmi-mpp: Fix drive strength setting pinctrl: spmi-mpp: Fix pmic_mpp_config_get() to be compliant pinctrl: ssbi-gpio: Fix pm8xxx_pin_config_get() to be compliant ixgbevf: VF2VF TCP RSS ath10k: schedule hardware restart if WMI command times out cgroup, netclassid: add a preemption point to write_classid scsi: esp_scsi: Track residual for PIO transfers scsi: megaraid_sas: fix a missing-check bug RDMA/core: Do not expose unsupported counters IB/ipoib: Clear IPCB before icmp_send tpm: suppress transmit cmd error logs when TPM 1.2 is disabled/deactivated VMCI: Resource wildcard match fixed usb: gadget: udc: atmel: handle at91sam9rl PMC ext4: fix argument checking in EXT4_IOC_MOVE_EXT MD: fix invalid stored role for a disk PCI/MSI: Warn and return error if driver enables MSI/MSI-X twice coresight: etb10: Fix handling of perf mode crypto: caam - fix implicit casts in endianness helpers usb: chipidea: Prevent unbalanced IRQ disable driver/dma/ioat: Call del_timer_sync() without holding prep_lock uio: ensure class is registered before devices scsi: lpfc: Correct soft lockup when running mds diagnostics signal: Always deliver the kernel's SIGKILL and SIGSTOP to a pid namespace init dmaengine: dma-jz4780: Return error if not probed from DT ALSA: hda: Check the non-cached stream buffers more explicitly ARM: dts: exynos: Remove "cooling-{min|max}-level" for CPU nodes arm: dts: exynos: Add missing cooling device properties for CPUs ARM: dts: exynos: Convert exynos5250.dtsi to opp-v2 bindings ARM: dts: exynos: Mark 1 GHz CPU OPP as suspend OPP on Exynos5250 xen-swiotlb: use actually allocated size on check physical continuous tpm: Restore functionality to xen vtpm driver. xen/blkfront: avoid NULL blkfront_info dereference on device removal xen: fix race in xen_qlock_wait() xen: make xen_qlock_wait() nestable libertas: don't set URB_ZERO_PACKET on IN USB transfer usbip:vudc: BUG kmalloc-2048 (Not tainted): Poison overwritten iwlwifi: mvm: check return value of rs_rate_from_ucode_rate() net/ipv4: defensive cipso option parsing libnvdimm: Hold reference on parent while scheduling async init ASoC: intel: skylake: Add missing break in skl_tplg_get_token() jbd2: fix use after free in jbd2_log_do_checkpoint() gfs2_meta: ->mount() can get NULL dev_name ext4: initialize retries variable in ext4_da_write_inline_data_begin() ext4: propagate error from dquot_initialize() in EXT4_IOC_FSSETXATTR HID: hiddev: fix potential Spectre v1 EDAC, {i7core,sb,skx}_edac: Fix uncorrected error counting EDAC, skx_edac: Fix logical channel intermediate decoding PCI: Add Device IDs for Intel GPU "spurious interrupt" quirk signal/GenWQE: Fix sending of SIGKILL crypto: lrw - Fix out-of bounds access on counter overflow crypto: tcrypt - fix ghash-generic speed test ima: fix showing large 'violations' or 'runtime_measurements_count' hugetlbfs: dirty pages as they are added to pagecache kbuild: fix kernel/bounds.c 'W=1' warning iio: ad5064: Fix regulator handling iio: adc: imx25-gcq: Fix leak of device_node in mx25_gcq_setup_cfgs() iio: adc: at91: fix acking DRDY irq on simple conversions iio: adc: at91: fix wrong channel number in triggered buffer mode w1: omap-hdq: fix missing bus unregister at removal smb3: allow stats which track session and share reconnects to be reset smb3: do not attempt cifs operation in smb3 query info error path smb3: on kerberos mount if server doesn't specify auth type use krb5 printk: Fix panic caused by passing log_buf_len to command line genirq: Fix race on spurious interrupt detection NFSv4.1: Fix the r/wsize checking nfsd: Fix an Oops in free_session() lockd: fix access beyond unterminated strings in prints dm ioctl: harden copy_params()'s copy_from_user() from malicious users powerpc/msi: Fix compile error on mpc83xx MIPS: OCTEON: fix out of bounds array access on CN68XX TC: Set DMA masks for devices media: v4l2-tpg: fix kernel oops when enabling HFLIP and OSD kgdboc: Passing ekgdboc to command line causes panic xen: fix xen_qlock_wait() media: em28xx: use a default format if TRY_FMT fails media: tvp5150: avoid going past array on v4l2_querymenu() media: em28xx: fix input name for Terratec AV 350 media: em28xx: make v4l2-compliance happier by starting sequence on zero arm64: lse: remove -fcall-used-x0 flag rpmsg: smd: fix memory leak on channel create Cramfs: fix abad comparison when wrap-arounds occur arm64: dts: stratix10: Correct System Manager register size soc/tegra: pmc: Fix child-node lookup btrfs: Handle owner mismatch gracefully when walking up tree btrfs: locking: Add extra check in btrfs_init_new_buffer() to avoid deadlock btrfs: fix error handling in free_log_tree btrfs: iterate all devices during trim, instead of fs_devices::alloc_list btrfs: don't attempt to trim devices that don't support it btrfs: wait on caching when putting the bg cache btrfs: reset max_extent_size on clear in a bitmap btrfs: make sure we create all new block groups Btrfs: fix wrong dentries after fsync of file that got its parent replaced btrfs: qgroup: Dirty all qgroups before rescan Btrfs: fix null pointer dereference on compressed write path error btrfs: set max_extent_size properly MD: fix invalid stored role for a disk - try2 Linux 4.9.137 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
592 lines
11 KiB
C
592 lines
11 KiB
C
/*
|
|
* Copyright (C) 2008,2009, Steven Rostedt <srostedt@redhat.com>
|
|
*
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; version 2 of the License (not later!)
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
*/
|
|
#include "util.h"
|
|
#include <dirent.h>
|
|
#include <mntent.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdarg.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/wait.h>
|
|
#include <pthread.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <stdbool.h>
|
|
#include <linux/list.h>
|
|
#include <linux/kernel.h>
|
|
|
|
#include "../perf.h"
|
|
#include "trace-event.h"
|
|
#include <api/fs/tracing_path.h>
|
|
#include "evsel.h"
|
|
#include "debug.h"
|
|
|
|
#define VERSION "0.5"
|
|
|
|
static int output_fd;
|
|
|
|
|
|
int bigendian(void)
|
|
{
|
|
unsigned char str[] = { 0x1, 0x2, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0};
|
|
unsigned int *ptr;
|
|
|
|
ptr = (unsigned int *)(void *)str;
|
|
return *ptr == 0x01020304;
|
|
}
|
|
|
|
/* unfortunately, you can not stat debugfs or proc files for size */
|
|
static int record_file(const char *file, ssize_t hdr_sz)
|
|
{
|
|
unsigned long long size = 0;
|
|
char buf[BUFSIZ], *sizep;
|
|
off_t hdr_pos = lseek(output_fd, 0, SEEK_CUR);
|
|
int r, fd;
|
|
int err = -EIO;
|
|
|
|
fd = open(file, O_RDONLY);
|
|
if (fd < 0) {
|
|
pr_debug("Can't read '%s'", file);
|
|
return -errno;
|
|
}
|
|
|
|
/* put in zeros for file size, then fill true size later */
|
|
if (hdr_sz) {
|
|
if (write(output_fd, &size, hdr_sz) != hdr_sz)
|
|
goto out;
|
|
}
|
|
|
|
do {
|
|
r = read(fd, buf, BUFSIZ);
|
|
if (r > 0) {
|
|
size += r;
|
|
if (write(output_fd, buf, r) != r)
|
|
goto out;
|
|
}
|
|
} while (r > 0);
|
|
|
|
/* ugh, handle big-endian hdr_size == 4 */
|
|
sizep = (char*)&size;
|
|
if (bigendian())
|
|
sizep += sizeof(u64) - hdr_sz;
|
|
|
|
if (hdr_sz && pwrite(output_fd, sizep, hdr_sz, hdr_pos) < 0) {
|
|
pr_debug("writing file size failed\n");
|
|
goto out;
|
|
}
|
|
|
|
err = 0;
|
|
out:
|
|
close(fd);
|
|
return err;
|
|
}
|
|
|
|
static int record_header_files(void)
|
|
{
|
|
char *path;
|
|
struct stat st;
|
|
int err = -EIO;
|
|
|
|
path = get_tracing_file("events/header_page");
|
|
if (!path) {
|
|
pr_debug("can't get tracing/events/header_page");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
if (stat(path, &st) < 0) {
|
|
pr_debug("can't read '%s'", path);
|
|
goto out;
|
|
}
|
|
|
|
if (write(output_fd, "header_page", 12) != 12) {
|
|
pr_debug("can't write header_page\n");
|
|
goto out;
|
|
}
|
|
|
|
if (record_file(path, 8) < 0) {
|
|
pr_debug("can't record header_page file\n");
|
|
goto out;
|
|
}
|
|
|
|
put_tracing_file(path);
|
|
|
|
path = get_tracing_file("events/header_event");
|
|
if (!path) {
|
|
pr_debug("can't get tracing/events/header_event");
|
|
err = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
if (stat(path, &st) < 0) {
|
|
pr_debug("can't read '%s'", path);
|
|
goto out;
|
|
}
|
|
|
|
if (write(output_fd, "header_event", 13) != 13) {
|
|
pr_debug("can't write header_event\n");
|
|
goto out;
|
|
}
|
|
|
|
if (record_file(path, 8) < 0) {
|
|
pr_debug("can't record header_event file\n");
|
|
goto out;
|
|
}
|
|
|
|
err = 0;
|
|
out:
|
|
put_tracing_file(path);
|
|
return err;
|
|
}
|
|
|
|
static bool name_in_tp_list(char *sys, struct tracepoint_path *tps)
|
|
{
|
|
while (tps) {
|
|
if (!strcmp(sys, tps->name))
|
|
return true;
|
|
tps = tps->next;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
static int copy_event_system(const char *sys, struct tracepoint_path *tps)
|
|
{
|
|
struct dirent *dent;
|
|
struct stat st;
|
|
char *format;
|
|
DIR *dir;
|
|
int count = 0;
|
|
int ret;
|
|
int err;
|
|
|
|
dir = opendir(sys);
|
|
if (!dir) {
|
|
pr_debug("can't read directory '%s'", sys);
|
|
return -errno;
|
|
}
|
|
|
|
while ((dent = readdir(dir))) {
|
|
if (dent->d_type != DT_DIR ||
|
|
strcmp(dent->d_name, ".") == 0 ||
|
|
strcmp(dent->d_name, "..") == 0 ||
|
|
!name_in_tp_list(dent->d_name, tps))
|
|
continue;
|
|
if (asprintf(&format, "%s/%s/format", sys, dent->d_name) < 0) {
|
|
err = -ENOMEM;
|
|
goto out;
|
|
}
|
|
ret = stat(format, &st);
|
|
free(format);
|
|
if (ret < 0)
|
|
continue;
|
|
count++;
|
|
}
|
|
|
|
if (write(output_fd, &count, 4) != 4) {
|
|
err = -EIO;
|
|
pr_debug("can't write count\n");
|
|
goto out;
|
|
}
|
|
|
|
rewinddir(dir);
|
|
while ((dent = readdir(dir))) {
|
|
if (dent->d_type != DT_DIR ||
|
|
strcmp(dent->d_name, ".") == 0 ||
|
|
strcmp(dent->d_name, "..") == 0 ||
|
|
!name_in_tp_list(dent->d_name, tps))
|
|
continue;
|
|
if (asprintf(&format, "%s/%s/format", sys, dent->d_name) < 0) {
|
|
err = -ENOMEM;
|
|
goto out;
|
|
}
|
|
ret = stat(format, &st);
|
|
|
|
if (ret >= 0) {
|
|
err = record_file(format, 8);
|
|
if (err) {
|
|
free(format);
|
|
goto out;
|
|
}
|
|
}
|
|
free(format);
|
|
}
|
|
err = 0;
|
|
out:
|
|
closedir(dir);
|
|
return err;
|
|
}
|
|
|
|
static int record_ftrace_files(struct tracepoint_path *tps)
|
|
{
|
|
char *path;
|
|
int ret;
|
|
|
|
path = get_tracing_file("events/ftrace");
|
|
if (!path) {
|
|
pr_debug("can't get tracing/events/ftrace");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
ret = copy_event_system(path, tps);
|
|
|
|
put_tracing_file(path);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static bool system_in_tp_list(char *sys, struct tracepoint_path *tps)
|
|
{
|
|
while (tps) {
|
|
if (!strcmp(sys, tps->system))
|
|
return true;
|
|
tps = tps->next;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
static int record_event_files(struct tracepoint_path *tps)
|
|
{
|
|
struct dirent *dent;
|
|
struct stat st;
|
|
char *path;
|
|
char *sys;
|
|
DIR *dir;
|
|
int count = 0;
|
|
int ret;
|
|
int err;
|
|
|
|
path = get_tracing_file("events");
|
|
if (!path) {
|
|
pr_debug("can't get tracing/events");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
dir = opendir(path);
|
|
if (!dir) {
|
|
err = -errno;
|
|
pr_debug("can't read directory '%s'", path);
|
|
goto out;
|
|
}
|
|
|
|
while ((dent = readdir(dir))) {
|
|
if (dent->d_type != DT_DIR ||
|
|
strcmp(dent->d_name, ".") == 0 ||
|
|
strcmp(dent->d_name, "..") == 0 ||
|
|
strcmp(dent->d_name, "ftrace") == 0 ||
|
|
!system_in_tp_list(dent->d_name, tps))
|
|
continue;
|
|
count++;
|
|
}
|
|
|
|
if (write(output_fd, &count, 4) != 4) {
|
|
err = -EIO;
|
|
pr_debug("can't write count\n");
|
|
goto out;
|
|
}
|
|
|
|
rewinddir(dir);
|
|
while ((dent = readdir(dir))) {
|
|
if (dent->d_type != DT_DIR ||
|
|
strcmp(dent->d_name, ".") == 0 ||
|
|
strcmp(dent->d_name, "..") == 0 ||
|
|
strcmp(dent->d_name, "ftrace") == 0 ||
|
|
!system_in_tp_list(dent->d_name, tps))
|
|
continue;
|
|
if (asprintf(&sys, "%s/%s", path, dent->d_name) < 0) {
|
|
err = -ENOMEM;
|
|
goto out;
|
|
}
|
|
ret = stat(sys, &st);
|
|
if (ret >= 0) {
|
|
ssize_t size = strlen(dent->d_name) + 1;
|
|
|
|
if (write(output_fd, dent->d_name, size) != size ||
|
|
copy_event_system(sys, tps) < 0) {
|
|
err = -EIO;
|
|
free(sys);
|
|
goto out;
|
|
}
|
|
}
|
|
free(sys);
|
|
}
|
|
err = 0;
|
|
out:
|
|
closedir(dir);
|
|
put_tracing_file(path);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int record_proc_kallsyms(void)
|
|
{
|
|
unsigned long long size = 0;
|
|
/*
|
|
* Just to keep older perf.data file parsers happy, record a zero
|
|
* sized kallsyms file, i.e. do the same thing that was done when
|
|
* /proc/kallsyms (or something specified via --kallsyms, in a
|
|
* different path) couldn't be read.
|
|
*/
|
|
return write(output_fd, &size, 4) != 4 ? -EIO : 0;
|
|
}
|
|
|
|
static int record_ftrace_printk(void)
|
|
{
|
|
unsigned int size;
|
|
char *path;
|
|
struct stat st;
|
|
int ret, err = 0;
|
|
|
|
path = get_tracing_file("printk_formats");
|
|
if (!path) {
|
|
pr_debug("can't get tracing/printk_formats");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
ret = stat(path, &st);
|
|
if (ret < 0) {
|
|
/* not found */
|
|
size = 0;
|
|
if (write(output_fd, &size, 4) != 4)
|
|
err = -EIO;
|
|
goto out;
|
|
}
|
|
err = record_file(path, 4);
|
|
|
|
out:
|
|
put_tracing_file(path);
|
|
return err;
|
|
}
|
|
|
|
static void
|
|
put_tracepoints_path(struct tracepoint_path *tps)
|
|
{
|
|
while (tps) {
|
|
struct tracepoint_path *t = tps;
|
|
|
|
tps = tps->next;
|
|
zfree(&t->name);
|
|
zfree(&t->system);
|
|
free(t);
|
|
}
|
|
}
|
|
|
|
static struct tracepoint_path *
|
|
get_tracepoints_path(struct list_head *pattrs)
|
|
{
|
|
struct tracepoint_path path, *ppath = &path;
|
|
struct perf_evsel *pos;
|
|
int nr_tracepoints = 0;
|
|
|
|
list_for_each_entry(pos, pattrs, node) {
|
|
if (pos->attr.type != PERF_TYPE_TRACEPOINT)
|
|
continue;
|
|
++nr_tracepoints;
|
|
|
|
if (pos->name) {
|
|
ppath->next = tracepoint_name_to_path(pos->name);
|
|
if (ppath->next)
|
|
goto next;
|
|
|
|
if (strchr(pos->name, ':') == NULL)
|
|
goto try_id;
|
|
|
|
goto error;
|
|
}
|
|
|
|
try_id:
|
|
ppath->next = tracepoint_id_to_path(pos->attr.config);
|
|
if (!ppath->next) {
|
|
error:
|
|
pr_debug("No memory to alloc tracepoints list\n");
|
|
put_tracepoints_path(&path);
|
|
return NULL;
|
|
}
|
|
next:
|
|
ppath = ppath->next;
|
|
}
|
|
|
|
return nr_tracepoints > 0 ? path.next : NULL;
|
|
}
|
|
|
|
bool have_tracepoints(struct list_head *pattrs)
|
|
{
|
|
struct perf_evsel *pos;
|
|
|
|
list_for_each_entry(pos, pattrs, node)
|
|
if (pos->attr.type == PERF_TYPE_TRACEPOINT)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
static int tracing_data_header(void)
|
|
{
|
|
char buf[20];
|
|
ssize_t size;
|
|
|
|
/* just guessing this is someone's birthday.. ;) */
|
|
buf[0] = 23;
|
|
buf[1] = 8;
|
|
buf[2] = 68;
|
|
memcpy(buf + 3, "tracing", 7);
|
|
|
|
if (write(output_fd, buf, 10) != 10)
|
|
return -1;
|
|
|
|
size = strlen(VERSION) + 1;
|
|
if (write(output_fd, VERSION, size) != size)
|
|
return -1;
|
|
|
|
/* save endian */
|
|
if (bigendian())
|
|
buf[0] = 1;
|
|
else
|
|
buf[0] = 0;
|
|
|
|
if (write(output_fd, buf, 1) != 1)
|
|
return -1;
|
|
|
|
/* save size of long */
|
|
buf[0] = sizeof(long);
|
|
if (write(output_fd, buf, 1) != 1)
|
|
return -1;
|
|
|
|
/* save page_size */
|
|
if (write(output_fd, &page_size, 4) != 4)
|
|
return -1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
struct tracing_data *tracing_data_get(struct list_head *pattrs,
|
|
int fd, bool temp)
|
|
{
|
|
struct tracepoint_path *tps;
|
|
struct tracing_data *tdata;
|
|
int err;
|
|
|
|
output_fd = fd;
|
|
|
|
tps = get_tracepoints_path(pattrs);
|
|
if (!tps)
|
|
return NULL;
|
|
|
|
tdata = malloc(sizeof(*tdata));
|
|
if (!tdata)
|
|
return NULL;
|
|
|
|
tdata->temp = temp;
|
|
tdata->size = 0;
|
|
|
|
if (temp) {
|
|
int temp_fd;
|
|
|
|
snprintf(tdata->temp_file, sizeof(tdata->temp_file),
|
|
"/tmp/perf-XXXXXX");
|
|
if (!mkstemp(tdata->temp_file)) {
|
|
pr_debug("Can't make temp file");
|
|
free(tdata);
|
|
return NULL;
|
|
}
|
|
|
|
temp_fd = open(tdata->temp_file, O_RDWR);
|
|
if (temp_fd < 0) {
|
|
pr_debug("Can't read '%s'", tdata->temp_file);
|
|
free(tdata);
|
|
return NULL;
|
|
}
|
|
|
|
/*
|
|
* Set the temp file the default output, so all the
|
|
* tracing data are stored into it.
|
|
*/
|
|
output_fd = temp_fd;
|
|
}
|
|
|
|
err = tracing_data_header();
|
|
if (err)
|
|
goto out;
|
|
err = record_header_files();
|
|
if (err)
|
|
goto out;
|
|
err = record_ftrace_files(tps);
|
|
if (err)
|
|
goto out;
|
|
err = record_event_files(tps);
|
|
if (err)
|
|
goto out;
|
|
err = record_proc_kallsyms();
|
|
if (err)
|
|
goto out;
|
|
err = record_ftrace_printk();
|
|
|
|
out:
|
|
/*
|
|
* All tracing data are stored by now, we can restore
|
|
* the default output file in case we used temp file.
|
|
*/
|
|
if (temp) {
|
|
tdata->size = lseek(output_fd, 0, SEEK_CUR);
|
|
close(output_fd);
|
|
output_fd = fd;
|
|
}
|
|
|
|
if (err)
|
|
zfree(&tdata);
|
|
|
|
put_tracepoints_path(tps);
|
|
return tdata;
|
|
}
|
|
|
|
int tracing_data_put(struct tracing_data *tdata)
|
|
{
|
|
int err = 0;
|
|
|
|
if (tdata->temp) {
|
|
err = record_file(tdata->temp_file, 0);
|
|
unlink(tdata->temp_file);
|
|
}
|
|
|
|
free(tdata);
|
|
return err;
|
|
}
|
|
|
|
int read_tracing_data(int fd, struct list_head *pattrs)
|
|
{
|
|
int err;
|
|
struct tracing_data *tdata;
|
|
|
|
/*
|
|
* We work over the real file, so we can write data
|
|
* directly, no temp file is needed.
|
|
*/
|
|
tdata = tracing_data_get(pattrs, fd, false);
|
|
if (!tdata)
|
|
return -ENOMEM;
|
|
|
|
err = tracing_data_put(tdata);
|
|
return err;
|
|
}
|