1*287e80b3SSadaf Ebrahimilibtracefs(3) 2*287e80b3SSadaf Ebrahimi============= 3*287e80b3SSadaf Ebrahimi 4*287e80b3SSadaf EbrahimiNAME 5*287e80b3SSadaf Ebrahimi---- 6*287e80b3SSadaf Ebrahimitracefs_event_systems, tracefs_system_events, tracefs_event_enable, tracefs_event_disable, 7*287e80b3SSadaf Ebrahimitracefs_event_is_enabled - Work with trace systems and events. 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 Ebrahimienum tracefs_event_state { 16*287e80b3SSadaf Ebrahimi TRACEFS_ERROR = -1, 17*287e80b3SSadaf Ebrahimi TRACEFS_ALL_DISABLED = 0, 18*287e80b3SSadaf Ebrahimi TRACEFS_ALL_ENABLED = 1, 19*287e80b3SSadaf Ebrahimi TRACEFS_SOME_ENABLED = 2, 20*287e80b3SSadaf Ebrahimi}; 21*287e80b3SSadaf Ebrahimi 22*287e80b3SSadaf Ebrahimichar pass:[*]pass:[*]*tracefs_event_systems*(const char pass:[*]_tracing_dir_); 23*287e80b3SSadaf Ebrahimichar pass:[*]pass:[*]*tracefs_system_events*(const char pass:[*]_tracing_dir_, const char pass:[*]_system_); 24*287e80b3SSadaf Ebrahimiint *tracefs_event_enable*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_system_, 25*287e80b3SSadaf Ebrahimi const char pass:[*]_event_); 26*287e80b3SSadaf Ebrahimiint *tracefs_event_disable*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_system_, 27*287e80b3SSadaf Ebrahimi const char pass:[*]_event_); 28*287e80b3SSadaf Ebrahimienum tracefs_enable_state *tracefs_event_is_enabled*(struct tracefs_instance pass:[*]_instance_, 29*287e80b3SSadaf Ebrahimi const char pass:[*]_system_, const char pass:[*]_event_); 30*287e80b3SSadaf Ebrahimi-- 31*287e80b3SSadaf Ebrahimi 32*287e80b3SSadaf EbrahimiDESCRIPTION 33*287e80b3SSadaf Ebrahimi----------- 34*287e80b3SSadaf EbrahimiTrace systems and events related APIs. 35*287e80b3SSadaf Ebrahimi 36*287e80b3SSadaf EbrahimiThe *tracefs_event_systems()* function returns array of strings with the 37*287e80b3SSadaf Ebrahiminames of all registered trace systems, located in the given _tracing_dir_ 38*287e80b3SSadaf Ebrahimidirectory. This could be NULL or the location of the tracefs mount point 39*287e80b3SSadaf Ebrahimifor the trace systems of the local machine, or it may be a path to a copy 40*287e80b3SSadaf Ebrahimiof the tracefs directory from another machine. The last entry in the array 41*287e80b3SSadaf Ebrahimiis a NULL pointer. The array must be freed with *tracefs_list_free()* API. 42*287e80b3SSadaf Ebrahimi 43*287e80b3SSadaf EbrahimiThe *tracefs_system_events()* function returns array of strings with the 44*287e80b3SSadaf Ebrahiminames of all registered trace events for given trace system specified by 45*287e80b3SSadaf Ebrahimi_system_, located in the given _tracing_dir_ directory. This could be NULL 46*287e80b3SSadaf Ebrahimior the location of the tracefs mount point for the trace systems of the 47*287e80b3SSadaf Ebrahimilocal machine, or it may be a path to a copy of the tracefs directory 48*287e80b3SSadaf Ebrahimifrom another machine. The last entry in the array as a NULL pointer. 49*287e80b3SSadaf EbrahimiThe array must be freed with *tracefs_list_free()* API. 50*287e80b3SSadaf Ebrahimi 51*287e80b3SSadaf EbrahimiThe *tracefs_event_enable()* function enables a given event based on 52*287e80b3SSadaf Ebrahimithe _system_ and _event_ passed in for the given _instance_. If _instance_ 53*287e80b3SSadaf Ebrahimiis NULL, then the top level tracing directory is used. If _system_ 54*287e80b3SSadaf Ebrahimiand _event_ are both NULL, then all events are enabled for the _instance_. 55*287e80b3SSadaf EbrahimiIf _event_ is NULL then all events within the _system_ are enabled. 56*287e80b3SSadaf EbrahimiIf _system_ is NULL, then all systems are searched and any event within 57*287e80b3SSadaf Ebrahimia system that matches _event_ is enabled. Both _system_ and _event_ may 58*287e80b3SSadaf Ebrahimibe regular expressions as defined by *regex*(3). 59*287e80b3SSadaf Ebrahimi 60*287e80b3SSadaf EbrahimiThe *tracefs_event_disable()* function disables the events that match 61*287e80b3SSadaf Ebrahimithe _system_ and _event_ parameters for the given _instance_. What events 62*287e80b3SSadaf Ebrahimiare disable follow the same rules as *tracefs_event_enable()* for matching 63*287e80b3SSadaf Ebrahimievents. That is, if _instance_ is NULL, then the top level tracing directory 64*287e80b3SSadaf Ebrahimiis used. If both _system_ and _event_ are NULL then all events are disabled 65*287e80b3SSadaf Ebrahimifor the given _instance_, and so on. 66*287e80b3SSadaf Ebrahimi 67*287e80b3SSadaf EbrahimiThe *tracefs_event_is_enabled()* returns if an event is enabled, a set of 68*287e80b3SSadaf Ebrahimievents are enabled, a system is enabled, or all events are enabled. If both 69*287e80b3SSadaf Ebrahimi_system_ and _event_ are NULL, then it returns the enable state of all events. 70*287e80b3SSadaf EbrahimiIf _system_ is not NULL and _event_ is NULL, then it will check if all the events 71*287e80b3SSadaf Ebrahimiin all the systems that _system_ and return the enable state of those events. 72*287e80b3SSadaf EbrahimiIf _system_ is NULL and _event_ is not NULL, then it will match all the events 73*287e80b3SSadaf Ebrahimiin all systems that match _event_ and return their enabled state. If both _system_ 74*287e80b3SSadaf Ebrahimiand _event_ are not NULL, then it will return the enabled state of all matching 75*287e80b3SSadaf Ebrahimievents. The enabled state is defined as: 76*287e80b3SSadaf Ebrahimi 77*287e80b3SSadaf Ebrahimi*TRACEFS_ERROR* - An error occurred including no event were matched. 78*287e80b3SSadaf Ebrahimi 79*287e80b3SSadaf Ebrahimi*TRACEFS_ALL_DISABLED* - All matching events are disabled. 80*287e80b3SSadaf Ebrahimi 81*287e80b3SSadaf Ebrahimi*TRACEFS_ALL_ENABLED* - All matching events are enabled. 82*287e80b3SSadaf Ebrahimi 83*287e80b3SSadaf Ebrahimi*TRACEFS_SOME_ENABLED* - Some matching events were enabled while others were not. 84*287e80b3SSadaf Ebrahimi 85*287e80b3SSadaf EbrahimiRETURN VALUE 86*287e80b3SSadaf Ebrahimi------------ 87*287e80b3SSadaf EbrahimiThe *tracefs_event_systems()* and *tracefs_system_events()* functions return 88*287e80b3SSadaf Ebrahimian array of strings. The last element in that array is a NULL pointer. The array 89*287e80b3SSadaf Ebrahimimust be freed with *tracefs_list_free()* API. In case of an error, NULL is returned. 90*287e80b3SSadaf Ebrahimi 91*287e80b3SSadaf EbrahimiBoth *tracefs_event_enable()* and *tracefs_event_disable()* return 0 if they found 92*287e80b3SSadaf Ebrahimiany matching events (Note it does not check the previous status of the event. If 93*287e80b3SSadaf Ebrahimi*tracefs_event_enable()* finds an event that is already enabled, and there are no 94*287e80b3SSadaf Ebrahimiother errors, then it will return 0). If an error occurs, even if other events were 95*287e80b3SSadaf Ebrahimifound, it will return -1 and errno will be set. If no errors occur, but no events 96*287e80b3SSadaf Ebrahimiare found that match the _system_ and _event_ parameters, then -1 is returned 97*287e80b3SSadaf Ebrahimiand errno is not set. 98*287e80b3SSadaf Ebrahimi 99*287e80b3SSadaf EbrahimiThe *tracefs_event_is_enabled()* returns the enabled status of the matching events 100*287e80b3SSadaf Ebrahimior TRACEFS_ERROR on error. 101*287e80b3SSadaf Ebrahimi 102*287e80b3SSadaf EbrahimiEXAMPLE 103*287e80b3SSadaf Ebrahimi------- 104*287e80b3SSadaf Ebrahimi[source,c] 105*287e80b3SSadaf Ebrahimi-- 106*287e80b3SSadaf Ebrahimi#include <tracefs.h> 107*287e80b3SSadaf Ebrahimi 108*287e80b3SSadaf Ebrahimichar **systems = tracefs_event_systems(NULL); 109*287e80b3SSadaf Ebrahimi 110*287e80b3SSadaf Ebrahimi if (systems) { 111*287e80b3SSadaf Ebrahimi int i = 0; 112*287e80b3SSadaf Ebrahimi /* Got registered trace systems from the top trace instance */ 113*287e80b3SSadaf Ebrahimi while (systems[i]) { 114*287e80b3SSadaf Ebrahimi char **events = tracefs_system_events(NULL, systems[i]); 115*287e80b3SSadaf Ebrahimi if (events) { 116*287e80b3SSadaf Ebrahimi /* Got registered events in system[i] from the top trace instance */ 117*287e80b3SSadaf Ebrahimi int j = 0; 118*287e80b3SSadaf Ebrahimi 119*287e80b3SSadaf Ebrahimi while (events[j]) { 120*287e80b3SSadaf Ebrahimi /* Got event[j] in system[i] from the top trace instance */ 121*287e80b3SSadaf Ebrahimi j++; 122*287e80b3SSadaf Ebrahimi } 123*287e80b3SSadaf Ebrahimi tracefs_list_free(events); 124*287e80b3SSadaf Ebrahimi } 125*287e80b3SSadaf Ebrahimi i++; 126*287e80b3SSadaf Ebrahimi } 127*287e80b3SSadaf Ebrahimi tracefs_list_free(systems); 128*287e80b3SSadaf Ebrahimi } 129*287e80b3SSadaf Ebrahimi.... 130*287e80b3SSadaf Ebrahimistatic int records_walk(struct tep_event *tep, struct tep_record *record, int cpu, void *context) 131*287e80b3SSadaf Ebrahimi{ 132*287e80b3SSadaf Ebrahimi /* Got recorded event on cpu */ 133*287e80b3SSadaf Ebrahimi return 0; 134*287e80b3SSadaf Ebrahimi} 135*287e80b3SSadaf Ebrahimi... 136*287e80b3SSadaf Ebrahimistruct tep_handle *tep = tracefs_local_events(NULL); 137*287e80b3SSadaf Ebrahimi 138*287e80b3SSadaf Ebrahimi if (!tep) { 139*287e80b3SSadaf Ebrahimi /* Failed to initialise tep handler with local events */ 140*287e80b3SSadaf Ebrahimi ... 141*287e80b3SSadaf Ebrahimi } 142*287e80b3SSadaf Ebrahimi 143*287e80b3SSadaf Ebrahimi errno = 0; 144*287e80b3SSadaf Ebrahimi ret = tracefs_event_enable(NULL, "sched", NULL); 145*287e80b3SSadaf Ebrahimi if (ret < 0 && !errno) 146*287e80b3SSadaf Ebrahimi printf("Could not find 'sched' events\n"); 147*287e80b3SSadaf Ebrahimi tracefs_event_enable(NULL, "irq", "irq_handler_\(enter\|exit\)"); 148*287e80b3SSadaf Ebrahimi 149*287e80b3SSadaf Ebrahimi if (tracefs_iterate_raw_events(tep, NULL, NULL, 0, records_walk, NULL) < 0) { 150*287e80b3SSadaf Ebrahimi /* Error walking through the recorded raw events */ 151*287e80b3SSadaf Ebrahimi } 152*287e80b3SSadaf Ebrahimi 153*287e80b3SSadaf Ebrahimi /* Disable all events */ 154*287e80b3SSadaf Ebrahimi tracefs_event_disable(NULL, NULL, NULL); 155*287e80b3SSadaf Ebrahimi tep_free(tep); 156*287e80b3SSadaf Ebrahimi-- 157*287e80b3SSadaf EbrahimiFILES 158*287e80b3SSadaf Ebrahimi----- 159*287e80b3SSadaf Ebrahimi[verse] 160*287e80b3SSadaf Ebrahimi-- 161*287e80b3SSadaf Ebrahimi*tracefs.h* 162*287e80b3SSadaf Ebrahimi Header file to include in order to have access to the library APIs. 163*287e80b3SSadaf Ebrahimi*-ltracefs* 164*287e80b3SSadaf Ebrahimi Linker switch to add when building a program that uses the library. 165*287e80b3SSadaf Ebrahimi-- 166*287e80b3SSadaf Ebrahimi 167*287e80b3SSadaf EbrahimiSEE ALSO 168*287e80b3SSadaf Ebrahimi-------- 169*287e80b3SSadaf Ebrahimi*libtracefs*(3), 170*287e80b3SSadaf Ebrahimi*libtraceevent*(3), 171*287e80b3SSadaf Ebrahimi*trace-cmd*(1) 172*287e80b3SSadaf Ebrahimi 173*287e80b3SSadaf EbrahimiAUTHOR 174*287e80b3SSadaf Ebrahimi------ 175*287e80b3SSadaf Ebrahimi[verse] 176*287e80b3SSadaf Ebrahimi-- 177*287e80b3SSadaf Ebrahimi*Steven Rostedt* <[email protected]> 178*287e80b3SSadaf Ebrahimi*Tzvetomir Stoyanov* <[email protected]> 179*287e80b3SSadaf Ebrahimi-- 180*287e80b3SSadaf EbrahimiREPORTING BUGS 181*287e80b3SSadaf Ebrahimi-------------- 182*287e80b3SSadaf EbrahimiReport bugs to <[email protected]> 183*287e80b3SSadaf Ebrahimi 184*287e80b3SSadaf EbrahimiLICENSE 185*287e80b3SSadaf Ebrahimi------- 186*287e80b3SSadaf Ebrahimilibtracefs is Free Software licensed under the GNU LGPL 2.1 187*287e80b3SSadaf Ebrahimi 188*287e80b3SSadaf EbrahimiRESOURCES 189*287e80b3SSadaf Ebrahimi--------- 190*287e80b3SSadaf Ebrahimihttps://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ 191*287e80b3SSadaf Ebrahimi 192*287e80b3SSadaf EbrahimiCOPYING 193*287e80b3SSadaf Ebrahimi------- 194*287e80b3SSadaf EbrahimiCopyright \(C) 2020 VMware, Inc. Free use of this software is granted under 195*287e80b3SSadaf Ebrahimithe terms of the GNU Public License (GPL). 196