aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (Google) <rostedt@goodmis.org>2022-11-14 15:45:20 -0500
committerSteven Rostedt (Google) <rostedt@goodmis.org>2022-11-14 15:54:51 -0500
commit936193d852423321c0baf1ca7e09a8de50bd46ca (patch)
treee2cc5af9ef33b7be3ab6728b9ff9117f236380c7
parent772fdb8dad255249a7cc79dd77e62802fd2124c4 (diff)
downloadlibtracefs-936193d852423321c0baf1ca7e09a8de50bd46ca.tar.gz
libtracefs: Add tracefs_instance_get_buffer_size() API
Add the function tracefs_instance_get_buffer_size() to return the size of the ring buffer. Link: https://lore.kernel.org/linux-trace-devel/20221114204522.2433500-3-rostedt@goodmis.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--Documentation/libtracefs-instances-utils.txt14
-rw-r--r--Documentation/libtracefs.txt1
-rw-r--r--include/tracefs.h1
-rw-r--r--src/tracefs-instance.c37
4 files changed, 49 insertions, 4 deletions
diff --git a/Documentation/libtracefs-instances-utils.txt b/Documentation/libtracefs-instances-utils.txt
index a79cc34..9bec8a9 100644
--- a/Documentation/libtracefs-instances-utils.txt
+++ b/Documentation/libtracefs-instances-utils.txt
@@ -3,9 +3,8 @@ libtracefs(3)
NAME
----
-tracefs_instance_get_name, tracefs_instance_get_trace_dir,
-tracefs_instances_walk, tracefs_instance_exists -
-Helper functions for working with tracing instances.
+tracefs_instance_get_name, tracefs_instance_get_trace_dir, tracefs_instances_walk, tracefs_instance_exists,
+tracefs_instance_get_buffer_size - Helper functions for working with tracing instances.
SYNOPSIS
--------
@@ -17,7 +16,7 @@ const char pass:[*]*tracefs_instance_get_name*(struct tracefs_instance pass:[*]_
const char pass:[*]*tracefs_instance_get_trace_dir*(struct tracefs_instance pass:[*]_instance_);
int *tracefs_instances_walk*(int (pass:[*]_callback_)(const char pass:[*], void pass:[*]), void pass:[*]_context)_;
bool *tracefs_instance_exists*(const char pass:[*]_name_);
-
+size_t *tracefs_instance_get_buffer_size*(struct tracefs_instance pass:[*]_instance_, int _cpu_);
--
DESCRIPTION
@@ -39,6 +38,10 @@ called for the top top instance.
The *tracefs_instance_exists()* function checks if an instance with the given
_name_ exists in the system.
+The *tracefs_instace_get_buffer_size()* returns the size of the ring buffer. If _cpu_
+is negative, it returns the total size of all the per CPU ring buffers, otherwise
+it returns the size of the per CPU ring buffer for _cpu_.
+
RETURN VALUE
------------
The *tracefs_instance_get_name()* returns a string or NULL in case of the top
@@ -53,6 +56,9 @@ if the iteration was stopped by the _callback_, or -1 in case of an error.
The *tracefs_instance_exists()* returns true if an instance with the given _name_
exists in the system or false otherwise.
+The *tracefs_instance_get_buffer_size()* returns the size of the ring buffer depending on
+the _cpu_ value passed in, or -1 on error.
+
EXAMPLE
-------
[source,c]
diff --git a/Documentation/libtracefs.txt b/Documentation/libtracefs.txt
index e029740..3b485a0 100644
--- a/Documentation/libtracefs.txt
+++ b/Documentation/libtracefs.txt
@@ -45,6 +45,7 @@ Trace instances:
char pass:[*]*tracefs_instance_get_affinity*(struct tracefs_instance pass:[*]_instance_);
int *tracefs_instance_get_affinity_set*(struct tracefs_instance pass:[*]_instance_, cpu_set_t pass:[*]_set_, size_t _set_size_);
char pass:[*]*tracefs_instance_get_affinity_raw*(struct tracefs_instance pass:[*]_instance_);
+ size_t *tracefs_instance_get_buffer_size*(struct tracefs_instance pass:[*]_instance_, int _cpu_);
Trace events:
char pass:[*]pass:[*]*tracefs_event_systems*(const char pass:[*]_tracing_dir_);
diff --git a/include/tracefs.h b/include/tracefs.h
index f2524b0..3391deb 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -55,6 +55,7 @@ char *tracefs_instance_get_affinity(struct tracefs_instance *instance);
char *tracefs_instance_get_affinity_raw(struct tracefs_instance *instance);
int tracefs_instance_get_affinity_set(struct tracefs_instance *instance,
cpu_set_t *set, size_t set_size);
+ssize_t tracefs_instance_get_buffer_size(struct tracefs_instance *instance, int cpu);
char **tracefs_instances(const char *regex);
bool tracefs_instance_exists(const char *name);
diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c
index 249a5c9..206f8c9 100644
--- a/src/tracefs-instance.c
+++ b/src/tracefs-instance.c
@@ -364,6 +364,43 @@ const char *tracefs_instance_get_name(struct tracefs_instance *instance)
}
/**
+ * tracefs_instance_get_buffer_size - return the buffer size of the ring buffer
+ * @instance: The instance to get the buffer size from
+ * @cpu: if less that zero, will return the total size, otherwise the cpu size
+ *
+ * Returns the buffer size. If @cpu is less than zero, it returns the total size
+ * of the ring buffer otherwise it returs the size of the buffer for the given
+ * CPU.
+ *
+ * Returns -1 on error.
+ */
+ssize_t tracefs_instance_get_buffer_size(struct tracefs_instance *instance, int cpu)
+{
+ unsigned long long size;
+ char *path;
+ char *val;
+ int ret;
+
+ if (cpu < 0) {
+ val = tracefs_instance_file_read(instance, "buffer_total_size_kb", NULL);
+ } else {
+ ret = asprintf(&path, "per_cpu/cpu%d/buffer_size_kb", cpu);
+ if (ret < 0)
+ return ret;
+
+ val = tracefs_instance_file_read(instance, path, NULL);
+ free(path);
+ }
+
+ if (!val)
+ return -1;
+
+ size = strtoull(val, NULL, 0);
+ free(val);
+ return size;
+}
+
+/**
* tracefs_instance_get_trace_dir - return the top trace directory, where the instance is confuigred
* @instance: ftrace instance
*