1*287e80b3SSadaf Ebrahimilibtracefs(3) 2*287e80b3SSadaf Ebrahimi============= 3*287e80b3SSadaf Ebrahimi 4*287e80b3SSadaf EbrahimiNAME 5*287e80b3SSadaf Ebrahimi---- 6*287e80b3SSadaf Ebrahimitracefs_tracers, tracefs_tracer_available, tracefs_get_clock, tracefs_list_free, 7*287e80b3SSadaf Ebrahimitracefs_list_add, tracefs_list_size - Helper functions for working with trace file system. 8*287e80b3SSadaf Ebrahimi 9*287e80b3SSadaf EbrahimiSYNOPSIS 10*287e80b3SSadaf Ebrahimi-------- 11*287e80b3SSadaf Ebrahimi[verse] 12*287e80b3SSadaf Ebrahimi-- 13*287e80b3SSadaf Ebrahimi*#include <tracefs.h>* 14*287e80b3SSadaf Ebrahimi 15*287e80b3SSadaf Ebrahimichar pass:[*]pass:[*]*tracefs_tracers*(const char pass:[*]_tracing_dir_); 16*287e80b3SSadaf Ebrahimibool *tracefs_tracer_available*(const char pass:[*]_tracing_dir_, const char pass:[*]_tracer_); 17*287e80b3SSadaf Ebrahimichar pass:[*]*tracefs_get_clock*(struct tracefs_instance pass:[*]_instance_); 18*287e80b3SSadaf Ebrahimivoid *tracefs_list_free*(char pass:[*]pass:[*]_list_); 19*287e80b3SSadaf Ebrahimichar pass:[**]*tracefs_list_add*(char **_list_, const char *_string_); 20*287e80b3SSadaf Ebrahimiint *tracefs_list_size*(char pass:[**]_list_); 21*287e80b3SSadaf Ebrahimi-- 22*287e80b3SSadaf Ebrahimi 23*287e80b3SSadaf EbrahimiDESCRIPTION 24*287e80b3SSadaf Ebrahimi----------- 25*287e80b3SSadaf EbrahimiVarious useful functions for working with trace file system. 26*287e80b3SSadaf Ebrahimi 27*287e80b3SSadaf EbrahimiThe *tracefs_tracers()* function returns array of strings with the 28*287e80b3SSadaf Ebrahiminames of supported tracer plugins, located in the given _tracing_dir_ 29*287e80b3SSadaf Ebrahimidirectory. This could be NULL or the location of the tracefs mount point 30*287e80b3SSadaf Ebrahimifor the trace systems of the local machine, or it may be a path to a copy 31*287e80b3SSadaf Ebrahimiof the tracefs directory from another machine. The last entry in the array 32*287e80b3SSadaf Ebrahimias a NULL pointer. The array must be freed with *tracefs_list_free()* API. 33*287e80b3SSadaf Ebrahimi 34*287e80b3SSadaf EbrahimiThe *tracefs_tracer_available()* returns true if the _tracer_ is available 35*287e80b3SSadaf Ebrahimiin the given _tracing_dir_director_, and false otherwise. 36*287e80b3SSadaf Ebrahimi 37*287e80b3SSadaf EbrahimiThe *tracefs_get_clock()* function returns name of the current trace clock, 38*287e80b3SSadaf Ebrahimiused in the given _instance_. If _instance_ is NULL, the clock of the main 39*287e80b3SSadaf Ebrahimitrace instance is returned. The returned string must be freed with free(). 40*287e80b3SSadaf Ebrahimi 41*287e80b3SSadaf EbrahimiThe *tracefs_list_free()* function frees an array of strings, returned by 42*287e80b3SSadaf Ebrahimi*tracefs_event_systems()*, *tracefs_system_events()* and *tracefs_tracers()* 43*287e80b3SSadaf EbrahimiAPIs. 44*287e80b3SSadaf Ebrahimi 45*287e80b3SSadaf EbrahimiThe *tracefs_list_add()* function adds _string_ to the string _list_. If 46*287e80b3SSadaf Ebrahimi_list_ is NULL, then a new list is created with the first element a copy 47*287e80b3SSadaf Ebrahimiof _string_, and the second element will be a NULL pointer. If _list_ is 48*287e80b3SSadaf Ebrahiminot NULL, then it is reallocated to include a new element and a NULL terminator, 49*287e80b3SSadaf Ebrahimiand the new allocated array is returned. The list passed in should be ignored, 50*287e80b3SSadaf Ebrahimias it wil be freed if a new one was allocated. 51*287e80b3SSadaf Ebrahimi 52*287e80b3SSadaf EbrahimiThe *tracefs_list_size()* is a fast way to find out the number of elements 53*287e80b3SSadaf Ebrahimiin a string array that is to be freed with *tracefs_list_free()*. Note, this 54*287e80b3SSadaf Ebrahimidepends on meta data that is created for these lists and will not work on 55*287e80b3SSadaf Ebrahiminormal string arrays like argv. 56*287e80b3SSadaf Ebrahimi 57*287e80b3SSadaf EbrahimiRETURN VALUE 58*287e80b3SSadaf Ebrahimi------------ 59*287e80b3SSadaf EbrahimiThe *tracefs_tracers()* returns array of strings. The last element in that 60*287e80b3SSadaf Ebrahimiarray is a NULL pointer. The array must be freed with *tracefs_list_free()* API. 61*287e80b3SSadaf EbrahimiIn case of an error, NULL is returned. 62*287e80b3SSadaf Ebrahimi 63*287e80b3SSadaf EbrahimiThe *tracefs_tracer_available()* returns true if the _tracer_ is available, 64*287e80b3SSadaf Ebrahimiand false otherwise. 65*287e80b3SSadaf Ebrahimi 66*287e80b3SSadaf EbrahimiThe *tracefs_get_clock()* returns string, that must be freed with free(), or NULL 67*287e80b3SSadaf Ebrahimiin case of an error. 68*287e80b3SSadaf Ebrahimi 69*287e80b3SSadaf EbrahimiThe *tracefs_list_add()* returns an allocated string array that must be freed 70*287e80b3SSadaf Ebrahimiwith *tracefs_list_free()* on success or NULL on error. If NULL is returned, 71*287e80b3SSadaf Ebrahimithen the passed in _list_ is untouched. Thus, *tracefs_list_add()* should be 72*287e80b3SSadaf Ebrahimitreated similarly to *realloc*(3). 73*287e80b3SSadaf Ebrahimi 74*287e80b3SSadaf EbrahimiThe *tracefs_list_size()* returns the number of strings in the _list_. The 75*287e80b3SSadaf Ebrahimipassed in list must be one that is to be freed with *tracefs_list_free()* 76*287e80b3SSadaf Ebrahimias the list has meta data that is used to determine the size and this does 77*287e80b3SSadaf Ebrahiminot work on any normal string array like argv. 78*287e80b3SSadaf Ebrahimi 79*287e80b3SSadaf EbrahimiEXAMPLE 80*287e80b3SSadaf Ebrahimi------- 81*287e80b3SSadaf Ebrahimi[source,c] 82*287e80b3SSadaf Ebrahimi-- 83*287e80b3SSadaf Ebrahimi#include <tracefs.h> 84*287e80b3SSadaf Ebrahimi 85*287e80b3SSadaf Ebrahimichar **tracers = tracefs_tracers(NULL); 86*287e80b3SSadaf Ebrahimi 87*287e80b3SSadaf Ebrahimi if (tracers) { 88*287e80b3SSadaf Ebrahimi /* Got tracer plugins from the top trace instance */ 89*287e80b3SSadaf Ebrahimi ... 90*287e80b3SSadaf Ebrahimi tracefs_list_free(tracers); 91*287e80b3SSadaf Ebrahimi } 92*287e80b3SSadaf Ebrahimi.... 93*287e80b3SSadaf Ebrahimichar *clock = tracefs_get_clock(NULL); 94*287e80b3SSadaf Ebrahimi 95*287e80b3SSadaf Ebrahimi if (clock) { 96*287e80b3SSadaf Ebrahimi /* Got current trace clock of the top trace instance */ 97*287e80b3SSadaf Ebrahimi ... 98*287e80b3SSadaf Ebrahimi free(clock); 99*287e80b3SSadaf Ebrahimi } 100*287e80b3SSadaf Ebrahimi-- 101*287e80b3SSadaf EbrahimiFILES 102*287e80b3SSadaf Ebrahimi----- 103*287e80b3SSadaf Ebrahimi[verse] 104*287e80b3SSadaf Ebrahimi-- 105*287e80b3SSadaf Ebrahimi*tracefs.h* 106*287e80b3SSadaf Ebrahimi Header file to include in order to have access to the library APIs. 107*287e80b3SSadaf Ebrahimi*-ltracefs* 108*287e80b3SSadaf Ebrahimi Linker switch to add when building a program that uses the library. 109*287e80b3SSadaf Ebrahimi-- 110*287e80b3SSadaf Ebrahimi 111*287e80b3SSadaf EbrahimiSEE ALSO 112*287e80b3SSadaf Ebrahimi-------- 113*287e80b3SSadaf Ebrahimi*libtracefs*(3), 114*287e80b3SSadaf Ebrahimi*libtraceevent*(3), 115*287e80b3SSadaf Ebrahimi*trace-cmd*(1) 116*287e80b3SSadaf Ebrahimi 117*287e80b3SSadaf EbrahimiAUTHOR 118*287e80b3SSadaf Ebrahimi------ 119*287e80b3SSadaf Ebrahimi[verse] 120*287e80b3SSadaf Ebrahimi-- 121*287e80b3SSadaf Ebrahimi*Steven Rostedt* <[email protected]> 122*287e80b3SSadaf Ebrahimi*Tzvetomir Stoyanov* <[email protected]> 123*287e80b3SSadaf Ebrahimi-- 124*287e80b3SSadaf EbrahimiREPORTING BUGS 125*287e80b3SSadaf Ebrahimi-------------- 126*287e80b3SSadaf EbrahimiReport bugs to <[email protected]> 127*287e80b3SSadaf Ebrahimi 128*287e80b3SSadaf EbrahimiLICENSE 129*287e80b3SSadaf Ebrahimi------- 130*287e80b3SSadaf Ebrahimilibtracefs is Free Software licensed under the GNU LGPL 2.1 131*287e80b3SSadaf Ebrahimi 132*287e80b3SSadaf EbrahimiRESOURCES 133*287e80b3SSadaf Ebrahimi--------- 134*287e80b3SSadaf Ebrahimihttps://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ 135*287e80b3SSadaf Ebrahimi 136*287e80b3SSadaf EbrahimiCOPYING 137*287e80b3SSadaf Ebrahimi------- 138*287e80b3SSadaf EbrahimiCopyright \(C) 2020 VMware, Inc. Free use of this software is granted under 139*287e80b3SSadaf Ebrahimithe terms of the GNU Public License (GPL). 140