blob: 91db6e8e4493e8daac9dbce87b8e70ca4fe643e2 [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 Rostedt520509432009-08-17 16:18:05 +020050static const char *find_debugfs(void)
51{
Borislav Petkov13559152013-02-20 16:32:31 +010052 const char *path = perf_debugfs_mount(NULL);
Steven Rostedt520509432009-08-17 16:18:05 +020053
Xiao Guangrong61be3e52009-12-28 16:48:30 +080054 if (!path)
Namhyung Kim454f8c72013-03-21 16:18:44 +090055 pr_debug("Your kernel does not support the debugfs filesystem");
Steven Rostedt520509432009-08-17 16:18:05 +020056
Xiao Guangrong61be3e52009-12-28 16:48:30 +080057 return path;
Steven Rostedt520509432009-08-17 16:18:05 +020058}
59
60/*
61 * Finds the path to the debugfs/tracing
62 * Allocates the string and stores it.
63 */
64static const char *find_tracing_dir(void)
65{
66 static char *tracing;
67 static int tracing_found;
68 const char *debugfs;
69
70 if (tracing_found)
71 return tracing;
72
73 debugfs = find_debugfs();
Namhyung Kim454f8c72013-03-21 16:18:44 +090074 if (!debugfs)
75 return NULL;
Steven Rostedt520509432009-08-17 16:18:05 +020076
Namhyung Kim454f8c72013-03-21 16:18:44 +090077 tracing = malloc(strlen(debugfs) + 9);
78 if (!tracing)
79 return NULL;
Steven Rostedt520509432009-08-17 16:18:05 +020080
81 sprintf(tracing, "%s/tracing", debugfs);
82
83 tracing_found = 1;
84 return tracing;
85}
86
87static char *get_tracing_file(const char *name)
88{
89 const char *tracing;
90 char *file;
91
92 tracing = find_tracing_dir();
93 if (!tracing)
94 return NULL;
95
Namhyung Kim454f8c72013-03-21 16:18:44 +090096 file = malloc(strlen(tracing) + strlen(name) + 2);
97 if (!file)
98 return NULL;
Steven Rostedt520509432009-08-17 16:18:05 +020099
100 sprintf(file, "%s/%s", tracing, name);
101 return file;
102}
103
104static void put_tracing_file(char *file)
105{
106 free(file);
107}
108
109static ssize_t write_or_die(const void *buf, size_t len)
110{
111 int ret;
112
113 ret = write(output_fd, buf, len);
114 if (ret < 0)
115 die("writing to '%s'", output_file);
116
117 return ret;
118}
119
120int bigendian(void)
121{
122 unsigned char str[] = { 0x1, 0x2, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0};
123 unsigned int *ptr;
124
Ingo Molnar65014ab2009-09-02 14:55:55 +0200125 ptr = (unsigned int *)(void *)str;
Steven Rostedt520509432009-08-17 16:18:05 +0200126 return *ptr == 0x01020304;
127}
128
Sonny Rao259032b2011-07-14 13:34:43 +1000129/* unfortunately, you can not stat debugfs or proc files for size */
130static void record_file(const char *file, size_t hdr_sz)
Steven Rostedt520509432009-08-17 16:18:05 +0200131{
132 unsigned long long size = 0;
Sonny Rao259032b2011-07-14 13:34:43 +1000133 char buf[BUFSIZ], *sizep;
134 off_t hdr_pos = lseek(output_fd, 0, SEEK_CUR);
135 int r, fd;
136
137 fd = open(file, O_RDONLY);
138 if (fd < 0)
139 die("Can't read '%s'", file);
140
141 /* put in zeros for file size, then fill true size later */
Jiri Olsa29208e52011-10-20 15:59:43 +0200142 if (hdr_sz)
143 write_or_die(&size, hdr_sz);
Steven Rostedt520509432009-08-17 16:18:05 +0200144
145 do {
146 r = read(fd, buf, BUFSIZ);
147 if (r > 0) {
148 size += r;
149 write_or_die(buf, r);
150 }
151 } while (r > 0);
Steven Rostedt520509432009-08-17 16:18:05 +0200152 close(fd);
153
Sonny Rao259032b2011-07-14 13:34:43 +1000154 /* ugh, handle big-endian hdr_size == 4 */
155 sizep = (char*)&size;
156 if (bigendian())
157 sizep += sizeof(u64) - hdr_sz;
Steven Rostedt520509432009-08-17 16:18:05 +0200158
Jiri Olsa29208e52011-10-20 15:59:43 +0200159 if (hdr_sz && pwrite(output_fd, sizep, hdr_sz, hdr_pos) < 0)
Sonny Rao259032b2011-07-14 13:34:43 +1000160 die("writing to %s", output_file);
Steven Rostedt520509432009-08-17 16:18:05 +0200161}
162
163static void read_header_files(void)
164{
Steven Rostedt520509432009-08-17 16:18:05 +0200165 char *path;
Sonny Rao259032b2011-07-14 13:34:43 +1000166 struct stat st;
Steven Rostedt520509432009-08-17 16:18:05 +0200167
168 path = get_tracing_file("events/header_page");
Namhyung Kim454f8c72013-03-21 16:18:44 +0900169 if (!path)
170 die("can't get tracing/events/header_page");
171
Sonny Rao259032b2011-07-14 13:34:43 +1000172 if (stat(path, &st) < 0)
Steven Rostedt520509432009-08-17 16:18:05 +0200173 die("can't read '%s'", path);
174
Steven Rostedt520509432009-08-17 16:18:05 +0200175 write_or_die("header_page", 12);
Sonny Rao259032b2011-07-14 13:34:43 +1000176 record_file(path, 8);
Steven Rostedt520509432009-08-17 16:18:05 +0200177 put_tracing_file(path);
178
179 path = get_tracing_file("events/header_event");
Namhyung Kim454f8c72013-03-21 16:18:44 +0900180 if (!path)
181 die("can't get tracing/events/header_event");
182
Sonny Rao259032b2011-07-14 13:34:43 +1000183 if (stat(path, &st) < 0)
Steven Rostedt520509432009-08-17 16:18:05 +0200184 die("can't read '%s'", path);
185
Steven Rostedt520509432009-08-17 16:18:05 +0200186 write_or_die("header_event", 13);
Sonny Rao259032b2011-07-14 13:34:43 +1000187 record_file(path, 8);
Steven Rostedt520509432009-08-17 16:18:05 +0200188 put_tracing_file(path);
189}
190
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200191static bool name_in_tp_list(char *sys, struct tracepoint_path *tps)
192{
193 while (tps) {
194 if (!strcmp(sys, tps->name))
195 return true;
196 tps = tps->next;
197 }
198
199 return false;
200}
201
Namhyung Kim5a6fd272013-03-21 16:18:45 +0900202static int copy_event_system(const char *sys, struct tracepoint_path *tps)
Steven Rostedt520509432009-08-17 16:18:05 +0200203{
Steven Rostedt520509432009-08-17 16:18:05 +0200204 struct dirent *dent;
205 struct stat st;
206 char *format;
207 DIR *dir;
208 int count = 0;
209 int ret;
Namhyung Kim5a6fd272013-03-21 16:18:45 +0900210 int err;
Steven Rostedt520509432009-08-17 16:18:05 +0200211
212 dir = opendir(sys);
213 if (!dir)
214 die("can't read directory '%s'", sys);
215
216 while ((dent = readdir(dir))) {
Ulrich Drepper659d8cf2009-12-19 16:40:28 -0500217 if (dent->d_type != DT_DIR ||
218 strcmp(dent->d_name, ".") == 0 ||
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200219 strcmp(dent->d_name, "..") == 0 ||
220 !name_in_tp_list(dent->d_name, tps))
Steven Rostedt520509432009-08-17 16:18:05 +0200221 continue;
Namhyung Kim5a6fd272013-03-21 16:18:45 +0900222 format = malloc(strlen(sys) + strlen(dent->d_name) + 10);
223 if (!format) {
224 err = -ENOMEM;
225 goto out;
226 }
Steven Rostedt520509432009-08-17 16:18:05 +0200227 sprintf(format, "%s/%s/format", sys, dent->d_name);
228 ret = stat(format, &st);
229 free(format);
230 if (ret < 0)
231 continue;
232 count++;
233 }
234
235 write_or_die(&count, 4);
236
237 rewinddir(dir);
238 while ((dent = readdir(dir))) {
Ulrich Drepper659d8cf2009-12-19 16:40:28 -0500239 if (dent->d_type != DT_DIR ||
240 strcmp(dent->d_name, ".") == 0 ||
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200241 strcmp(dent->d_name, "..") == 0 ||
242 !name_in_tp_list(dent->d_name, tps))
Steven Rostedt520509432009-08-17 16:18:05 +0200243 continue;
Namhyung Kim5a6fd272013-03-21 16:18:45 +0900244 format = malloc(strlen(sys) + strlen(dent->d_name) + 10);
245 if (!format) {
246 err = -ENOMEM;
247 goto out;
248 }
Steven Rostedt520509432009-08-17 16:18:05 +0200249 sprintf(format, "%s/%s/format", sys, dent->d_name);
250 ret = stat(format, &st);
251
Sonny Rao259032b2011-07-14 13:34:43 +1000252 if (ret >= 0)
253 record_file(format, 8);
Steven Rostedt520509432009-08-17 16:18:05 +0200254 free(format);
255 }
Namhyung Kim5a6fd272013-03-21 16:18:45 +0900256 err = 0;
257out:
Xiao Guangrong99674112009-12-28 16:49:38 +0800258 closedir(dir);
Namhyung Kim5a6fd272013-03-21 16:18:45 +0900259 return err;
Steven Rostedt520509432009-08-17 16:18:05 +0200260}
261
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200262static void read_ftrace_files(struct tracepoint_path *tps)
Steven Rostedt520509432009-08-17 16:18:05 +0200263{
264 char *path;
265
266 path = get_tracing_file("events/ftrace");
Namhyung Kim454f8c72013-03-21 16:18:44 +0900267 if (!path)
268 die("can't get tracing/events/ftrace");
Steven Rostedt520509432009-08-17 16:18:05 +0200269
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200270 copy_event_system(path, tps);
Steven Rostedt520509432009-08-17 16:18:05 +0200271
272 put_tracing_file(path);
273}
274
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200275static bool system_in_tp_list(char *sys, struct tracepoint_path *tps)
276{
277 while (tps) {
278 if (!strcmp(sys, tps->system))
279 return true;
280 tps = tps->next;
281 }
282
283 return false;
284}
285
Namhyung Kim5a6fd272013-03-21 16:18:45 +0900286static int read_event_files(struct tracepoint_path *tps)
Steven Rostedt520509432009-08-17 16:18:05 +0200287{
288 struct dirent *dent;
289 struct stat st;
290 char *path;
291 char *sys;
292 DIR *dir;
293 int count = 0;
294 int ret;
Namhyung Kim5a6fd272013-03-21 16:18:45 +0900295 int err;
Steven Rostedt520509432009-08-17 16:18:05 +0200296
297 path = get_tracing_file("events");
Namhyung Kim454f8c72013-03-21 16:18:44 +0900298 if (!path)
299 die("can't get tracing/events");
Steven Rostedt520509432009-08-17 16:18:05 +0200300
301 dir = opendir(path);
302 if (!dir)
303 die("can't read directory '%s'", path);
304
305 while ((dent = readdir(dir))) {
Ulrich Drepper659d8cf2009-12-19 16:40:28 -0500306 if (dent->d_type != DT_DIR ||
307 strcmp(dent->d_name, ".") == 0 ||
Steven Rostedt520509432009-08-17 16:18:05 +0200308 strcmp(dent->d_name, "..") == 0 ||
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200309 strcmp(dent->d_name, "ftrace") == 0 ||
310 !system_in_tp_list(dent->d_name, tps))
Steven Rostedt520509432009-08-17 16:18:05 +0200311 continue;
Ulrich Drepper659d8cf2009-12-19 16:40:28 -0500312 count++;
Steven Rostedt520509432009-08-17 16:18:05 +0200313 }
314
315 write_or_die(&count, 4);
316
317 rewinddir(dir);
318 while ((dent = readdir(dir))) {
Ulrich Drepper659d8cf2009-12-19 16:40:28 -0500319 if (dent->d_type != DT_DIR ||
320 strcmp(dent->d_name, ".") == 0 ||
Steven Rostedt520509432009-08-17 16:18:05 +0200321 strcmp(dent->d_name, "..") == 0 ||
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200322 strcmp(dent->d_name, "ftrace") == 0 ||
323 !system_in_tp_list(dent->d_name, tps))
Steven Rostedt520509432009-08-17 16:18:05 +0200324 continue;
Namhyung Kim5a6fd272013-03-21 16:18:45 +0900325 sys = malloc(strlen(path) + strlen(dent->d_name) + 2);
326 if (!sys) {
327 err = -ENOMEM;
328 goto out;
329 }
Steven Rostedt520509432009-08-17 16:18:05 +0200330 sprintf(sys, "%s/%s", path, dent->d_name);
331 ret = stat(sys, &st);
332 if (ret >= 0) {
Ulrich Drepper659d8cf2009-12-19 16:40:28 -0500333 write_or_die(dent->d_name, strlen(dent->d_name) + 1);
334 copy_event_system(sys, tps);
Steven Rostedt520509432009-08-17 16:18:05 +0200335 }
336 free(sys);
337 }
Namhyung Kim5a6fd272013-03-21 16:18:45 +0900338 err = 0;
339out:
Xiao Guangrong99674112009-12-28 16:49:38 +0800340 closedir(dir);
Steven Rostedt520509432009-08-17 16:18:05 +0200341 put_tracing_file(path);
Namhyung Kim5a6fd272013-03-21 16:18:45 +0900342
343 return err;
Steven Rostedt520509432009-08-17 16:18:05 +0200344}
345
346static void read_proc_kallsyms(void)
347{
Sonny Rao259032b2011-07-14 13:34:43 +1000348 unsigned int size;
Steven Rostedt520509432009-08-17 16:18:05 +0200349 const char *path = "/proc/kallsyms";
350 struct stat st;
351 int ret;
352
353 ret = stat(path, &st);
354 if (ret < 0) {
355 /* not found */
356 size = 0;
357 write_or_die(&size, 4);
358 return;
359 }
Sonny Rao259032b2011-07-14 13:34:43 +1000360 record_file(path, 4);
Steven Rostedt520509432009-08-17 16:18:05 +0200361}
362
363static void read_ftrace_printk(void)
364{
Sonny Rao259032b2011-07-14 13:34:43 +1000365 unsigned int size;
Li Zefan6706ccf2009-09-17 16:34:23 +0800366 char *path;
Steven Rostedt520509432009-08-17 16:18:05 +0200367 struct stat st;
368 int ret;
369
370 path = get_tracing_file("printk_formats");
Namhyung Kim454f8c72013-03-21 16:18:44 +0900371 if (!path)
372 die("can't get tracing/printk_formats");
373
Steven Rostedt520509432009-08-17 16:18:05 +0200374 ret = stat(path, &st);
375 if (ret < 0) {
376 /* not found */
377 size = 0;
378 write_or_die(&size, 4);
Li Zefan6706ccf2009-09-17 16:34:23 +0800379 goto out;
Steven Rostedt520509432009-08-17 16:18:05 +0200380 }
Sonny Rao259032b2011-07-14 13:34:43 +1000381 record_file(path, 4);
382
Li Zefan6706ccf2009-09-17 16:34:23 +0800383out:
384 put_tracing_file(path);
Steven Rostedt520509432009-08-17 16:18:05 +0200385}
386
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200387static struct tracepoint_path *
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200388get_tracepoints_path(struct list_head *pattrs)
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200389{
390 struct tracepoint_path path, *ppath = &path;
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200391 struct perf_evsel *pos;
392 int nr_tracepoints = 0;
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200393
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200394 list_for_each_entry(pos, pattrs, node) {
395 if (pos->attr.type != PERF_TYPE_TRACEPOINT)
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200396 continue;
Arnaldo Carvalho de Meloe2561362009-11-21 14:31:26 -0200397 ++nr_tracepoints;
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200398 ppath->next = tracepoint_id_to_path(pos->attr.config);
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200399 if (!ppath->next)
400 die("%s\n", "No memory to alloc tracepoints list");
401 ppath = ppath->next;
402 }
403
Arnaldo Carvalho de Meloe2561362009-11-21 14:31:26 -0200404 return nr_tracepoints > 0 ? path.next : NULL;
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200405}
Arnaldo Carvalho de Meloe2561362009-11-21 14:31:26 -0200406
Jiri Olsa29208e52011-10-20 15:59:43 +0200407static void
408put_tracepoints_path(struct tracepoint_path *tps)
409{
410 while (tps) {
411 struct tracepoint_path *t = tps;
412
413 tps = tps->next;
414 free(t->name);
415 free(t->system);
416 free(t);
417 }
418}
419
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200420bool have_tracepoints(struct list_head *pattrs)
Tom Zanussi63e0c772010-05-03 00:14:48 -0500421{
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200422 struct perf_evsel *pos;
Tom Zanussidb620b12010-05-04 22:20:16 -0500423
Arnaldo Carvalho de Melo69aad6f2011-01-03 16:39:04 -0200424 list_for_each_entry(pos, pattrs, node)
425 if (pos->attr.type == PERF_TYPE_TRACEPOINT)
Tom Zanussidb620b12010-05-04 22:20:16 -0500426 return true;
427
428 return false;
Tom Zanussi63e0c772010-05-03 00:14:48 -0500429}
430
Jiri Olsa29208e52011-10-20 15:59:43 +0200431static void tracing_data_header(void)
Steven Rostedt520509432009-08-17 16:18:05 +0200432{
Jiri Olsa29208e52011-10-20 15:59:43 +0200433 char buf[20];
Arnaldo Carvalho de Meloe2561362009-11-21 14:31:26 -0200434
Jiri Olsa29208e52011-10-20 15:59:43 +0200435 /* just guessing this is someone's birthday.. ;) */
Steven Rostedt520509432009-08-17 16:18:05 +0200436 buf[0] = 23;
437 buf[1] = 8;
438 buf[2] = 68;
439 memcpy(buf + 3, "tracing", 7);
440
441 write_or_die(buf, 10);
442
443 write_or_die(VERSION, strlen(VERSION) + 1);
444
445 /* save endian */
446 if (bigendian())
447 buf[0] = 1;
448 else
449 buf[0] = 0;
450
Steven Rostedtaaf045f2012-04-06 00:47:56 +0200451 read_trace_init(buf[0], buf[0]);
452
Steven Rostedt520509432009-08-17 16:18:05 +0200453 write_or_die(buf, 1);
454
455 /* save size of long */
456 buf[0] = sizeof(long);
457 write_or_die(buf, 1);
458
459 /* save page_size */
Steven Rostedt520509432009-08-17 16:18:05 +0200460 write_or_die(&page_size, 4);
Jiri Olsa29208e52011-10-20 15:59:43 +0200461}
Steven Rostedt520509432009-08-17 16:18:05 +0200462
Jiri Olsa29208e52011-10-20 15:59:43 +0200463struct tracing_data *tracing_data_get(struct list_head *pattrs,
464 int fd, bool temp)
465{
466 struct tracepoint_path *tps;
467 struct tracing_data *tdata;
468
469 output_fd = fd;
470
471 tps = get_tracepoints_path(pattrs);
472 if (!tps)
473 return NULL;
474
Namhyung Kim5a6fd272013-03-21 16:18:45 +0900475 tdata = malloc(sizeof(*tdata));
476 if (!tdata)
477 return NULL;
478
Jiri Olsa29208e52011-10-20 15:59:43 +0200479 tdata->temp = temp;
480 tdata->size = 0;
481
482 if (temp) {
483 int temp_fd;
484
485 snprintf(tdata->temp_file, sizeof(tdata->temp_file),
486 "/tmp/perf-XXXXXX");
487 if (!mkstemp(tdata->temp_file))
488 die("Can't make temp file");
489
490 temp_fd = open(tdata->temp_file, O_RDWR);
491 if (temp_fd < 0)
492 die("Can't read '%s'", tdata->temp_file);
493
494 /*
495 * Set the temp file the default output, so all the
496 * tracing data are stored into it.
497 */
498 output_fd = temp_fd;
499 }
500
501 tracing_data_header();
Steven Rostedt520509432009-08-17 16:18:05 +0200502 read_header_files();
Frederic Weisbecker1ef2ed12009-08-28 03:09:58 +0200503 read_ftrace_files(tps);
504 read_event_files(tps);
Steven Rostedt520509432009-08-17 16:18:05 +0200505 read_proc_kallsyms();
506 read_ftrace_printk();
Arnaldo Carvalho de Meloe2561362009-11-21 14:31:26 -0200507
Jiri Olsa29208e52011-10-20 15:59:43 +0200508 /*
509 * All tracing data are stored by now, we can restore
510 * the default output file in case we used temp file.
511 */
512 if (temp) {
513 tdata->size = lseek(output_fd, 0, SEEK_CUR);
514 close(output_fd);
515 output_fd = fd;
516 }
517
518 put_tracepoints_path(tps);
519 return tdata;
Steven Rostedt520509432009-08-17 16:18:05 +0200520}
Tom Zanussi92155452010-04-01 23:59:21 -0500521
Jiri Olsa29208e52011-10-20 15:59:43 +0200522void tracing_data_put(struct tracing_data *tdata)
Tom Zanussi92155452010-04-01 23:59:21 -0500523{
Jiri Olsa29208e52011-10-20 15:59:43 +0200524 if (tdata->temp) {
525 record_file(tdata->temp_file, 0);
526 unlink(tdata->temp_file);
527 }
Tom Zanussi92155452010-04-01 23:59:21 -0500528
Jiri Olsa29208e52011-10-20 15:59:43 +0200529 free(tdata);
530}
Tom Zanussi92155452010-04-01 23:59:21 -0500531
Jiri Olsa29208e52011-10-20 15:59:43 +0200532int read_tracing_data(int fd, struct list_head *pattrs)
533{
534 struct tracing_data *tdata;
Tom Zanussi92155452010-04-01 23:59:21 -0500535
Jiri Olsa29208e52011-10-20 15:59:43 +0200536 /*
537 * We work over the real file, so we can write data
538 * directly, no temp file is needed.
539 */
540 tdata = tracing_data_get(pattrs, fd, false);
541 if (!tdata)
542 return -ENOMEM;
543
544 tracing_data_put(tdata);
545 return 0;
Tom Zanussi92155452010-04-01 23:59:21 -0500546}