📄 export_text.c
字号:
/* Copyright (C) 2004,2005,2006 Bull S.A. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#if HAVE_CONFIG_H#include <config.h>#endif#include "time.h"#include "types.h"#include "modules.h"extern ptt_event_data_t ptt_event_array[];static ptt_header_t *head;static int print_pid;static int time_div;static int init (ptt_header_t *header, int display, int time_division) { head = header; print_pid = display; time_div = time_division; return 0;}static inline int write_header (FILE *fd) { char start_date [50]; strftime (start_date, sizeof (start_date), "%a, %d %b %Y %H:%M:%S %z", localtime (&head->start_time)); return fprintf (fd, "#\tPTT version %d.%d.\n" "#\tThe trace was generated on %s on %s.\n" "#\tThis file is the number %d.\n#\n#\n", head->version.major, head->version.minor, head->architecture, start_date,head->file_number);} static int init_file_raw (FILE *fd, FILE *old_fd) { int ret = write_header (fd); if (ret < 0) return ret; if (print_pid) fprintf(fd, "# timestamp : event-id : process-id : thread-id : arg1 " ": arg2 : arg3 : arg4 : arg5\n#\n"); else fprintf(fd, "# timestamp : event-id : thread-id : arg1 : arg2 : arg3 " ": arg4 : arg5\n#\n"); if (ret < 0) return ret; else return 0;}static int init_file_text (FILE *fd, FILE *old_fd) { int ret = write_header (fd); if (ret < 0) return ret; else return 0;}static int write_raw (FILE *fd, ptt_timestamp_t time, pid_t pid, ptt_event_t event, char **tn, int *ti, unsigned int *tu, long long *tll) { /* precondition : event is in the bounds and checksum is correct */ int ret; ptt_event_data_t *evt_data = ptt_event_array + event; int arg_ind = 0; int cnt_n = 0; int cnt_i = 0; int cnt_u = 0; int cnt_ll = 0; if (time_div) ret = fprintf (fd, "%014.6Lf : %-25s : ", (long double)time/1000000.0, evt_data->name); else ret = fprintf (fd, "%014llu : %-25s : ", time, evt_data->name); if (ret < 0) return ret; if (print_pid) ret = fprintf(fd, "%d : %s", pid, tn[cnt_n++]); else ret = fprintf(fd, "%s", tn[cnt_n++]); if (ret < 0) return ret; if (evt_data->flags) arg_ind = 1; /* read each data in the event */ for (; arg_ind < evt_data->nargs; arg_ind++) { switch (evt_data->arg_type[arg_ind]) { case PTT_INT: ret = fprintf (fd, " : %d", ti[cnt_i++]); break; case PTT_PTR: ret = fprintf (fd, " : %s", tn[cnt_n++]); break; case PTT_UINT: ret = fprintf (fd, " : %u", tu[cnt_u++]); break; case PTT_ULL: ret = fprintf (fd, " : %llu", tll[cnt_ll++]); break; default: fprintf (stderr, "INVALID TYPE OF ARGUMENT\n"); return -1; } if (ret < 0) return ret; } ret = fprintf(fd, "\n"); if (ret < 0) return ret; return 0;}static int write_text (FILE *fd, ptt_timestamp_t time, pid_t pid, ptt_event_t event, char **tn, int *ti, unsigned int *tu, long long *tll) { /* precondition : event is in the bounds and checksum is correct */ int ret; ptt_event_data_t *evt_data = ptt_event_array + event; const char *v_descr; int arg_ind = 0; int cnt_n = 0; int cnt_i = 0; int cnt_u = 0; int cnt_ll = 0; if (time_div) ret = fprintf (fd, "%014.6Lf ", (long double)time/1000000.0); else ret = fprintf (fd, "%014llu ", time); if (ret < 0) return ret; if (print_pid) ret = fprintf (fd, "Pid %d, Thread %s", pid, tn[cnt_n++]); else ret = fprintf (fd, "Thread %s", tn[cnt_n++]); if (ret < 0) return ret; if (evt_data->flags) arg_ind = 1; /* read each data in the event */ for(; arg_ind < evt_data->nargs; arg_ind++) { v_descr = evt_data->descr[arg_ind]; switch (evt_data->arg_type[arg_ind]) { case PTT_INT: ret = fprintf (fd, "%s%d", v_descr, ti[cnt_i++]); break; case PTT_PTR: ret = fprintf (fd, "%s%s", v_descr, tn[cnt_n++]); break; case PTT_UINT: ret = fprintf (fd, "%s%u", v_descr, tu[cnt_u++]); break; case PTT_ULL: ret = fprintf (fd, "%s%llu", v_descr, tll[cnt_ll++]); break; default: fprintf (stderr, "INVALID TYPE OF ARGUMENT\n"); ret = -1; } if (ret < 0) return ret; } v_descr = evt_data->descr[arg_ind]; ret = fprintf (fd, "%s\n", v_descr); if (ret < 0) return ret; return 0;}static void close () { return; /* nothing to do */ }struct export export_raw = { .init = init, .init_file = init_file_raw, .write = write_raw, .close = close};struct export export_text = { .init = init, .init_file = init_file_text, .write = write_text, .close = close};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -