1libtracefs(3) 2============= 3 4NAME 5---- 6tracefs_file_exists, tracefs_dir_exists, 7tracefs_instance_get_file, tracefs_instance_get_dir - Work with files directories in tracing instances. 8 9SYNOPSIS 10-------- 11[verse] 12-- 13*#include <tracefs.h>* 14 15bool *tracefs_file_exists*(struct tracefs_instance pass:[*]_instance_, char pass:[*]_name_); 16bool *tracefs_dir_exists*(struct tracefs_instance pass:[*]_instance_, char pass:[*]_name_); 17char pass:[*]*tracefs_instance_get_file*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_); 18char pass:[*]*tracefs_instance_get_dir*(struct tracefs_instance pass:[*]_instance_); 19 20-- 21 22DESCRIPTION 23----------- 24This set of APIs can be used to work with trace files in all trace instances. 25Each of these APIs take an _instance_ argument, that can be NULL to act 26on the top level instance. Otherwise, it acts on an instance created with 27*tracefs_insance_create*(3) 28 29The *tracefs_file_exists()* function checks if a file with _name_ exists in _instance_. 30 31The *tracefs_dir_exists()* function checks if a directory with _name_ exists in _instance_. 32 33The *tracefs_instance_get_file()* function returns the full path of the file 34with given _name_ in _instance_. Note, it does not check if the file exists in 35the instance. 36 37The *tracefs_instance_get_dir()* function returns the full path of the directory 38with given _name_ in _instance_. Note, it does not check if the directory exists 39in the instance. 40 41RETURN VALUE 42------------ 43The *tracefs_file_exists()* and *tracefs_dir_exists()* functions return true if the 44file / directory exist in the given instance or false if it does not exist. 45 46The *tracefs_instance_get_file()* and *tracefs_instance_get_dir()* functions return 47a string or NULL in case of an error. The returned string must be freed with 48*tracefs_put_tracing_file()*. 49 50EXAMPLE 51------- 52[source,c] 53-- 54#include <tracefs.h> 55 56struct tracefs_instance *inst = tracefs_instance_create("foo"); 57 if (!inst) { 58 /* Error creating a new trace instance */ 59 ... 60 } 61 62 if (tracefs_file_exists(inst,"trace_clock")) { 63 /* The instance foo supports trace clock */ 64 char *path, *clock; 65 int size; 66 67 path = = tracefs_instance_get_file(inst, "trace_clock") 68 if (!path) { 69 /* Error getting the path to trace_clock file in instance foo */ 70 ... 71 } 72 ... 73 tracefs_put_tracing_file(path); 74 75 clock = tracefs_instance_file_read(inst, "trace_clock", &size); 76 if (!clock) { 77 /* Failed to read trace_clock file in instance foo */ 78 ... 79 } 80 ... 81 free(clock); 82 83 if (tracefs_instance_file_write(inst, "trace_clock", "global") != strlen("global")) { 84 /* Failed to set gloabl trace clock in instance foo */ 85 ... 86 } 87 } else { 88 /* The instance foo does not support trace clock */ 89 } 90 91 if (tracefs_dir_exists(inst,"options")) { 92 /* The instance foo supports trace options */ 93 char *path = tracefs_instance_get_file(inst, "options"); 94 if (!path) { 95 /* Error getting the path to options directory in instance foo */ 96 ... 97 } 98 99 tracefs_put_tracing_file(path); 100 } else { 101 /* The instance foo does not support trace options */ 102 } 103 104 ... 105 106 if (tracefs_instance_is_new(inst)) 107 tracefs_instance_destroy(inst); 108 else 109 tracefs_instance_free(inst); 110 ... 111 112 long long int res; 113 if (tracefs_instance_file_read_number(NULL, "tracing_on", &res) == 0) { 114 if (res == 0) { 115 /* tracing is disabled in the top instance */ 116 } else if (res == 1) { 117 /* tracing is enabled in the top instance */ 118 } else { 119 /* Unknown tracing state of the top instance */ 120 } 121 } else { 122 /* Failed to read integer from tracing_on file */ 123 } 124 125 ... 126 127 int fd; 128 fd = tracefs_instance_file_open(NULL, "tracing_on", O_WRONLY); 129 if (fd >= 0) { 130 /* Got file descriptor to the tracing_on file from the top instance for writing */ 131 ... 132 close(fd); 133 } 134-- 135FILES 136----- 137[verse] 138-- 139*tracefs.h* 140 Header file to include in order to have access to the library APIs. 141*-ltracefs* 142 Linker switch to add when building a program that uses the library. 143-- 144 145SEE ALSO 146-------- 147*libtracefs*(3), 148*libtraceevent*(3), 149*trace-cmd*(1) 150 151AUTHOR 152------ 153[verse] 154-- 155*Steven Rostedt* <[email protected]> 156*Tzvetomir Stoyanov* <[email protected]> 157-- 158REPORTING BUGS 159-------------- 160Report bugs to <[email protected]> 161 162LICENSE 163------- 164libtracefs is Free Software licensed under the GNU LGPL 2.1 165 166RESOURCES 167--------- 168https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ 169 170COPYING 171------- 172Copyright \(C) 2020 VMware, Inc. Free use of this software is granted under 173the terms of the GNU Public License (GPL). 174