Lines Matching full:instance

34 supported_opts_mask(struct tracefs_instance *instance)  in supported_opts_mask()  argument
36 return instance ? &instance->supported_opts : &toplevel_supported_opts; in supported_opts_mask()
40 enabled_opts_mask(struct tracefs_instance *instance) in enabled_opts_mask() argument
42 return instance ? &instance->enabled_opts : &toplevel_enabled_opts; in enabled_opts_mask()
46 * instance_alloc - allocate a new ftrace instance
47 * @trace_dir - Full path to the tracing directory, where the instance is
48 * @name: The name of the instance (instance will point to this)
50 * Returns a newly allocated instance, or NULL in case of an error.
54 struct tracefs_instance *instance; in instance_alloc() local
56 instance = calloc(1, sizeof(*instance)); in instance_alloc()
57 if (!instance) in instance_alloc()
59 instance->trace_dir = strdup(trace_dir); in instance_alloc()
60 if (!instance->trace_dir) in instance_alloc()
63 instance->name = strdup(name); in instance_alloc()
64 if (!instance->name) in instance_alloc()
68 if (pthread_mutex_init(&instance->lock, NULL) < 0) in instance_alloc()
71 instance->ftrace_filter_fd = -1; in instance_alloc()
72 instance->ftrace_notrace_fd = -1; in instance_alloc()
73 instance->ftrace_marker_fd = -1; in instance_alloc()
74 instance->ftrace_marker_raw_fd = -1; in instance_alloc()
76 return instance; in instance_alloc()
79 if (instance) { in instance_alloc()
80 free(instance->name); in instance_alloc()
81 free(instance->trace_dir); in instance_alloc()
82 free(instance); in instance_alloc()
88 __hidden int trace_get_instance(struct tracefs_instance *instance) in trace_get_instance() argument
92 pthread_mutex_lock(&instance->lock); in trace_get_instance()
93 if (instance->flags & FLAG_INSTANCE_DELETED) { in trace_get_instance()
96 instance->ref++; in trace_get_instance()
99 pthread_mutex_unlock(&instance->lock); in trace_get_instance()
103 __hidden void trace_put_instance(struct tracefs_instance *instance) in trace_put_instance() argument
105 pthread_mutex_lock(&instance->lock); in trace_put_instance()
106 if (--instance->ref < 0) in trace_put_instance()
107 instance->flags |= FLAG_INSTANCE_DELETED; in trace_put_instance()
108 pthread_mutex_unlock(&instance->lock); in trace_put_instance()
110 if (!(instance->flags & FLAG_INSTANCE_DELETED)) in trace_put_instance()
113 if (instance->ftrace_filter_fd >= 0) in trace_put_instance()
114 close(instance->ftrace_filter_fd); in trace_put_instance()
116 if (instance->ftrace_notrace_fd >= 0) in trace_put_instance()
117 close(instance->ftrace_notrace_fd); in trace_put_instance()
119 if (instance->ftrace_marker_fd >= 0) in trace_put_instance()
120 close(instance->ftrace_marker_fd); in trace_put_instance()
122 if (instance->ftrace_marker_raw_fd >= 0) in trace_put_instance()
123 close(instance->ftrace_marker_raw_fd); in trace_put_instance()
125 free(instance->trace_dir); in trace_put_instance()
126 free(instance->name); in trace_put_instance()
127 pthread_mutex_destroy(&instance->lock); in trace_put_instance()
128 free(instance); in trace_put_instance()
132 * tracefs_instance_free - Free an instance, previously allocated by
134 * @instance: Pointer to the instance to be freed
137 void tracefs_instance_free(struct tracefs_instance *instance) in tracefs_instance_free() argument
139 if (!instance) in tracefs_instance_free()
142 trace_put_instance(instance); in tracefs_instance_free()
165 * tracefs_instance_is_new - Check if the instance is newly created by the library
166 * @instance: Pointer to an ftrace instance
168 * Returns true, if the ftrace instance is newly created by the library or
171 bool tracefs_instance_is_new(struct tracefs_instance *instance) in tracefs_instance_is_new() argument
173 if (instance && (instance->flags & FLAG_INSTANCE_NEWLY_CREATED)) in tracefs_instance_is_new()
179 * tracefs_instance_create - Create a new ftrace instance
180 * @name: Name of the instance to be created
182 * Allocates and initializes a new instance structure. If the instance does not
184 * Returns a pointer to a newly allocated instance, or NULL in case of an error.
185 * The returned instance must be freed by tracefs_instance_free().
206 /* Cannot create the top instance, if it does not exist! */ in tracefs_instance_create()
223 * tracefs_instance_alloc - Allocate an instance structure for existing trace instance
224 * @tracing_dir: full path to the system trace directory, where the new instance is
226 * @name: Name of the instance.
228 * Allocates and initializes a new instance structure. If the instance does not
230 * Returns a pointer to a newly allocated instance, or NULL in case of an error
231 * or the requested instance does not exists.
232 * The returned instance must be freed by tracefs_instance_free().
266 * tracefs_instance_destroy - Remove a ftrace instance
267 * @instance: Pointer to the instance to be removed
271 int tracefs_instance_destroy(struct tracefs_instance *instance) in tracefs_instance_destroy() argument
276 if (!instance || !instance->name) { in tracefs_instance_destroy()
277 tracefs_warning("Cannot remove top instance"); in tracefs_instance_destroy()
281 path = tracefs_instance_get_dir(instance); in tracefs_instance_destroy()
286 pthread_mutex_lock(&instance->lock); in tracefs_instance_destroy()
287 instance->flags |= FLAG_INSTANCE_DELETED; in tracefs_instance_destroy()
288 pthread_mutex_unlock(&instance->lock); in tracefs_instance_destroy()
295 * tracefs_instance_get_file - return the path to an instance file.
296 * @instance: ftrace instance, can be NULL for the top instance
299 * Returns the path of the @file for the given @instance, or NULL in
305 tracefs_instance_get_file(struct tracefs_instance *instance, const char *file) in tracefs_instance_get_file() argument
310 if (!instance) in tracefs_instance_get_file()
312 if (!instance->name) in tracefs_instance_get_file()
313 ret = asprintf(&path, "%s/%s", instance->trace_dir, file); in tracefs_instance_get_file()
316 instance->trace_dir, instance->name, file); in tracefs_instance_get_file()
324 * tracefs_instance_get_dir - return the path to the instance directory.
325 * @instance: ftrace instance, can be NULL for the top instance
327 * Returns the full path to the instance directory
331 char *tracefs_instance_get_dir(struct tracefs_instance *instance) in tracefs_instance_get_dir() argument
336 if (!instance) /* Top instance of default system trace directory */ in tracefs_instance_get_dir()
339 if (!instance->name) in tracefs_instance_get_dir()
340 return strdup(instance->trace_dir); in tracefs_instance_get_dir()
342 ret = asprintf(&path, "%s/instances/%s", instance->trace_dir, instance->name); in tracefs_instance_get_dir()
344 tracefs_warning("Failed to allocate path for instance %s", in tracefs_instance_get_dir()
345 instance->name); in tracefs_instance_get_dir()
353 * tracefs_instance_get_name - return the name of an instance
354 * @instance: ftrace instance
356 * Returns the name of the given @instance.
359 const char *tracefs_instance_get_name(struct tracefs_instance *instance) in tracefs_instance_get_name() argument
361 if (instance) in tracefs_instance_get_name()
362 return instance->name; in tracefs_instance_get_name()
368 * @instance: The instance to get the buffer size from
377 ssize_t tracefs_instance_get_buffer_size(struct tracefs_instance *instance, int cpu) in tracefs_instance_get_buffer_size() argument
385 val = tracefs_instance_file_read(instance, "buffer_total_size_kb", NULL); in tracefs_instance_get_buffer_size()
391 val = tracefs_instance_file_read(instance, path, NULL); in tracefs_instance_get_buffer_size()
403 int tracefs_instance_set_buffer_size(struct tracefs_instance *instance, size_t size, int cpu) in tracefs_instance_set_buffer_size() argument
414 ret = tracefs_instance_file_write(instance, "buffer_size_kb", val); in tracefs_instance_set_buffer_size()
422 ret = tracefs_instance_file_write(instance, path, val); in tracefs_instance_set_buffer_size()
431 * tracefs_instance_get_trace_dir - return the top trace directory, where the instance is confuigred
432 * @instance: ftrace instance
434 * Returns the top trace directory where the given @instance is configured.
437 const char *tracefs_instance_get_trace_dir(struct tracefs_instance *instance) in tracefs_instance_get_trace_dir() argument
439 if (instance) in tracefs_instance_get_trace_dir()
440 return instance->trace_dir; in tracefs_instance_get_trace_dir()
462 static int instance_file_write(struct tracefs_instance *instance, in instance_file_write() argument
469 path = tracefs_instance_get_file(instance, file); in instance_file_write()
481 * tracefs_instance_file_write - Write in trace file of specific instance.
482 * @instance: ftrace instance, can be NULL for the top instance
488 int tracefs_instance_file_write(struct tracefs_instance *instance, in tracefs_instance_file_write() argument
491 return instance_file_write(instance, file, str, O_WRONLY | O_TRUNC); in tracefs_instance_file_write()
495 * tracefs_instance_file_append - Append to a trace file of specific instance.
496 * @instance: ftrace instance, can be NULL for the top instance.
502 int tracefs_instance_file_append(struct tracefs_instance *instance, in tracefs_instance_file_append() argument
505 return instance_file_write(instance, file, str, O_WRONLY); in tracefs_instance_file_append()
509 * tracefs_instance_file_clear - Clear a trace file of specific instance.
519 * @instance: ftrace instance, can be NULL for the top instance.
524 int tracefs_instance_file_clear(struct tracefs_instance *instance, in tracefs_instance_file_clear() argument
527 return instance_file_write(instance, file, NULL, O_WRONLY | O_TRUNC); in tracefs_instance_file_clear()
531 * tracefs_instance_file_read - Read from a trace file of specific instance.
532 * @instance: ftrace instance, can be NULL for the top instance
540 char *tracefs_instance_file_read(struct tracefs_instance *instance, in tracefs_instance_file_read() argument
547 path = tracefs_instance_get_file(instance, file); in tracefs_instance_file_read()
562 * @instance: ftrace instance, can be NULL for the top instance
569 int tracefs_instance_file_read_number(struct tracefs_instance *instance, in tracefs_instance_file_read_number() argument
578 str = tracefs_instance_file_read(instance, file, &size); in tracefs_instance_file_read_number()
593 * @instance: ftrace instance, can be NULL for the top instance
600 int tracefs_instance_file_open(struct tracefs_instance *instance, in tracefs_instance_file_open() argument
607 path = tracefs_instance_get_file(instance, file); in tracefs_instance_file_open()
619 static bool check_file_exists(struct tracefs_instance *instance, in check_file_exists() argument
627 path = tracefs_instance_get_dir(instance); in check_file_exists()
641 * tracefs_instance_exists - Check an instance with given name exists
642 * @name: name of the instance
644 * Returns true if the instance exists, false otherwise
658 * tracefs_file_exists - Check if a file with given name exists in given instance
659 * @instance: ftrace instance, can be NULL for the top instance
666 bool tracefs_file_exists(struct tracefs_instance *instance, const char *name) in tracefs_file_exists() argument
668 return check_file_exists(instance, name, false); in tracefs_file_exists()
672 * tracefs_dir_exists - Check if a directory with given name exists in given instance
673 * @instance: ftrace instance, can be NULL for the top instance
678 bool tracefs_dir_exists(struct tracefs_instance *instance, const char *name) in tracefs_dir_exists() argument
680 return check_file_exists(instance, name, true); in tracefs_dir_exists()
685 * @callback: user callback, called for each instance. Instance name is passed
714 char *instance; in tracefs_instances_walk() local
719 instance = trace_append_file(path, dent->d_name); in tracefs_instances_walk()
720 ret = stat(instance, &st); in tracefs_instances_walk()
721 free(instance); in tracefs_instances_walk()
772 * tracefs_instances - return a list of instance names
807 * @instance: ftrace instance, can be NULL for the top instance
809 * Returns the current trace clock of the given instance, or NULL in
813 char *tracefs_get_clock(struct tracefs_instance *instance) in tracefs_get_clock() argument
821 all_clocks = tracefs_instance_file_read(instance, "trace_clock", &bytes); in tracefs_get_clock()
842 * @instance: The instance to set affinity to (NULL for top level)
845 * Sets the tracing affinity CPU mask for @instance. The @mask is the raw
850 int tracefs_instance_set_affinity_raw(struct tracefs_instance *instance, in tracefs_instance_set_affinity_raw() argument
853 return tracefs_instance_file_write(instance, "tracing_cpumask", mask); in tracefs_instance_set_affinity_raw()
858 * @instance: The instance to set affinity to (NULL for top level)
862 * Sets the tracing affinity CPU mask for @instance. The bits in @set will be
870 int tracefs_instance_set_affinity_set(struct tracefs_instance *instance, in tracefs_instance_set_affinity_set() argument
934 ret = tracefs_instance_set_affinity_raw(instance, seq.buffer); in tracefs_instance_set_affinity_set()
944 * @instance: The instance to set affinity to (NULL for top level)
947 * Sets the tracing affinity CPU mask for @instance. The @cpu_str is a set
960 int tracefs_instance_set_affinity(struct tracefs_instance *instance, in tracefs_instance_set_affinity() argument
976 return tracefs_instance_set_affinity_set(instance, NULL, 0); in tracefs_instance_set_affinity()
1036 ret = tracefs_instance_set_affinity_set(instance, set, set_size); in tracefs_instance_set_affinity()
1044 * tracefs_instance_get_affinity_raw - read the affinity instance file
1045 * @instance: The instance to get affinity of (NULL for top level)
1047 * Reads the affinity file for @instance (or the top level if @instance
1053 char *tracefs_instance_get_affinity_raw(struct tracefs_instance *instance) in tracefs_instance_get_affinity_raw() argument
1055 return tracefs_instance_file_read(instance, "tracing_cpumask", NULL); in tracefs_instance_get_affinity_raw()
1080 * tracefs_instance_get_affinity_set - Retrieve the cpuset of an instance affinity
1081 * @instance: The instance to get affinity of (NULL for top level)
1085 * Reads the affinity of a given instance and updates the CPU set by the
1086 * instance.
1090 int tracefs_instance_get_affinity_set(struct tracefs_instance *instance, in tracefs_instance_get_affinity_set() argument
1105 affinity = tracefs_instance_get_affinity_raw(instance); in tracefs_instance_get_affinity_set()
1178 * tracefs_instance_get_affinity - Retrieve a string of CPUs for instance affinity
1179 * @instance: The instance to get affinity of (NULL for top level)
1181 * Reads the affinity of a given instance and returns a CPU count of the
1182 * instance. For example, if it reads "eb" it will return:
1191 char *tracefs_instance_get_affinity(struct tracefs_instance *instance) in tracefs_instance_get_affinity() argument
1201 affinity = tracefs_instance_get_affinity_raw(instance); in tracefs_instance_get_affinity()