/* return TRUE if a command match, FALSE if not */ static TBOOLEAN show_two() { if (almost_equals(c_token, "p$lot")) { (void) putc('\n', stderr); show_plot(); c_token++; } else if (almost_equals(c_token, "par$ametric")) { (void) putc('\n', stderr); show_parametric(); c_token++; } else if (almost_equals(c_token, "poi$ntsize")) { (void) putc('\n', stderr); show_pointsize(); c_token++; } else if (almost_equals(c_token, "enc$oding")) { (void) putc('\n', stderr); show_encoding(); c_token++; } else if (almost_equals(c_token, "pol$ar")) { (void) putc('\n', stderr); show_polar(); c_token++; } else if (almost_equals(c_token, "an$gles")) { (void) putc('\n', stderr); show_angles(); c_token++; } else if (almost_equals(c_token, "ti$cs")) { (void) putc('\n', stderr); show_tics(TRUE, TRUE, TRUE, TRUE, TRUE); c_token++; } else if (almost_equals(c_token, "tim$estamp")) { (void) putc('\n', stderr); show_xyzlabel("time", &timelabel); fprintf(stderr, "\twritten in %s corner\n", (timelabel_bottom ? "bottom" : "top")); if (timelabel_rotate) fputs("\trotated if the terminal allows it\n\t", stderr); else fputs("\tnot rotated\n\t", stderr); c_token++; } else if (almost_equals(c_token, "su$rface")) { (void) putc('\n', stderr); show_surface(); c_token++; } else if (almost_equals(c_token, "hi$dden3d")) { (void) putc('\n', stderr); show_hidden3d(); c_token++; } else if (almost_equals(c_token, "cla$bel")) { (void) putc('\n', stderr); show_label_contours(); c_token++; } else if (almost_equals(c_token, "xti$cs")) { show_tics(TRUE, FALSE, FALSE, TRUE, FALSE); c_token++; } else if (almost_equals(c_token, "yti$cs")) { show_tics(FALSE, TRUE, FALSE, FALSE, TRUE); c_token++; } else if (almost_equals(c_token, "zti$cs")) { show_tics(FALSE, FALSE, TRUE, FALSE, FALSE); c_token++; } else if (almost_equals(c_token, "x2ti$cs")) { show_tics(FALSE, FALSE, FALSE, TRUE, FALSE); c_token++; } else if (almost_equals(c_token, "y2ti$cs")) { show_tics(FALSE, FALSE, FALSE, FALSE, TRUE); c_token++; } else if (almost_equals(c_token, "xdti$cs")) { show_tics(TRUE, FALSE, FALSE, TRUE, FALSE); c_token++; } else if (almost_equals(c_token, "ydti$cs")) { show_tics(FALSE, TRUE, FALSE, FALSE, TRUE); c_token++; } else if (almost_equals(c_token, "zdti$cs")) { show_tics(FALSE, FALSE, TRUE, FALSE, FALSE); c_token++; } else if (almost_equals(c_token, "x2dti$cs")) { show_tics(FALSE, FALSE, FALSE, TRUE, FALSE); c_token++; } else if (almost_equals(c_token, "y2dti$cs")) { show_tics(FALSE, FALSE, FALSE, FALSE, TRUE); c_token++; } else if (almost_equals(c_token, "xmti$cs")) { show_tics(TRUE, FALSE, FALSE, TRUE, FALSE); c_token++; } else if (almost_equals(c_token, "ymti$cs")) { show_tics(FALSE, TRUE, FALSE, FALSE, TRUE); c_token++; } else if (almost_equals(c_token, "zmti$cs")) { show_tics(FALSE, FALSE, TRUE, FALSE, FALSE); c_token++; } else if (almost_equals(c_token, "x2mti$cs")) { show_tics(FALSE, FALSE, FALSE, TRUE, FALSE); c_token++; } else if (almost_equals(c_token, "y2mti$cs")) { show_tics(FALSE, FALSE, FALSE, FALSE, TRUE); c_token++; } else if (almost_equals(c_token, "sa$mples")) { (void) putc('\n', stderr); show_samples(); c_token++; } else if (almost_equals(c_token, "isosa$mples")) { (void) putc('\n', stderr); show_isosamples(); c_token++; } else if (almost_equals(c_token, "si$ze")) { (void) putc('\n', stderr); show_size(); c_token++; } else if (almost_equals(c_token, "orig$in")) { (void) putc('\n', stderr); show_origin(); c_token++; } else if (almost_equals(c_token, "t$erminal")) { (void) putc('\n', stderr); show_term(); c_token++; } else if (almost_equals(c_token, "rr$ange")) { (void) putc('\n', stderr); show_range(R_AXIS, rmin, rmax, autoscale_r, "r"); c_token++; } else if (almost_equals(c_token, "tr$ange")) { (void) putc('\n', stderr); show_range(T_AXIS, tmin, tmax, autoscale_t, "t"); c_token++; } else if (almost_equals(c_token, "ur$ange")) { (void) putc('\n', stderr); show_range(U_AXIS, umin, umax, autoscale_u, "u"); c_token++; } else if (almost_equals(c_token, "vi$ew")) { (void) putc('\n', stderr); show_view(); c_token++; } else if (almost_equals(c_token, "vr$ange")) { (void) putc('\n', stderr); show_range(V_AXIS, vmin, vmax, autoscale_v, "v"); c_token++; } else if (almost_equals(c_token, "v$ariables")) { show_variables(); c_token++; } else if (almost_equals(c_token, "ve$rsion")) { show_version(stderr); } else if (almost_equals(c_token, "xr$ange")) { (void) putc('\n', stderr); show_range(FIRST_X_AXIS, xmin, xmax, autoscale_x, "x"); c_token++; } else if (almost_equals(c_token, "yr$ange")) { (void) putc('\n', stderr); show_range(FIRST_Y_AXIS, ymin, ymax, autoscale_y, "y"); c_token++; } else if (almost_equals(c_token, "x2r$ange")) { (void) putc('\n', stderr); show_range(SECOND_X_AXIS, x2min, x2max, autoscale_x2, "x2"); c_token++; } else if (almost_equals(c_token, "y2r$ange")) { (void) putc('\n', stderr); show_range(SECOND_Y_AXIS, y2min, y2max, autoscale_y2, "y2"); c_token++; } else if (almost_equals(c_token, "zr$ange")) { (void) putc('\n', stderr); show_range(FIRST_Z_AXIS, zmin, zmax, autoscale_z, "z"); c_token++; } else if (almost_equals(c_token, "z$ero")) { (void) putc('\n', stderr); show_zero(); c_token++; } else if (almost_equals(c_token, "a$ll")) { c_token++; show_version(stderr); show_autoscale(); show_bars(); show_border(); show_boxwidth(); show_clip(); show_contour(); show_dgrid3d(); show_mapping(); (void) fprintf(stderr, "\tdummy variables are \"%s\" and \"%s\"\n", dummy_var[0], dummy_var[1]); show_format(); show_style("data", data_style); show_style("functions", func_style); show_grid(); show_xzeroaxis(); show_yzeroaxis(); show_label(0); show_arrow(0); show_linestyle(0); show_keytitle(); show_key(); show_logscale(); show_offsets(); show_margin(); show_output(); show_parametric(); show_pointsize(); show_encoding(); show_polar(); show_angles(); show_samples(); show_isosamples(); show_view(); show_surface(); #ifndef LITE show_hidden3d(); #endif show_size(); show_origin(); show_term(); show_tics(TRUE, TRUE, TRUE, TRUE, TRUE); show_mtics(mxtics, mxtfreq, "x"); show_mtics(mytics, mytfreq, "y"); show_mtics(mztics, mztfreq, "z"); show_mtics(mx2tics, mx2tfreq, "x2"); show_mtics(my2tics, my2tfreq, "y2"); show_xyzlabel("time", &timelabel); if (parametric || polar) { if (!is_3d_plot) show_range(T_AXIS, tmin, tmax, autoscale_t, "t"); else { show_range(U_AXIS, umin, umax, autoscale_u, "u"); show_range(V_AXIS, vmin, vmax, autoscale_v, "v"); } } show_range(FIRST_X_AXIS, xmin, xmax, autoscale_x, "x"); show_range(FIRST_Y_AXIS, ymin, ymax, autoscale_y, "y"); show_range(SECOND_X_AXIS, x2min, x2max, autoscale_x2, "x2"); show_range(SECOND_Y_AXIS, y2min, y2max, autoscale_y2, "y2"); show_range(FIRST_Z_AXIS, zmin, zmax, autoscale_z, "z"); show_xyzlabel("title", &title); show_xyzlabel("xlabel", &xlabel); show_xyzlabel("ylabel", &ylabel); show_xyzlabel("zlabel", &zlabel); show_xyzlabel("x2label", &x2label); show_xyzlabel("y2label", &y2label); show_datatype("xdata", FIRST_X_AXIS); show_datatype("ydata", FIRST_Y_AXIS); show_datatype("x2data", SECOND_X_AXIS); show_datatype("y2data", SECOND_Y_AXIS); show_datatype("zdata", FIRST_Z_AXIS); show_timefmt(); show_locale(); show_zero(); show_missing(); show_plot(); show_variables(); show_functions(); c_token++; } else return (FALSE); return (TRUE); }
int main (int argc, char **argv) { int c; errno = 0; if (argc < 2) usage(argv); if (strcmp(argv[1], "report") == 0) { trace_report(argc, argv); exit(0); } else if (strcmp(argv[1], "snapshot") == 0) { trace_snapshot(argc, argv); exit(0); } else if (strcmp(argv[1], "hist") == 0) { trace_hist(argc, argv); exit(0); } else if (strcmp(argv[1], "mem") == 0) { trace_mem(argc, argv); exit(0); } else if (strcmp(argv[1], "listen") == 0) { trace_listen(argc, argv); exit(0); } else if (strcmp(argv[1], "split") == 0) { trace_split(argc, argv); exit(0); } else if (strcmp(argv[1], "restore") == 0) { trace_restore(argc, argv); exit(0); } else if (strcmp(argv[1], "stack") == 0) { trace_stack(argc, argv); exit(0); } else if (strcmp(argv[1], "check-events") == 0) { const char *tracing; int ret; struct pevent *pevent = NULL; struct plugin_list *list = NULL; while ((c = getopt(argc-1, argv+1, "+hN")) >= 0) { switch (c) { case 'h': default: usage(argv); break; case 'N': tracecmd_disable_plugins = 1; break; } } tracing = tracecmd_get_tracing_dir(); if (!tracing) { printf("Can not find or mount tracing directory!\n" "Either tracing is not configured for this " "kernel\n" "or you do not have the proper permissions to " "mount the directory"); exit(EINVAL); } pevent = pevent_alloc(); if (!pevent) exit(EINVAL); list = tracecmd_load_plugins(pevent); ret = tracecmd_fill_local_events(tracing, pevent); if (ret || pevent->parsing_failures) ret = EINVAL; tracecmd_unload_plugins(list, pevent); pevent_free(pevent); exit(ret); } else if (strcmp(argv[1], "record") == 0 || strcmp(argv[1], "start") == 0 || strcmp(argv[1], "extract") == 0 || strcmp(argv[1], "stop") == 0 || strcmp(argv[1], "stream") == 0 || strcmp(argv[1], "profile") == 0 || strcmp(argv[1], "restart") == 0 || strcmp(argv[1], "reset") == 0) { trace_record(argc, argv); exit(0); } else if (strcmp(argv[1], "stat") == 0) { trace_stat(argc, argv); exit(0); } else if (strcmp(argv[1], "options") == 0) { show_plugin_options(); exit(0); } else if (strcmp(argv[1], "show") == 0) { const char *buffer = NULL; const char *file = "trace"; const char *cpu = NULL; struct buffer_instance *instance = &top_instance; char cpu_path[128]; char *path; int snap = 0; int pipe = 0; int show_name = 0; int option_index = 0; int stop = 0; static struct option long_options[] = { {"tracing_on", no_argument, NULL, OPT_tracing_on}, {"current_tracer", no_argument, NULL, OPT_current_tracer}, {"buffer_size", no_argument, NULL, OPT_buffer_size_kb}, {"buffer_total_size", no_argument, NULL, OPT_buffer_total_size_kb}, {"ftrace_filter", no_argument, NULL, OPT_ftrace_filter}, {"ftrace_notrace", no_argument, NULL, OPT_ftrace_notrace}, {"ftrace_pid", no_argument, NULL, OPT_ftrace_pid}, {"graph_function", no_argument, NULL, OPT_graph_function}, {"graph_notrace", no_argument, NULL, OPT_graph_notrace}, {"cpumask", no_argument, NULL, OPT_cpumask}, {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} }; while ((c = getopt_long(argc-1, argv+1, "B:c:fsp", long_options, &option_index)) >= 0) { switch (c) { case 'h': usage(argv); break; case 'B': if (buffer) die("Can only show one buffer at a time"); buffer = optarg; instance = create_instance(optarg); if (!instance) die("Failed to create instance"); break; case 'c': if (cpu) die("Can only show one CPU at a time"); cpu = optarg; break; case 'f': show_name = 1; break; case 's': snap = 1; if (pipe) die("Can not have -s and -p together"); break; case 'p': pipe = 1; if (snap) die("Can not have -s and -p together"); break; case OPT_tracing_on: show_instance_file(instance, "tracing_on"); stop = 1; break; case OPT_current_tracer: show_instance_file(instance, "current_tracer"); stop = 1; break; case OPT_buffer_size_kb: show_instance_file(instance, "buffer_size_kb"); stop = 1; break; case OPT_buffer_total_size_kb: show_instance_file(instance, "buffer_total_size_kb"); stop = 1; break; case OPT_ftrace_filter: show_instance_file(instance, "set_ftrace_filter"); stop = 1; break; case OPT_ftrace_notrace: show_instance_file(instance, "set_ftrace_notrace"); stop = 1; break; case OPT_ftrace_pid: show_instance_file(instance, "set_ftrace_pid"); stop = 1; break; case OPT_graph_function: show_instance_file(instance, "set_graph_function"); stop = 1; break; case OPT_graph_notrace: show_instance_file(instance, "set_graph_notrace"); stop = 1; break; case OPT_cpumask: show_instance_file(instance, "tracing_cpumask"); stop = 1; break; default: usage(argv); } } if (stop) exit(0); if (pipe) file = "trace_pipe"; else if (snap) file = "snapshot"; if (cpu) { snprintf(cpu_path, 128, "per_cpu/cpu%d/%s", atoi(cpu), file); file = cpu_path; } if (buffer) { path = malloc(strlen(buffer) + strlen("instances//") + strlen(file) + 1); if (path) die("Failed to allocate instance path %s", file); sprintf(path, "instances/%s/%s", buffer, file); file = path; } if (show_name) { char *name; name = tracecmd_get_tracing_file(file); printf("%s\n", name); tracecmd_put_tracing_file(name); } show_file(file); if (buffer) free(path); exit(0); } else if (strcmp(argv[1], "list") == 0) { int events = 0; int tracer = 0; int options = 0; int funcs = 0; int buffers = 0; int clocks = 0; int plug = 0; int plug_op = 0; int flags = 0; int show_all = 1; int i; const char *arg; const char *funcre = NULL; const char *eventre = NULL; for (i = 2; i < argc; i++) { arg = NULL; if (argv[i][0] == '-') { if (i < argc - 1) { if (argv[i+1][0] != '-') arg = argv[i+1]; } switch (argv[i][1]) { case 'h': usage(argv); break; case 'e': events = 1; eventre = arg; show_all = 0; break; case 'B': buffers = 1; show_all = 0; break; case 'C': clocks = 1; show_all = 0; break; case 'F': flags |= SHOW_EVENT_FORMAT; break; case 'R': flags |= SHOW_EVENT_TRIGGER; break; case 'l': flags |= SHOW_EVENT_FILTER; break; case 'p': case 't': tracer = 1; show_all = 0; break; case 'P': plug = 1; show_all = 0; break; case 'O': plug_op = 1; show_all = 0; break; case 'o': options = 1; show_all = 0; break; case 'f': funcs = 1; funcre = arg; show_all = 0; break; default: fprintf(stderr, "list: invalid option -- '%c'\n", argv[optind][1]); usage(argv); } } } if (events) show_events(eventre, flags); if (tracer) show_tracers(); if (options) show_options(); if (plug) show_plugins(); if (plug_op) show_plugin_options(); if (funcs) show_functions(funcre); if (buffers) show_buffers(); if (clocks) show_clocks(); if (show_all) { printf("events:\n"); show_events(NULL, 0); printf("\ntracers:\n"); show_tracers(); printf("\noptions:\n"); show_options(); } exit(0); } else if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "help") == 0) { usage(argv); } else { fprintf(stderr, "unknown command: %s\n", argv[1]); usage(argv); } return 0; }
/* return TRUE if a command match, FALSE if not */ static TBOOLEAN show_one() { if (almost_equals(c_token, "ac$tion_table") || equals(c_token, "at")) { c_token++; show_at(); c_token++; } else if (almost_equals(c_token, "ar$row")) { struct value a; int tag = 0; c_token++; if (!END_OF_COMMAND) { tag = (int) real(const_express(&a)); if (tag <= 0) int_error("tag must be > zero", c_token); } (void) putc('\n', stderr); show_arrow(tag); } else if (almost_equals(c_token, "au$toscale")) { (void) putc('\n', stderr); show_autoscale(); c_token++; } else if (almost_equals(c_token, "b$ars")) { (void) putc('\n', stderr); show_bars(); c_token++; } else if (almost_equals(c_token, "bor$der")) { (void) putc('\n', stderr); show_border(); c_token++; } else if (almost_equals(c_token, "box$width")) { (void) putc('\n', stderr); show_boxwidth(); c_token++; } else if (almost_equals(c_token, "c$lip")) { (void) putc('\n', stderr); show_clip(); c_token++; } else if (almost_equals(c_token, "ma$pping")) { (void) putc('\n', stderr); show_mapping(); c_token++; } else if (almost_equals(c_token, "co$ntour") || almost_equals(c_token, "cn$trparam")) { (void) putc('\n', stderr); show_contour(); c_token++; } else if (almost_equals(c_token, "da$ta")) { c_token++; if (!almost_equals(c_token, "s$tyle")) int_error("expecting keyword 'style'", c_token); (void) putc('\n', stderr); show_style("data", data_style); c_token++; } else if (almost_equals(c_token, "dg$rid3d")) { (void) putc('\n', stderr); show_dgrid3d(); c_token++; } else if (almost_equals(c_token, "du$mmy")) { (void) fprintf(stderr, "\n\tdummy variables are \"%s\" and \"%s\"\n", dummy_var[0], dummy_var[1]); c_token++; } else if (almost_equals(c_token, "fo$rmat")) { show_format(); c_token++; } else if (almost_equals(c_token, "fu$nctions")) { c_token++; if (almost_equals(c_token, "s$tyle")) { (void) putc('\n', stderr); show_style("functions", func_style); c_token++; } else show_functions(); } else if (almost_equals(c_token, "lo$gscale")) { (void) putc('\n', stderr); show_logscale(); c_token++; } else if (almost_equals(c_token, "of$fsets")) { (void) putc('\n', stderr); show_offsets(); c_token++; } else if (almost_equals(c_token, "ma$rgin")) { (void) putc('\n', stderr); show_margin(); c_token++; } else if (almost_equals(c_token, "o$utput")) { (void) putc('\n', stderr); show_output(); c_token++; } else if (almost_equals(c_token, "tit$le")) { (void) putc('\n', stderr); show_xyzlabel("title", &title); c_token++; } else if (almost_equals(c_token, "mis$sing")) { (void) putc('\n', stderr); show_missing(); c_token++; } else if (almost_equals(c_token, "xl$abel")) { (void) putc('\n', stderr); show_xyzlabel("xlabel", &xlabel); c_token++; } else if (almost_equals(c_token, "x2l$abel")) { (void) putc('\n', stderr); show_xyzlabel("x2label", &x2label); c_token++; } else if (almost_equals(c_token, "yl$abel")) { (void) putc('\n', stderr); show_xyzlabel("ylabel", &ylabel); c_token++; } else if (almost_equals(c_token, "y2l$abel")) { (void) putc('\n', stderr); show_xyzlabel("y2label", &y2label); c_token++; } else if (almost_equals(c_token, "zl$abel")) { (void) putc('\n', stderr); show_xyzlabel("zlabel", &zlabel); c_token++; } else if (almost_equals(c_token, "keyt$itle")) { (void) putc('\n', stderr); show_keytitle(); c_token++; } else if (almost_equals(c_token, "xda$ta")) { (void) putc('\n', stderr); show_datatype("xdata", FIRST_X_AXIS); c_token++; } else if (almost_equals(c_token, "yda$ta")) { (void) putc('\n', stderr); show_datatype("ydata", FIRST_Y_AXIS); c_token++; } else if (almost_equals(c_token, "x2da$ta")) { (void) putc('\n', stderr); show_datatype("x2data", SECOND_X_AXIS); c_token++; } else if (almost_equals(c_token, "y2da$ta")) { (void) putc('\n', stderr); show_datatype("y2data", SECOND_Y_AXIS); c_token++; } else if (almost_equals(c_token, "zda$ta")) { (void) putc('\n', stderr); show_datatype("zdata", FIRST_Z_AXIS); c_token++; } else if (almost_equals(c_token, "timef$mt")) { (void) putc('\n', stderr); show_timefmt(); c_token++; } else if (almost_equals(c_token, "loca$le")) { (void) putc('\n', stderr); show_locale(); c_token++; } else if (almost_equals(c_token, "xzero$axis")) { (void) putc('\n', stderr); show_xzeroaxis(); c_token++; } else if (almost_equals(c_token, "yzero$axis")) { (void) putc('\n', stderr); show_yzeroaxis(); c_token++; } else if (almost_equals(c_token, "zeroa$xis")) { (void) putc('\n', stderr); show_xzeroaxis(); show_yzeroaxis(); c_token++; } else if (almost_equals(c_token, "la$bel")) { struct value a; int tag = 0; c_token++; if (!END_OF_COMMAND) { tag = (int) real(const_express(&a)); if (tag <= 0) int_error("tag must be > zero", c_token); } (void) putc('\n', stderr); show_label(tag); } else if (almost_equals(c_token, "li$nestyle") || equals(c_token, "ls")) { struct value a; int tag = 0; c_token++; if (!END_OF_COMMAND) { tag = (int) real(const_express(&a)); if (tag <= 0) int_error("tag must be > zero", c_token); } (void) putc('\n', stderr); show_linestyle(tag); } else if (almost_equals(c_token, "g$rid")) { (void) putc('\n', stderr); show_grid(); c_token++; } else if (almost_equals(c_token, "mxt$ics")) { (void) putc('\n', stderr); show_mtics(mxtics, mxtfreq, "x"); c_token++; } else if (almost_equals(c_token, "myt$ics")) { (void) putc('\n', stderr); show_mtics(mytics, mytfreq, "y"); c_token++; } else if (almost_equals(c_token, "mzt$ics")) { (void) putc('\n', stderr); show_mtics(mztics, mztfreq, "z"); c_token++; } else if (almost_equals(c_token, "mx2t$ics")) { (void) putc('\n', stderr); show_mtics(mx2tics, mx2tfreq, "x2"); c_token++; } else if (almost_equals(c_token, "my2t$ics")) { (void) putc('\n', stderr); show_mtics(my2tics, my2tfreq, "y2"); c_token++; } else if (almost_equals(c_token, "k$ey")) { (void) putc('\n', stderr); show_key(); c_token++; } else return (FALSE); return TRUE; }