/* unfortunately, you can not stat debugfs or proc files for size */ staticint record_file(constchar *file, ssize_t hdr_sz)
{ unsignedlonglong size = 0; char buf[BUFSIZ], *sizep;
off_t hdr_pos = lseek(output_fd, 0, SEEK_CUR); int r, fd; int err = -EIO;
staticint copy_event_system(constchar *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;
}
for_each_event_tps(dir, dent, tps) { if (!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++;
}
staticint record_ftrace_files(struct tracepoint_path *tps)
{ char *path; int ret;
path = get_events_file("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;
}
staticbool system_in_tp_list(char *sys, struct tracepoint_path *tps)
{ while (tps) { if (!strcmp(sys, tps->system)) returntrue;
tps = tps->next;
}
returnfalse;
}
staticint 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;
}
staticint record_proc_kallsyms(void)
{ unsignedlonglong 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;
}
staticint record_ftrace_printk(void)
{ unsignedint 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;
}
staticint record_saved_cmdline(void)
{ unsignedlonglong size; char *path; struct stat st; int ret, err = 0;
path = get_tracing_file("saved_cmdlines"); if (!path) {
pr_debug("can't get tracing/saved_cmdline"); return -ENOMEM;
}
ret = stat(path, &st); if (ret < 0) { /* not found */
size = 0; if (write(output_fd, &size, 8) != 8)
err = -EIO; goto out;
}
err = record_file(path, 8);
/* * 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(); if (err) goto out;
err = record_saved_cmdline();
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;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.