1*287e80b3SSadaf Ebrahimilibtracefs(3) 2*287e80b3SSadaf Ebrahimi============= 3*287e80b3SSadaf Ebrahimi 4*287e80b3SSadaf EbrahimiNAME 5*287e80b3SSadaf Ebrahimi---- 6*287e80b3SSadaf Ebrahimitracefs_tracer_set, tracefs_tracer_clear - Enable or disable a tracer in an instance or the top level 7*287e80b3SSadaf Ebrahimi 8*287e80b3SSadaf EbrahimiSYNOPSIS 9*287e80b3SSadaf Ebrahimi-------- 10*287e80b3SSadaf Ebrahimi[verse] 11*287e80b3SSadaf Ebrahimi-- 12*287e80b3SSadaf Ebrahimi*#include <tracefs.h>* 13*287e80b3SSadaf Ebrahimi 14*287e80b3SSadaf Ebrahimiint *tracefs_tracer_set*(struct tracefs_instance pass:[*]_instance_, enum tracefs_tracers _tracer_); 15*287e80b3SSadaf Ebrahimiint *tracefs_tracer_set*(struct tracefs_instance pass:[*]_instance_, enum tracefs_tracers _tracer_, const char pass:[*]_name_); 16*287e80b3SSadaf Ebrahimiint *tracefs_tracer_clear*(struct tracefs_instance pass:[*]_instance_); 17*287e80b3SSadaf Ebrahimi-- 18*287e80b3SSadaf Ebrahimi 19*287e80b3SSadaf EbrahimiDESCRIPTION 20*287e80b3SSadaf Ebrahimi----------- 21*287e80b3SSadaf Ebrahimi*tracefs_tracer_set* enables a tracer in the given instance, defined by the 22*287e80b3SSadaf Ebrahimi_instance_ parameter. If _instance_ is NULL, then the top level instance is 23*287e80b3SSadaf Ebrahimichanged. If _tracer_ is set to *TRACFES_TRACER_CUSTOM* then a _name_ 24*287e80b3SSadaf Ebrahimistring must be passed in as the third parameter, and that is written into the 25*287e80b3SSadaf Ebrahimiinstance to enable the tracer with that name. This is useful for newer or 26*287e80b3SSadaf Ebrahimicustom kernels that contain tracers that are not yet identified by the 27*287e80b3SSadaf Ebrahimitracefs_tracers enum. 28*287e80b3SSadaf Ebrahimi 29*287e80b3SSadaf Ebrahimi*tracefs_tracer_clear* disables the tracer for the given instance defined by 30*287e80b3SSadaf Ebrahimithe _instance_ variable, or the top level instance if it is NULL. 31*287e80b3SSadaf EbrahimiThis is the same as calling *tracefs_tracer_set* with TRACEFS_TRACER_NOP as 32*287e80b3SSadaf Ebrahimithe _tracer_ parameter. 33*287e80b3SSadaf Ebrahimi 34*287e80b3SSadaf EbrahimiTRACEFS_TRACER ENUMS 35*287e80b3SSadaf Ebrahimi-------------------- 36*287e80b3SSadaf Ebrahimi 37*287e80b3SSadaf EbrahimiThe currently defined enums that are accepted are: 38*287e80b3SSadaf Ebrahimi 39*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_NOP* : 40*287e80b3SSadaf EbrahimiThis is the idle tracer, which does nothing and is used to clear any 41*287e80b3SSadaf Ebrahimiactive tracer. 42*287e80b3SSadaf Ebrahimi 43*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_FUNCTION* : 44*287e80b3SSadaf EbrahimiEnables most functions in the kernel to be traced. 45*287e80b3SSadaf Ebrahimi 46*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_FUNCTION_GRAPH* : 47*287e80b3SSadaf EbrahimiEnables most functions in the kernel to be traced as well as the return 48*287e80b3SSadaf Ebrahimiof the function. 49*287e80b3SSadaf Ebrahimi 50*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_IRQSOFF* : 51*287e80b3SSadaf EbrahimiTracers the latency of interrupts disabled. 52*287e80b3SSadaf Ebrahimi 53*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_PREEMPTOFF* : 54*287e80b3SSadaf EbrahimiTracers the latency of preemption disabled (the time in the kernel that 55*287e80b3SSadaf Ebrahimitasks can not be scheduled from the CPU). 56*287e80b3SSadaf Ebrahimi 57*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_PREEMPTIRQSOFF* : 58*287e80b3SSadaf EbrahimiTraces the combined total latency of when interrupts are disabled as well as when 59*287e80b3SSadaf Ebrahimipreemption is disabled. 60*287e80b3SSadaf Ebrahimi 61*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_WAKEUP* : 62*287e80b3SSadaf EbrahimiTraces the latency of when the highest priority task takes to wake up. 63*287e80b3SSadaf Ebrahimi 64*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_WAKEUP_RT* : 65*287e80b3SSadaf EbrahimiTraces the latency of when the highest priority real-time task takes to wake up. 66*287e80b3SSadaf EbrahimiAll other tasks are ignored. 67*287e80b3SSadaf Ebrahimi 68*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_WAKEUP_DL* : 69*287e80b3SSadaf EbrahimiTraces the latency of when the highest priority DEADLINE task takes to wake up. 70*287e80b3SSadaf EbrahimiAll other tasks are ignored. 71*287e80b3SSadaf Ebrahimi 72*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_MMIOTRACE* : 73*287e80b3SSadaf EbrahimiTraces the interaction of devices with the kernel. 74*287e80b3SSadaf Ebrahimi 75*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_HWLAT* : 76*287e80b3SSadaf EbrahimiDetects latency caused by the hardware that is outside the scope of the kernel. 77*287e80b3SSadaf Ebrahimi 78*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_BRANCH* : 79*287e80b3SSadaf EbrahimiTraces when likely or unlikely branches are taken. 80*287e80b3SSadaf Ebrahimi 81*287e80b3SSadaf Ebrahimi*TRACEFS_TRACER_BLOCK* : 82*287e80b3SSadaf EbrahimiSpecial tracer for the block devices. 83*287e80b3SSadaf Ebrahimi 84*287e80b3SSadaf EbrahimiNote that the above tracers may not be available in the kernel and 85*287e80b3SSadaf Ebrahimi*tracefs_tracer_set()* will return an error with errno set to ENODEV, 86*287e80b3SSadaf Ebrahimiif the kernel does not support the _tracer_ option, or the custom one 87*287e80b3SSadaf Ebrahimiif TRACEFS_TRACER_CUSTOM is used. 88*287e80b3SSadaf Ebrahimi 89*287e80b3SSadaf EbrahimiRETURN VALUE 90*287e80b3SSadaf Ebrahimi------------ 91*287e80b3SSadaf EbrahimiReturns 0 on success, or -1 on error. 92*287e80b3SSadaf Ebrahimi 93*287e80b3SSadaf EbrahimiERRORS 94*287e80b3SSadaf Ebrahimi------ 95*287e80b3SSadaf Ebrahimi 96*287e80b3SSadaf Ebrahimi*tracefs_tracer_set*() can fail with the following errors: 97*287e80b3SSadaf Ebrahimi 98*287e80b3SSadaf Ebrahimi*EINVAL* The _tracer_ parameter is outside the scope of what is defined. 99*287e80b3SSadaf Ebrahimi 100*287e80b3SSadaf Ebrahimi*ENOMEM* Memory allocation error. 101*287e80b3SSadaf Ebrahimi 102*287e80b3SSadaf Ebrahimi*ENOENT* Tracers are not supported on the running kernel. 103*287e80b3SSadaf Ebrahimi 104*287e80b3SSadaf Ebrahimi*ENODEV* The specified tracer is not supported on the running kernel. 105*287e80b3SSadaf Ebrahimi 106*287e80b3SSadaf EbrahimiOther errors may also happen caused by internal system calls. 107*287e80b3SSadaf Ebrahimi 108*287e80b3SSadaf EbrahimiEXAMPLE 109*287e80b3SSadaf Ebrahimi------- 110*287e80b3SSadaf Ebrahimi[source,c] 111*287e80b3SSadaf Ebrahimi-- 112*287e80b3SSadaf Ebrahimi#include <stdlib.h> 113*287e80b3SSadaf Ebrahimi#include <stdio.h> 114*287e80b3SSadaf Ebrahimi#include <getopt.h> 115*287e80b3SSadaf Ebrahimi#include <errno.h> 116*287e80b3SSadaf Ebrahimi#include <tracefs.h> 117*287e80b3SSadaf Ebrahimi 118*287e80b3SSadaf Ebrahimiint main(int argc, char *argv[]) 119*287e80b3SSadaf Ebrahimi{ 120*287e80b3SSadaf Ebrahimi struct tracefs_instance *inst = NULL; 121*287e80b3SSadaf Ebrahimi enum tracefs_tracers t = TRACEFS_TRACER_NOP; 122*287e80b3SSadaf Ebrahimi const char *buf = NULL; 123*287e80b3SSadaf Ebrahimi const char *cust; 124*287e80b3SSadaf Ebrahimi int ret; 125*287e80b3SSadaf Ebrahimi int ch; 126*287e80b3SSadaf Ebrahimi 127*287e80b3SSadaf Ebrahimi while ((ch = getopt(argc, argv, "nfgiwdc:B:")) > 0) { 128*287e80b3SSadaf Ebrahimi switch (ch) { 129*287e80b3SSadaf Ebrahimi case 'f': t = TRACEFS_TRACER_FUNCTION; break; 130*287e80b3SSadaf Ebrahimi case 'g': t = TRACEFS_TRACER_FUNCTION_GRAPH; break; 131*287e80b3SSadaf Ebrahimi case 'i': t = TRACEFS_TRACER_PREEMPTIRQSOFF; break; 132*287e80b3SSadaf Ebrahimi case 'w': t = TRACEFS_TRACER_WAKEUP_RT; break; 133*287e80b3SSadaf Ebrahimi case 'd': t = TRACEFS_TRACER_WAKEUP_DL; break; 134*287e80b3SSadaf Ebrahimi case 'c': 135*287e80b3SSadaf Ebrahimi t = TRACEFS_TRACER_CUSTOM; 136*287e80b3SSadaf Ebrahimi cust = optarg; 137*287e80b3SSadaf Ebrahimi break; 138*287e80b3SSadaf Ebrahimi case 'B': 139*287e80b3SSadaf Ebrahimi buf = optarg; 140*287e80b3SSadaf Ebrahimi break; 141*287e80b3SSadaf Ebrahimi case 'n': 142*287e80b3SSadaf Ebrahimi /* nop */ 143*287e80b3SSadaf Ebrahimi break; 144*287e80b3SSadaf Ebrahimi default: 145*287e80b3SSadaf Ebrahimi printf("Unknow arg %c\n", ch); 146*287e80b3SSadaf Ebrahimi exit(-1); 147*287e80b3SSadaf Ebrahimi } 148*287e80b3SSadaf Ebrahimi } 149*287e80b3SSadaf Ebrahimi 150*287e80b3SSadaf Ebrahimi if (buf) { 151*287e80b3SSadaf Ebrahimi inst = tracefs_instance_create(buf); 152*287e80b3SSadaf Ebrahimi if (!inst) { 153*287e80b3SSadaf Ebrahimi printf("failed to create instance\n"); 154*287e80b3SSadaf Ebrahimi exit(-1); 155*287e80b3SSadaf Ebrahimi } 156*287e80b3SSadaf Ebrahimi } 157*287e80b3SSadaf Ebrahimi 158*287e80b3SSadaf Ebrahimi if (t == TRACEFS_TRACER_CUSTOM) 159*287e80b3SSadaf Ebrahimi ret = tracefs_tracer_set(inst, t, cust); 160*287e80b3SSadaf Ebrahimi else 161*287e80b3SSadaf Ebrahimi ret = tracefs_tracer_set(inst, t); 162*287e80b3SSadaf Ebrahimi 163*287e80b3SSadaf Ebrahimi if (ret < 0) { 164*287e80b3SSadaf Ebrahimi if (inst) { 165*287e80b3SSadaf Ebrahimi tracefs_instance_destroy(inst); 166*287e80b3SSadaf Ebrahimi tracefs_instance_free(inst); 167*287e80b3SSadaf Ebrahimi } 168*287e80b3SSadaf Ebrahimi if (errno == ENODEV) 169*287e80b3SSadaf Ebrahimi printf("Tracer not supported by kernel\n"); 170*287e80b3SSadaf Ebrahimi else 171*287e80b3SSadaf Ebrahimi perror("Error"); 172*287e80b3SSadaf Ebrahimi exit(-1); 173*287e80b3SSadaf Ebrahimi } 174*287e80b3SSadaf Ebrahimi 175*287e80b3SSadaf Ebrahimi if (inst) 176*287e80b3SSadaf Ebrahimi tracefs_instance_free(inst); 177*287e80b3SSadaf Ebrahimi 178*287e80b3SSadaf Ebrahimi exit(0); 179*287e80b3SSadaf Ebrahimi} 180*287e80b3SSadaf Ebrahimi-- 181*287e80b3SSadaf Ebrahimi 182*287e80b3SSadaf EbrahimiFILES 183*287e80b3SSadaf Ebrahimi----- 184*287e80b3SSadaf Ebrahimi[verse] 185*287e80b3SSadaf Ebrahimi-- 186*287e80b3SSadaf Ebrahimi*tracefs.h* 187*287e80b3SSadaf Ebrahimi Header file to include in order to have access to the library APIs. 188*287e80b3SSadaf Ebrahimi*-ltracefs* 189*287e80b3SSadaf Ebrahimi Linker switch to add when building a program that uses the library. 190*287e80b3SSadaf Ebrahimi-- 191*287e80b3SSadaf Ebrahimi 192*287e80b3SSadaf EbrahimiSEE ALSO 193*287e80b3SSadaf Ebrahimi-------- 194*287e80b3SSadaf Ebrahimi*libtracefs*(3), 195*287e80b3SSadaf Ebrahimi*libtraceevent*(3), 196*287e80b3SSadaf Ebrahimi*trace-cmd*(1) 197*287e80b3SSadaf Ebrahimi 198*287e80b3SSadaf EbrahimiAUTHOR 199*287e80b3SSadaf Ebrahimi------ 200*287e80b3SSadaf Ebrahimi[verse] 201*287e80b3SSadaf Ebrahimi-- 202*287e80b3SSadaf Ebrahimi*Steven Rostedt* <[email protected]> 203*287e80b3SSadaf Ebrahimi*Tzvetomir Stoyanov* <[email protected]> 204*287e80b3SSadaf Ebrahimi*sameeruddin shaik* <[email protected]> 205*287e80b3SSadaf Ebrahimi-- 206*287e80b3SSadaf EbrahimiREPORTING BUGS 207*287e80b3SSadaf Ebrahimi-------------- 208*287e80b3SSadaf EbrahimiReport bugs to <[email protected]> 209*287e80b3SSadaf Ebrahimi 210*287e80b3SSadaf EbrahimiLICENSE 211*287e80b3SSadaf Ebrahimi------- 212*287e80b3SSadaf Ebrahimilibtracefs is Free Software licensed under the GNU LGPL 2.1 213*287e80b3SSadaf Ebrahimi 214*287e80b3SSadaf EbrahimiRESOURCES 215*287e80b3SSadaf Ebrahimi--------- 216*287e80b3SSadaf Ebrahimihttps://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ 217*287e80b3SSadaf Ebrahimi 218*287e80b3SSadaf EbrahimiCOPYING 219*287e80b3SSadaf Ebrahimi------- 220*287e80b3SSadaf EbrahimiCopyright \(C) 2020 VMware, Inc. Free use of this software is granted under 221*287e80b3SSadaf Ebrahimithe terms of the GNU Public License (GPL). 222