cregit-Linux how code gets into the kernel

Release 4.11 tools/perf/util/trace-event-read.c

Directory: tools/perf/util
/*
 * Copyright (C) 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 <dirent.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 <sys/mman.h>
#include <pthread.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>

#include "../perf.h"
#include "util.h"
#include "trace-event.h"
#include "debug.h"


static int input_fd;


static ssize_t trace_data_size;

static bool repipe;


static int __do_read(int fd, void *buf, int size) { int rsize = size; while (size) { int ret = read(fd, buf, size); if (ret <= 0) return -1; if (repipe) { int retw = write(STDOUT_FILENO, buf, ret); if (retw <= 0 || retw != ret) { pr_debug("repiping input file"); return -1; } } size -= ret; buf += ret; } return rsize; }

Contributors

PersonTokensPropCommitsCommitProp
Tom Zanussi9191.92%266.67%
Namhyung Kim88.08%133.33%
Total99100.00%3100.00%


static int do_read(void *data, int size) { int r; r = __do_read(input_fd, data, size); if (r <= 0) { pr_debug("reading input file (size expected=%d received=%d)", size, r); return -1; } trace_data_size += r; return r; }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt4072.73%125.00%
Namhyung Kim1018.18%250.00%
Tom Zanussi59.09%125.00%
Total55100.00%4100.00%

/* If it fails, the next read will report it */
static void skip(int size) { char buf[BUFSIZ]; int r; while (size) { r = size > BUFSIZ ? BUFSIZ : size; do_read(buf, r); size -= r; }; }

Contributors

PersonTokensPropCommitsCommitProp
Tom Zanussi4597.83%150.00%
Namhyung Kim12.17%150.00%
Total46100.00%2100.00%


static unsigned int read4(struct pevent *pevent) { unsigned int data; if (do_read(&data, 4) < 0) return 0; return __data2host4(pevent, data); }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt2564.10%250.00%
Namhyung Kim923.08%125.00%
Arnaldo Carvalho de Melo512.82%125.00%
Total39100.00%4100.00%


static unsigned long long read8(struct pevent *pevent) { unsigned long long data; if (do_read(&data, 8) < 0) return 0; return __data2host8(pevent, data); }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt2765.85%250.00%
Namhyung Kim921.95%125.00%
Arnaldo Carvalho de Melo512.20%125.00%
Total41100.00%4100.00%


static char *read_string(void) { char buf[BUFSIZ]; char *str = NULL; int size = 0; off_t r; char c; for (;;) { r = read(input_fd, &c, 1); if (r < 0) { pr_debug("reading input file"); goto out; } if (!r) { pr_debug("no data"); goto out; } if (repipe) { int retw = write(STDOUT_FILENO, &c, 1); if (retw <= 0 || retw != r) { pr_debug("repiping input file string"); goto out; } } buf[size++] = c; if (!c) break; } trace_data_size += size; str = malloc(size); if (str) memcpy(str, buf, size); out: return str; }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt9155.49%114.29%
Tom Zanussi4628.05%228.57%
Namhyung Kim2615.85%342.86%
Xiao Guangrong10.61%114.29%
Total164100.00%7100.00%


static int read_proc_kallsyms(struct pevent *pevent) { unsigned int size; size = read4(pevent); if (!size) return 0; /* * Just skip it, now that we configure libtraceevent to use the * tools/perf/ symbol resolver. * * We need to skip it so that we can continue parsing old perf.data * files, that contains this /proc/kallsyms payload. * * Newer perf.data files will have just the 4-bytes zeros "kallsyms * payload", so that older tools can continue reading it and interpret * it as "no kallsyms payload is present". */ lseek(input_fd, size, SEEK_CUR); trace_data_size += size; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt2655.32%125.00%
Arnaldo Carvalho de Melo1429.79%250.00%
Namhyung Kim714.89%125.00%
Total47100.00%4100.00%


static int read_ftrace_printk(struct pevent *pevent) { unsigned int size; char *buf; /* it can have 0 size */ size = read4(pevent); if (!size) return 0; buf = malloc(size); if (buf == NULL) return -1; if (do_read(buf, size) < 0) { free(buf); return -1; } parse_ftrace_printk(pevent, buf, size); free(buf); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt4751.65%125.00%
Namhyung Kim3538.46%250.00%
Arnaldo Carvalho de Melo99.89%125.00%
Total91100.00%4100.00%


static int read_header_files(struct pevent *pevent) { unsigned long long size; char *header_page; char buf[BUFSIZ]; int ret = 0; if (do_read(buf, 12) < 0) return -1; if (memcmp(buf, "header_page", 12) != 0) { pr_debug("did not read header page"); return -1; } size = read8(pevent); header_page = malloc(size); if (header_page == NULL) return -1; if (do_read(header_page, size) < 0) { pr_debug("did not read header page"); free(header_page); return -1; } if (!pevent_parse_header_page(pevent, header_page, size, pevent_get_long_size(pevent))) { /* * The commit field in the page is of type long, * use that instead, since it represents the kernel. */ pevent_set_long_size(pevent, pevent->header_page_size_size); } free(header_page); if (do_read(buf, 13) < 0) return -1; if (memcmp(buf, "header_event", 13) != 0) { pr_debug("did not read header event"); return -1; } size = read8(pevent); skip(size); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Namhyung Kim12258.37%571.43%
Steven Rostedt7736.84%114.29%
Arnaldo Carvalho de Melo104.78%114.29%
Total209100.00%7100.00%


static int read_ftrace_file(struct pevent *pevent, unsigned long long size) { int ret; char *buf; buf = malloc(size); if (buf == NULL) { pr_debug("memory allocation failure\n"); return -1; } ret = do_read(buf, size); if (ret < 0) { pr_debug("error reading ftrace file.\n"); goto out; } ret = parse_ftrace_file(pevent, buf, size); if (ret < 0) pr_debug("error parsing ftrace file.\n"); out: free(buf); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Namhyung Kim5956.73%360.00%
Steven Rostedt3836.54%120.00%
Arnaldo Carvalho de Melo76.73%120.00%
Total104100.00%5100.00%


static int read_event_file(struct pevent *pevent, char *sys, unsigned long long size) { int ret; char *buf; buf = malloc(size); if (buf == NULL) { pr_debug("memory allocation failure\n"); return -1; } ret = do_read(buf, size); if (ret < 0) { free(buf); goto out; } ret = parse_event_file(pevent, buf, size, sys); if (ret < 0) pr_debug("error parsing event file.\n"); out: free(buf); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Namhyung Kim5953.64%360.00%
Steven Rostedt4440.00%120.00%
Arnaldo Carvalho de Melo76.36%120.00%
Total110100.00%5100.00%


static int read_ftrace_files(struct pevent *pevent) { unsigned long long size; int count; int i; int ret; count = read4(pevent); for (i = 0; i < count; i++) { size = read8(pevent); ret = read_ftrace_file(pevent, size); if (ret) return ret; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt4561.64%133.33%
Namhyung Kim1621.92%133.33%
Arnaldo Carvalho de Melo1216.44%133.33%
Total73100.00%3100.00%


static int read_event_files(struct pevent *pevent) { unsigned long long size; char *sys; int systems; int count; int i,x; int ret; systems = read4(pevent); for (i = 0; i < systems; i++) { sys = read_string(); if (sys == NULL) return -1; count = read4(pevent); for (x=0; x < count; x++) { size = read8(pevent); ret = read_event_file(pevent, sys, size); if (ret) return ret; } } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt8066.12%133.33%
Namhyung Kim2621.49%133.33%
Arnaldo Carvalho de Melo1512.40%133.33%
Total121100.00%3100.00%


static int read_saved_cmdline(struct pevent *pevent) { unsigned long long size; char *buf; int ret; /* it can have 0 size */ size = read8(pevent); if (!size) return 0; buf = malloc(size + 1); if (buf == NULL) { pr_debug("memory allocation failure\n"); return -1; } ret = do_read(buf, size); if (ret < 0) { pr_debug("error reading saved cmdlines\n"); goto out; } parse_saved_cmdline(pevent, buf, size); ret = 0; out: free(buf); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Namhyung Kim113100.00%2100.00%
Total113100.00%2100.00%


ssize_t trace_report(int fd, struct trace_event *tevent, bool __repipe) { char buf[BUFSIZ]; char test[] = { 23, 8, 68 }; char *version; int show_version = 0; int show_funcs = 0; int show_printk = 0; ssize_t size = -1; int file_bigendian; int host_bigendian; int file_long_size; int file_page_size; struct pevent *pevent = NULL; int err; repipe = __repipe; input_fd = fd; if (do_read(buf, 3) < 0) return -1; if (memcmp(buf, test, 3) != 0) { pr_debug("no trace data in the file"); return -1; } if (do_read(buf, 7) < 0) return -1; if (memcmp(buf, "tracing", 7) != 0) { pr_debug("not a trace file (missing 'tracing' tag)"); return -1; } version = read_string(); if (version == NULL) return -1; if (show_version) printf("version = %s\n", version); if (do_read(buf, 1) < 0) { free(version); return -1; } file_bigendian = buf[0]; host_bigendian = bigendian(); if (trace_event__init(tevent)) { pr_debug("trace_event__init failed"); goto out; } pevent = tevent->pevent; pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT); pevent_set_file_bigendian(pevent, file_bigendian); pevent_set_host_bigendian(pevent, host_bigendian); if (do_read(buf, 1) < 0) goto out; file_long_size = buf[0]; file_page_size = read4(pevent); if (!file_page_size) goto out; pevent_set_long_size(pevent, file_long_size); pevent_set_page_size(pevent, file_page_size); err = read_header_files(pevent); if (err) goto out; err = read_ftrace_files(pevent); if (err) goto out; err = read_event_files(pevent); if (err) goto out; err = read_proc_kallsyms(pevent); if (err) goto out; err = read_ftrace_printk(pevent); if (err) goto out; if (atof(version) >= 0.6) { err = read_saved_cmdline(pevent); if (err) goto out; } size = trace_data_size; repipe = false; if (show_funcs) { pevent_print_funcs(pevent); } else if (show_printk) { pevent_print_printk(pevent); } pevent = NULL; out: if (pevent) trace_event__cleanup(tevent); free(version); return size; }

Contributors

PersonTokensPropCommitsCommitProp
Namhyung Kim22247.23%950.00%
Steven Rostedt15432.77%211.11%
Jiri Olsa388.09%15.56%
Arnaldo Carvalho de Melo234.89%211.11%
Tom Zanussi214.47%211.11%
Ingo Molnar91.91%15.56%
Frédéric Weisbecker30.64%15.56%
Total470100.00%18100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt74440.28%27.69%
Namhyung Kim72339.14%1246.15%
Tom Zanussi21611.69%311.54%
Arnaldo Carvalho de Melo1075.79%311.54%
Jiri Olsa412.22%27.69%
Ingo Molnar90.49%13.85%
Frédéric Weisbecker60.32%27.69%
Xiao Guangrong10.05%13.85%
Total1847100.00%26100.00%
Directory: tools/perf/util
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.