blob: 81c673282ed4dd4aa521324c19e4cbaf4a169d3d [file] [log] [blame]
Steven Rostedt520509432009-08-17 16:18:05 +02001/*
2 * Copyright (C) 2008,2009, Steven Rostedt <srostedt@redhat.com>
3 *
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License (not later!)
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 */
Arnaldo Carvalho de Meloc168fbf2011-11-16 12:55:59 -020021#include "util.h"
Steven Rostedt520509432009-08-17 16:18:05 +020022#include <dirent.h>
Ulrich Drepper659d8cf2009-12-19 16:40:28 -050023#include <mntent.h>
Steven Rostedt520509432009-08-17 16:18:05 +020024#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <stdarg.h>
28#include <sys/types.h>
29#include <sys/stat.h>
30#include <sys/wait.h>
31#include <pthread.h>
32#include <fcntl.h>
33#include <unistd.h>
Steven Rostedt520509432009-08-17 16:18:05 +020034#include <errno.h>
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +020035#include <stdbool.h>
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020036#include <linux/list.h>
Arnaldo Carvalho de Meloe2561362009-11-21 14:31:26 -020037#include <linux/kernel.h>
Steven Rostedt520509432009-08-17 16:18:05 +020038
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +020039#include "../perf.h"
Steven Rostedt520509432009-08-17 16:18:05 +020040#include "trace-event.h"
Borislav Petkov85c66be2013-02-20 16:32:30 +010041#include <lk/debugfs.h>
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -020042#include "evsel.h"
Steven Rostedt520509432009-08-17 16:18:05 +020043
Steven Rostedt520509432009-08-17 16:18:05 +020044#define VERSION "0.5"
45
Steven Rostedt520509432009-08-17 16:18:05 +020046static const char *output_file = "trace.info";
47static int output_fd;
48
Steven Rostedt520509432009-08-17 16:18:05 +020049
Steven Rostedtaaf045f2012-04-06 00:47:56 +020050static void *malloc_or_die(unsigned int size)
Steven Rostedt520509432009-08-17 16:18:05 +020051{
52 void *data;
53
54 data = malloc(size);
55 if (!data)
56 die("malloc");
57 return data;
58}
59
60static const char *find_debugfs(void)
61{
Borislav Petkov13559152013-02-20 16:32:31 +010062 const char *path = perf_debugfs_mount(NULL);
Steven Rostedt520509432009-08-17 16:18:05 +020063
Xiao Guangrong61be3e52009-12-28 16:48:30 +080064 if (!path)
Namhyung Kim454f8c72013-03-21 16:18:44 +090065 pr_debug("Your kernel does not support the debugfs filesystem");
Steven Rostedt520509432009-08-17 16:18:05 +020066
Xiao Guangrong61be3e52009-12-28 16:48:30 +080067 return path;
Steven Rostedt520509432009-08-17 16:18:05 +020068}
69
70/*
71 * Finds the path to the debugfs/tracing
72 * Allocates the string and stores it.
73 */
74static const char *find_tracing_dir(void)
75{
76 static char *tracing;
77 static int tracing_found;
78 const char *debugfs;
79
80 if (tracing_found)
81 return tracing;
82
83 debugfs = find_debugfs();
Namhyung Kim454f8c72013-03-21 16:18:44 +090084 if (!debugfs)
85 return NULL;
Steven Rostedt520509432009-08-17 16:18:05 +020086
Namhyung Kim454f8c72013-03-21 16:18:44 +090087 tracing = malloc(strlen(debugfs) + 9);
88 if (!tracing)
89 return NULL;
Steven Rostedt520509432009-08-17 16:18:05 +020090
91 sprintf(tracing, "%s/tracing", debugfs);
92
93 tracing_found = 1;
94 return tracing;
95}
96
97static char *get_tracing_file(const char *name)
98{
99 const char *tracing;
100 char *file;
101
102 tracing = find_tracing_dir();
103 if (!tracing)
104 return NULL;
105
Namhyung Kim454f8c72013-03-21 16:18:44 +0900106 file = malloc(strlen(tracing) + strlen(name) + 2);
107 if (!file)
108 return NULL;
Steven Rostedt520509432009-08-17 16:18:05 +0200109
110 sprintf(file, "%s/%s", tracing, name);
111 return file;
112}
113
114static void put_tracing_file(char *file)
115{
116 free(file);
117}
118
119static ssize_t write_or_die(const void *buf, size_t len)
120{
121 int ret;
122
123 ret = write(output_fd, buf, len);
124 if (ret < 0)
125 die("writing to '%s'", output_file);
126
127 return ret;
128}
129
130int bigendian(void)
131{
132 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0};
133 unsigned int *ptr;
134
Ingo Molnar65014ab2009-09-02 14:55:55 +0200135 ptr = (unsigned int *)(void *)str;
Steven Rostedt520509432009-08-17 16:18:05 +0200136 return *ptr == 0x01020304;
137}
138
Sonny Rao259032b2011-07-14 13:34:43 +1000139/* unfortunately, you can not stat debugfs or proc files for size */
140static void record_file(const char *file, size_t hdr_sz)
Steven Rostedt520509432009-08-17 16:18:05 +0200141{
142 unsigned long long size = 0;
Sonny Rao259032b2011-07-14 13:34:43 +1000143 char buf[BUFSIZ], *sizep;
144 off_t hdr_pos = lseek(output_fd, 0, SEEK_CUR);
145 int r, fd;
146
147 fd = open(file, O_RDONLY);
148 if (fd < 0)
149 die("Can't read '%s'", file);
150
151 /* put in zeros for file size, then fill true size later */
Jiri Olsa29208e52011-10-20 15:59:43 +0200152 if (hdr_sz)
153 write_or_die(&size, hdr_sz);
Steven Rostedt520509432009-08-17 16:18:05 +0200154
155 do {
156 r = read(fd, buf, BUFSIZ);
157 if (r > 0) {
158 size += r;
159 write_or_die(buf, r);
160 }
161 } while (r > 0);
Steven Rostedt520509432009-08-17 16:18:05 +0200162 close(fd);
163
Sonny Rao259032b2011-07-14 13:34:43 +1000164 /* ugh, handle big-endian hdr_size == 4 */
165 sizep = (char*)&size;
166 if (bigendian())
167 sizep += sizeof(u64) - hdr_sz;
Steven Rostedt520509432009-08-17 16:18:05 +0200168
Jiri Olsa29208e52011-10-20 15:59:43 +0200169 if (hdr_sz && pwrite(output_fd, sizep, hdr_sz, hdr_pos) < 0)
Sonny Rao259032b2011-07-14 13:34:43 +1000170 die("writing to %s", output_file);
Steven Rostedt520509432009-08-17 16:18:05 +0200171}
172
173static void read_header_files(void)
174{
Steven Rostedt520509432009-08-17 16:18:05 +0200175 char *path;
Sonny Rao259032b2011-07-14 13:34:43 +1000176 struct stat st;
Steven Rostedt520509432009-08-17 16:18:05 +0200177
178 path = get_tracing_file("events/header_page");
Namhyung Kim454f8c72013-03-21 16:18:44 +0900179 if (!path)
180 die("can't get tracing/events/header_page");
181
Sonny Rao259032b2011-07-14 13:34:43 +1000182 if (stat(path, &st) < 0)
Steven Rostedt520509432009-08-17 16:18:05 +0200183 die("can't read '%s'", path);
184
Steven Rostedt520509432009-08-17 16:18:05 +0200185 write_or_die("header_page", 12);
Sonny Rao259032b2011-07-14 13:34:43 +1000186 record_file(path, 8);
Steven Rostedt520509432009-08-17 16:18:05 +0200187 put_tracing_file(path);
188
189 path = get_tracing_file("events/header_event");
Namhyung Kim454f8c72013-03-21 16:18:44 +0900190 if (!path)
191 die("can't get tracing/events/header_event");
192
Sonny Rao259032b2011-07-14 13:34:43 +1000193 if (stat(path, &st) < 0)
Steven Rostedt520509432009-08-17 16:18:05 +0200194 die("can't read '%s'", path);
195
Steven Rostedt520509432009-08-17 16:18:05 +0200196 write_or_die("header_event", 13);
Sonny Rao259032b2011-07-14 13:34:43 +1000197 record_file(path, 8);
Steven Rostedt520509432009-08-17 16:18:05 +0200198 put_tracing_file(path);
199}
200
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200201static bool name_in_tp_list(char *sys, struct tracepoint_path *tps)
202{
203 while (tps) {
204 if (!strcmp(sys, tps->name))
205 return true;
206 tps = tps->next;
207 }
208
209 return false;
210}
211
212static void copy_event_system(const char *sys, struct tracepoint_path *tps)
Steven Rostedt520509432009-08-17 16:18:05 +0200213{
Steven Rostedt520509432009-08-17 16:18:05 +0200214 struct dirent *dent;
215 struct stat st;
216 char *format;
217 DIR *dir;
218 int count = 0;
219 int ret;
220
221 dir = opendir(sys);
222 if (!dir)
223 die("can't read directory '%s'", sys);
224
225 while ((dent = readdir(dir))) {
Ulrich Drepper659d8cf2009-12-19 16:40:28 -0500226 if (dent->d_type != DT_DIR ||
227 strcmp(dent->d_name, ".") == 0 ||
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200228 strcmp(dent->d_name, "..") == 0 ||
229 !name_in_tp_list(dent->d_name, tps))
Steven Rostedt520509432009-08-17 16:18:05 +0200230 continue;
231 format = malloc_or_die(strlen(sys) + strlen(dent->d_name) + 10);
232 sprintf(format, "%s/%s/format", sys, dent->d_name);
233 ret = stat(format, &st);
234 free(format);
235 if (ret < 0)
236 continue;
237 count++;
238 }
239
240 write_or_die(&count, 4);
241
242 rewinddir(dir);
243 while ((dent = readdir(dir))) {
Ulrich Drepper659d8cf2009-12-19 16:40:28 -0500244 if (dent->d_type != DT_DIR ||
245 strcmp(dent->d_name, ".") == 0 ||
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200246 strcmp(dent->d_name, "..") == 0 ||
247 !name_in_tp_list(dent->d_name, tps))
Steven Rostedt520509432009-08-17 16:18:05 +0200248 continue;
249 format = malloc_or_die(strlen(sys) + strlen(dent->d_name) + 10);
250 sprintf(format, "%s/%s/format", sys, dent->d_name);
251 ret = stat(format, &st);
252
Sonny Rao259032b2011-07-14 13:34:43 +1000253 if (ret >= 0)
254 record_file(format, 8);
Steven Rostedt520509432009-08-17 16:18:05 +0200255
256 free(format);
257 }
Xiao Guangrong99674112009-12-28 16:49:38 +0800258 closedir(dir);
Steven Rostedt520509432009-08-17 16:18:05 +0200259}
260
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200261static void read_ftrace_files(struct tracepoint_path *tps)
Steven Rostedt520509432009-08-17 16:18:05 +0200262{
263 char *path;
264
265 path = get_tracing_file("events/ftrace");
Namhyung Kim454f8c72013-03-21 16:18:44 +0900266 if (!path)
267 die("can't get tracing/events/ftrace");
Steven Rostedt520509432009-08-17 16:18:05 +0200268
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200269 copy_event_system(path, tps);
Steven Rostedt520509432009-08-17 16:18:05 +0200270
271 put_tracing_file(path);
272}
273
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200274static bool system_in_tp_list(char *sys, struct tracepoint_path *tps)
275{
276 while (tps) {
277 if (!strcmp(sys, tps->system))
278 return true;
279 tps = tps->next;
280 }
281
282 return false;
283}
284
285static void read_event_files(struct tracepoint_path *tps)
Steven Rostedt520509432009-08-17 16:18:05 +0200286{
287 struct dirent *dent;
288 struct stat st;
289 char *path;
290 char *sys;
291 DIR *dir;
292 int count = 0;
293 int ret;
294
295 path = get_tracing_file("events");
Namhyung Kim454f8c72013-03-21 16:18:44 +0900296 if (!path)
297 die("can't get tracing/events");
Steven Rostedt520509432009-08-17 16:18:05 +0200298
299 dir = opendir(path);
300 if (!dir)
301 die("can't read directory '%s'", path);
302
303 while ((dent = readdir(dir))) {
Ulrich Drepper659d8cf2009-12-19 16:40:28 -0500304 if (dent->d_type != DT_DIR ||
305 strcmp(dent->d_name, ".") == 0 ||
Steven Rostedt520509432009-08-17 16:18:05 +0200306 strcmp(dent->d_name, "..") == 0 ||
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200307 strcmp(dent->d_name, "ftrace") == 0 ||
308 !system_in_tp_list(dent->d_name, tps))
Steven Rostedt520509432009-08-17 16:18:05 +0200309 continue;
Ulrich Drepper659d8cf2009-12-19 16:40:28 -0500310 count++;
Steven Rostedt520509432009-08-17 16:18:05 +0200311 }
312
313 write_or_die(&count, 4);
314
315 rewinddir(dir);
316 while ((dent = readdir(dir))) {
Ulrich Drepper659d8cf2009-12-19 16:40:28 -0500317 if (dent->d_type != DT_DIR ||
318 strcmp(dent->d_name, ".") == 0 ||
Steven Rostedt520509432009-08-17 16:18:05 +0200319 strcmp(dent->d_name, "..") == 0 ||
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200320 strcmp(dent->d_name, "ftrace") == 0 ||
321 !system_in_tp_list(dent->d_name, tps))
Steven Rostedt520509432009-08-17 16:18:05 +0200322 continue;
323 sys = malloc_or_die(strlen(path) + strlen(dent->d_name) + 2);
324 sprintf(sys, "%s/%s", path, dent->d_name);
325 ret = stat(sys, &st);
326 if (ret >= 0) {
Ulrich Drepper659d8cf2009-12-19 16:40:28 -0500327 write_or_die(dent->d_name, strlen(dent->d_name) + 1);
328 copy_event_system(sys, tps);
Steven Rostedt520509432009-08-17 16:18:05 +0200329 }
330 free(sys);
331 }
332
Xiao Guangrong99674112009-12-28 16:49:38 +0800333 closedir(dir);
Steven Rostedt520509432009-08-17 16:18:05 +0200334 put_tracing_file(path);
335}
336
337static void read_proc_kallsyms(void)
338{
Sonny Rao259032b2011-07-14 13:34:43 +1000339 unsigned int size;
Steven Rostedt520509432009-08-17 16:18:05 +0200340 const char *path = "/proc/kallsyms";
341 struct stat st;
342 int ret;
343
344 ret = stat(path, &st);
345 if (ret < 0) {
346 /* not found */
347 size = 0;
348 write_or_die(&size, 4);
349 return;
350 }
Sonny Rao259032b2011-07-14 13:34:43 +1000351 record_file(path, 4);
Steven Rostedt520509432009-08-17 16:18:05 +0200352}
353
354static void read_ftrace_printk(void)
355{
Sonny Rao259032b2011-07-14 13:34:43 +1000356 unsigned int size;
Li Zefan6706ccf2009-09-17 16:34:23 +0800357 char *path;
Steven Rostedt520509432009-08-17 16:18:05 +0200358 struct stat st;
359 int ret;
360
361 path = get_tracing_file("printk_formats");
Namhyung Kim454f8c72013-03-21 16:18:44 +0900362 if (!path)
363 die("can't get tracing/printk_formats");
364
Steven Rostedt520509432009-08-17 16:18:05 +0200365 ret = stat(path, &st);
366 if (ret < 0) {
367 /* not found */
368 size = 0;
369 write_or_die(&size, 4);
Li Zefan6706ccf2009-09-17 16:34:23 +0800370 goto out;
Steven Rostedt520509432009-08-17 16:18:05 +0200371 }
Sonny Rao259032b2011-07-14 13:34:43 +1000372 record_file(path, 4);
373
Li Zefan6706ccf2009-09-17 16:34:23 +0800374out:
375 put_tracing_file(path);
Steven Rostedt520509432009-08-17 16:18:05 +0200376}
377
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200378static struct tracepoint_path *
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200379get_tracepoints_path(struct list_head *pattrs)
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200380{
381 struct tracepoint_path path, *ppath = &path;
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200382 struct perf_evsel *pos;
383 int nr_tracepoints = 0;
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200384
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200385 list_for_each_entry(pos, pattrs, node) {
386 if (pos->attr.type != PERF_TYPE_TRACEPOINT)
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200387 continue;
Arnaldo Carvalho de Meloe2561362009-11-21 14:31:26 -0200388 ++nr_tracepoints;
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200389 ppath->next = tracepoint_id_to_path(pos->attr.config);
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200390 if (!ppath->next)
391 die("%s\n", "No memory to alloc tracepoints list");
392 ppath = ppath->next;
393 }
394
Arnaldo Carvalho de Meloe2561362009-11-21 14:31:26 -0200395 return nr_tracepoints > 0 ? path.next : NULL;
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200396}
Arnaldo Carvalho de Meloe2561362009-11-21 14:31:26 -0200397
Jiri Olsa29208e52011-10-20 15:59:43 +0200398static void
399put_tracepoints_path(struct tracepoint_path *tps)
400{
401 while (tps) {
402 struct tracepoint_path *t = tps;
403
404 tps = tps->next;
405 free(t->name);
406 free(t->system);
407 free(t);
408 }
409}
410
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200411bool have_tracepoints(struct list_head *pattrs)
Tom Zanussi63e0c772010-05-03 00:14:48 -0500412{
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200413 struct perf_evsel *pos;
Tom Zanussidb620b12010-05-04 22:20:16 -0500414
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200415 list_for_each_entry(pos, pattrs, node)
416 if (pos->attr.type == PERF_TYPE_TRACEPOINT)
Tom Zanussidb620b12010-05-04 22:20:16 -0500417 return true;
418
419 return false;
Tom Zanussi63e0c772010-05-03 00:14:48 -0500420}
421
Jiri Olsa29208e52011-10-20 15:59:43 +0200422static void tracing_data_header(void)
Steven Rostedt520509432009-08-17 16:18:05 +0200423{
Jiri Olsa29208e52011-10-20 15:59:43 +0200424 char buf[20];
Arnaldo Carvalho de Meloe2561362009-11-21 14:31:26 -0200425
Jiri Olsa29208e52011-10-20 15:59:43 +0200426 /* just guessing this is someone's birthday.. ;) */
Steven Rostedt520509432009-08-17 16:18:05 +0200427 buf[0] = 23;
428 buf[1] = 8;
429 buf[2] = 68;
430 memcpy(buf + 3, "tracing", 7);
431
432 write_or_die(buf, 10);
433
434 write_or_die(VERSION, strlen(VERSION) + 1);
435
436 /* save endian */
437 if (bigendian())
438 buf[0] = 1;
439 else
440 buf[0] = 0;
441
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200442 read_trace_init(buf[0], buf[0]);
443
Steven Rostedt520509432009-08-17 16:18:05 +0200444 write_or_die(buf, 1);
445
446 /* save size of long */
447 buf[0] = sizeof(long);
448 write_or_die(buf, 1);
449
450 /* save page_size */
Steven Rostedt520509432009-08-17 16:18:05 +0200451 write_or_die(&page_size, 4);
Jiri Olsa29208e52011-10-20 15:59:43 +0200452}
Steven Rostedt520509432009-08-17 16:18:05 +0200453
Jiri Olsa29208e52011-10-20 15:59:43 +0200454struct tracing_data *tracing_data_get(struct list_head *pattrs,
455 int fd, bool temp)
456{
457 struct tracepoint_path *tps;
458 struct tracing_data *tdata;
459
460 output_fd = fd;
461
462 tps = get_tracepoints_path(pattrs);
463 if (!tps)
464 return NULL;
465
466 tdata = malloc_or_die(sizeof(*tdata));
467 tdata->temp = temp;
468 tdata->size = 0;
469
470 if (temp) {
471 int temp_fd;
472
473 snprintf(tdata->temp_file, sizeof(tdata->temp_file),
474 "/tmp/perf-XXXXXX");
475 if (!mkstemp(tdata->temp_file))
476 die("Can't make temp file");
477
478 temp_fd = open(tdata->temp_file, O_RDWR);
479 if (temp_fd < 0)
480 die("Can't read '%s'", tdata->temp_file);
481
482 /*
483 * Set the temp file the default output, so all the
484 * tracing data are stored into it.
485 */
486 output_fd = temp_fd;
487 }
488
489 tracing_data_header();
Steven Rostedt520509432009-08-17 16:18:05 +0200490 read_header_files();
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200491 read_ftrace_files(tps);
492 read_event_files(tps);
Steven Rostedt520509432009-08-17 16:18:05 +0200493 read_proc_kallsyms();
494 read_ftrace_printk();
Arnaldo Carvalho de Meloe2561362009-11-21 14:31:26 -0200495
Jiri Olsa29208e52011-10-20 15:59:43 +0200496 /*
497 * All tracing data are stored by now, we can restore
498 * the default output file in case we used temp file.
499 */
500 if (temp) {
501 tdata->size = lseek(output_fd, 0, SEEK_CUR);
502 close(output_fd);
503 output_fd = fd;
504 }
505
506 put_tracepoints_path(tps);
507 return tdata;
Steven Rostedt520509432009-08-17 16:18:05 +0200508}
Tom Zanussi92155452010-04-01 23:59:21 -0500509
Jiri Olsa29208e52011-10-20 15:59:43 +0200510void tracing_data_put(struct tracing_data *tdata)
Tom Zanussi92155452010-04-01 23:59:21 -0500511{
Jiri Olsa29208e52011-10-20 15:59:43 +0200512 if (tdata->temp) {
513 record_file(tdata->temp_file, 0);
514 unlink(tdata->temp_file);
515 }
Tom Zanussi92155452010-04-01 23:59:21 -0500516
Jiri Olsa29208e52011-10-20 15:59:43 +0200517 free(tdata);
518}
Tom Zanussi92155452010-04-01 23:59:21 -0500519
Jiri Olsa29208e52011-10-20 15:59:43 +0200520int read_tracing_data(int fd, struct list_head *pattrs)
521{
522 struct tracing_data *tdata;
Tom Zanussi92155452010-04-01 23:59:21 -0500523
Jiri Olsa29208e52011-10-20 15:59:43 +0200524 /*
525 * We work over the real file, so we can write data
526 * directly, no temp file is needed.
527 */
528 tdata = tracing_data_get(pattrs, fd, false);
529 if (!tdata)
530 return -ENOMEM;
531
532 tracing_data_put(tdata);
533 return 0;
Tom Zanussi92155452010-04-01 23:59:21 -0500534}