1*287e80b3SSadaf Ebrahimilibtracefs(3) 2*287e80b3SSadaf Ebrahimi============= 3*287e80b3SSadaf Ebrahimi 4*287e80b3SSadaf EbrahimiNAME 5*287e80b3SSadaf Ebrahimi---- 6*287e80b3SSadaf Ebrahimitracefs_get_tracing_file, tracefs_put_tracing_file, tracefs_tracing_dir, tracefs_debug_dir, tracefs_set_tracing_dir, 7*287e80b3SSadaf Ebrahimitracefs_tracing_dir_is_mounted - Find and set locations of trace directory and files. 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:[*]*tracefs_get_tracing_file*(const char pass:[*]_name_); 16*287e80b3SSadaf Ebrahimivoid *tracefs_put_tracing_file*(char pass:[*]_name_); 17*287e80b3SSadaf Ebrahimiconst char pass:[*]*tracefs_tracing_dir*(void); 18*287e80b3SSadaf Ebrahimiconst char pass:[*]*tracefs_debug_dir*(void); 19*287e80b3SSadaf Ebrahimiint *tracefs_set_tracing_dir*(char pass:[*]_tracing_dir_) 20*287e80b3SSadaf Ebrahimiint *tracefs_tracing_dir_is_mounted*(bool _mount_, const char pass:[**]_path_); 21*287e80b3SSadaf Ebrahimi-- 22*287e80b3SSadaf Ebrahimi 23*287e80b3SSadaf EbrahimiDESCRIPTION 24*287e80b3SSadaf Ebrahimi----------- 25*287e80b3SSadaf EbrahimiThis set of APIs can be used to find the full path of the trace file 26*287e80b3SSadaf Ebrahimisystem mount point and trace files in it. 27*287e80b3SSadaf Ebrahimi 28*287e80b3SSadaf EbrahimiThe *tracefs_set_tracing_dir()* function sets a custom location of the 29*287e80b3SSadaf Ebrahimisystem's tracing directory mount point. Usually, the library auto detects 30*287e80b3SSadaf Ebrahimiit using the information from the /proc/mounts file. Use this API only if the 31*287e80b3SSadaf Ebrahimimount point is not standard and cannot be detected by the library. The _tracing_dir_ 32*287e80b3SSadaf Ebrahimiargument can be NULL, in that case the custom location is deleted and the library 33*287e80b3SSadaf Ebrahimiauto detection logic is used. 34*287e80b3SSadaf Ebrahimi 35*287e80b3SSadaf EbrahimiThe *tracefs_get_tracing_file()* function returns the full path of the 36*287e80b3SSadaf Ebrahimifile with given _name_ in the trace file system. The function works 37*287e80b3SSadaf Ebrahimionly with files in the tracefs main directory, it is not trace instance 38*287e80b3SSadaf Ebrahimiaware. It is recommended to use *tracefs_instance_get_file()* and 39*287e80b3SSadaf Ebrahimi*tracefs_instance_get_dir()* instead. The returned string must be freed 40*287e80b3SSadaf Ebrahimiwith *tracefs_put_tracing_file()*. 41*287e80b3SSadaf Ebrahimi 42*287e80b3SSadaf EbrahimiThe *tracefs_put_tracing_file()* function frees trace file name, 43*287e80b3SSadaf Ebrahimireturned by *tracefs_get_tracing_file()*. 44*287e80b3SSadaf Ebrahimi 45*287e80b3SSadaf EbrahimiThe *tracefs_tracing_dir()* function returns the full path to the 46*287e80b3SSadaf Ebrahimitrace file system. In the first function call, the mount point of the 47*287e80b3SSadaf Ebrahimitracing file system is located, cached and returned. It will mount it, 48*287e80b3SSadaf Ebrahimiif it is not mounted. On any subsequent call the cached path is returned. 49*287e80b3SSadaf EbrahimiThe return string must _not_ be freed. 50*287e80b3SSadaf Ebrahimi 51*287e80b3SSadaf EbrahimiThe *tracefs_debug_dir()* is similar to *tracefs_tracing_dir()* except 52*287e80b3SSadaf Ebrahimithat it will return where the debugfs file system is mounted. If it 53*287e80b3SSadaf Ebrahimiis not mounted it will try to mount it. The return string must _not_ 54*287e80b3SSadaf Ebrahimibe freed. 55*287e80b3SSadaf Ebrahimi 56*287e80b3SSadaf Ebrahimi*tracefs_tracing_dir_is_mounted()* returns 1 if the tracing directory is 57*287e80b3SSadaf Ebrahimialready mounted and 0 if it is not. If _mount_ is true, it will try to 58*287e80b3SSadaf Ebrahimimount it if it is not, and returns 0 if it succesfully mounted it and -1 59*287e80b3SSadaf Ebrahimiif it did not. If _path_ is set, it will be assigned to the path where it 60*287e80b3SSadaf Ebrahimimounted it. _path_ is internal and should not be freed. 61*287e80b3SSadaf Ebrahimi 62*287e80b3SSadaf EbrahimiRETURN VALUE 63*287e80b3SSadaf Ebrahimi------------ 64*287e80b3SSadaf EbrahimiThe *tracefs_set_tracing_dir()* function returns 0 on success, -1 otherwise. 65*287e80b3SSadaf Ebrahimi 66*287e80b3SSadaf EbrahimiThe *tracefs_get_tracing_file()* function returns a string or NULL in case 67*287e80b3SSadaf Ebrahimiof an error. The returned string must be freed with *tracefs_put_tracing_file()*. 68*287e80b3SSadaf Ebrahimi 69*287e80b3SSadaf EbrahimiThe *tracefs_tracing_dir()* function returns a constant string or NULL 70*287e80b3SSadaf Ebrahimiin case of an error. The returned string must _not_ be freed. 71*287e80b3SSadaf Ebrahimi 72*287e80b3SSadaf EbrahimiThe *tracefs_debug_dir()* function returns a constant string or NULL 73*287e80b3SSadaf Ebrahimiin case of an error. The returned string must _not_ be freed. 74*287e80b3SSadaf Ebrahimi 75*287e80b3SSadaf EbrahimiThe *tracefs_tracing_dir_is_mounted()* returns 1 if the tracing directory 76*287e80b3SSadaf Ebrahimiis already mounted, 0 if it is not, and -1 on error. 77*287e80b3SSadaf Ebrahimi 78*287e80b3SSadaf EbrahimiEXAMPLE 79*287e80b3SSadaf Ebrahimi------- 80*287e80b3SSadaf Ebrahimi[source,c] 81*287e80b3SSadaf Ebrahimi-- 82*287e80b3SSadaf Ebrahimi#include <tracefs.h> 83*287e80b3SSadaf Ebrahimi... 84*287e80b3SSadaf Ebrahimichar *trace_on = tracefs_get_tracing_file("tracing_on"); 85*287e80b3SSadaf Ebrahimi if (trace_on) { 86*287e80b3SSadaf Ebrahimi ... 87*287e80b3SSadaf Ebrahimi tracefs_put_tracing_file(trace_on); 88*287e80b3SSadaf Ebrahimi } 89*287e80b3SSadaf Ebrahimi... 90*287e80b3SSadaf Ebrahimiconst char *trace_dir = tracefs_tracing_dir(); 91*287e80b3SSadaf Ebrahimi 92*287e80b3SSadaf Ebrahimi-- 93*287e80b3SSadaf EbrahimiFILES 94*287e80b3SSadaf Ebrahimi----- 95*287e80b3SSadaf Ebrahimi[verse] 96*287e80b3SSadaf Ebrahimi-- 97*287e80b3SSadaf Ebrahimi*tracefs.h* 98*287e80b3SSadaf Ebrahimi Header file to include in order to have access to the library APIs. 99*287e80b3SSadaf Ebrahimi*-ltracefs* 100*287e80b3SSadaf Ebrahimi Linker switch to add when building a program that uses the library. 101*287e80b3SSadaf Ebrahimi-- 102*287e80b3SSadaf Ebrahimi 103*287e80b3SSadaf EbrahimiSEE ALSO 104*287e80b3SSadaf Ebrahimi-------- 105*287e80b3SSadaf Ebrahimi*libtracefs*(3), 106*287e80b3SSadaf Ebrahimi*libtraceevent*(3), 107*287e80b3SSadaf Ebrahimi*trace-cmd*(1) 108*287e80b3SSadaf Ebrahimi 109*287e80b3SSadaf EbrahimiAUTHOR 110*287e80b3SSadaf Ebrahimi------ 111*287e80b3SSadaf Ebrahimi[verse] 112*287e80b3SSadaf Ebrahimi-- 113*287e80b3SSadaf Ebrahimi*Steven Rostedt* <[email protected]> 114*287e80b3SSadaf Ebrahimi*Tzvetomir Stoyanov* <[email protected]> 115*287e80b3SSadaf Ebrahimi-- 116*287e80b3SSadaf EbrahimiREPORTING BUGS 117*287e80b3SSadaf Ebrahimi-------------- 118*287e80b3SSadaf EbrahimiReport bugs to <[email protected]> 119*287e80b3SSadaf Ebrahimi 120*287e80b3SSadaf EbrahimiLICENSE 121*287e80b3SSadaf Ebrahimi------- 122*287e80b3SSadaf Ebrahimilibtracefs is Free Software licensed under the GNU LGPL 2.1 123*287e80b3SSadaf Ebrahimi 124*287e80b3SSadaf EbrahimiRESOURCES 125*287e80b3SSadaf Ebrahimi--------- 126*287e80b3SSadaf Ebrahimihttps://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ 127*287e80b3SSadaf Ebrahimi 128*287e80b3SSadaf EbrahimiCOPYING 129*287e80b3SSadaf Ebrahimi------- 130*287e80b3SSadaf EbrahimiCopyright \(C) 2020 VMware, Inc. Free use of this software is granted under 131*287e80b3SSadaf Ebrahimithe terms of the GNU Public License (GPL). 132