On Fri, 29 Oct 2021 21:26:05 +0200 Daniel Bristot de Oliveira <bristot@xxxxxxxxxx> wrote: > +/* > + * enable_tracer_by_name - enable a tracer on the given instance > + */ > +int enable_tracer_by_name(struct tracefs_instance *inst, const char *tracer) > +{ > + enum tracefs_tracers t; > + int retval; > + > + t = TRACEFS_TRACER_CUSTOM; > + > + debug_msg("enabling %s tracer\n", tracer); > + > + retval = tracefs_tracer_set(inst, t, tracer); Interesting. We had discussions about having the custom option (which I fought for, for this very reason). > + if (retval < 0) { > + if (errno == ENODEV) > + err_msg("tracer %s not found!\n", tracer); > + > + err_msg("failed to enable the tracer %s\n", tracer); > + return -1; > + } > + > + return 0; > +} > + > +/* > + * disable_tracer - set nop tracer to the insta > + */ > +void disable_tracer(struct tracefs_instance *inst) > +{ > + enum tracefs_tracers t = TRACEFS_TRACER_NOP; > + int retval; > + > + retval = tracefs_tracer_set(inst, t); > + if (retval < 0) > + err_msg("oops, error disabling tracer\n"); > +} > + > +/* > + * create_instance - create a trace instance with *instance_name > + */ > +struct tracefs_instance *create_instance(char *instance_name) > +{ > + return tracefs_instance_create(instance_name); > +} > + > +/* > + * destroy_instance - remove a trace instance and free the data > + */ > +void destroy_instance(struct tracefs_instance *inst) > +{ > + tracefs_instance_destroy(inst); > + tracefs_instance_free(inst); > +} > + > +/* > + * save_trace_to_file - save the trace output of the instance to the file > + */ > +int save_trace_to_file(struct tracefs_instance *inst, const char *filename) > +{ > + const char *file = "trace"; > + mode_t mode = 0644; > + char *buffer[4096]; Did you really mean to have buffer be 4096 strings? Or did you mean: char buffer[4096]; (i.e. a single string of 4096 size)? -- Steve > + int out_fd, in_fd; > + int retval = -1; > + > + in_fd = tracefs_instance_file_open(inst, file, O_RDONLY); > + if (in_fd < 0) { > + err_msg("Failed to open trace file\n"); > + return -1; > + } > + > + out_fd = creat(filename, mode); > + if (out_fd < 0) { > + err_msg("Failed to create output file %s\n", filename); > + goto out_close_in; > + } > + > + do { > + retval = read(in_fd, buffer, sizeof(buffer)); > + if (retval <= 0) > + goto out_close; > + > + retval = write(out_fd, buffer, retval); > + if (retval < 0) > + goto out_close; > + } while (retval > 0); > + > + retval = 0; > +out_close: > + close(out_fd); > +out_close_in: > + close(in_fd); > + return retval; > +} > + > +/*