summaryrefslogtreecommitdiff
path: root/lib/trace.c
diff options
context:
space:
mode:
authorJerome Forissier <jerome.forissier@linaro.org>2024-12-13 13:45:36 +0100
committerTom Rini <trini@konsulko.com>2024-12-31 19:00:46 -0600
commit60a684e0a9f341d96c30ce0e1e472d7a203c85aa (patch)
tree601b5741220ea12963a8af890c7c8984caeb0206 /lib/trace.c
parentc3c20a5e3c04c7c9e0866812f6b615ec15af06d9 (diff)
trace: add support for 'trace wipe'
Implement a 'trace wipe' command to delete the currently accumulated trace data. This comes handy when someone needs to trace a particular command. For example: => trace pause; trace wipe => trace resume; dhcp; trace pause => trace stats => trace calls 0x02100000 0x10000000 => tftpput $profbase $profoffset 192.168.0.16:trace.bin Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Diffstat (limited to 'lib/trace.c')
-rw-r--r--lib/trace.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/lib/trace.c b/lib/trace.c
index cabbe47b58a..def9f912c92 100644
--- a/lib/trace.c
+++ b/lib/trace.c
@@ -351,14 +351,8 @@ static int get_func_count(void)
return gd->mon_len / FUNC_SITE_SIZE;
}
-/**
- * trace_init() - initialize the tracing system and enable it
- *
- * @buff: Pointer to trace buffer
- * @buff_size: Size of trace buffer
- * Return: 0 if ok
- */
-int notrace trace_init(void *buff, size_t buff_size)
+static int notrace trace_init_(void *buff, size_t buff_size, bool copy_early,
+ bool enable)
{
int func_count = get_func_count();
size_t needed;
@@ -368,7 +362,7 @@ int notrace trace_init(void *buff, size_t buff_size)
return func_count;
trace_save_gd();
- if (!was_disabled) {
+ if (copy_early) {
#ifdef CONFIG_TRACE_EARLY
ulong used, count;
char *end;
@@ -394,9 +388,6 @@ int notrace trace_init(void *buff, size_t buff_size)
}
puts("\n");
memcpy(buff, hdr, used);
-#else
- puts("trace: already enabled\n");
- return -EALREADY;
#endif
}
hdr = (struct trace_hdr *)buff;
@@ -419,13 +410,41 @@ int notrace trace_init(void *buff, size_t buff_size)
hdr->ftrace_size = (buff_size - needed) / sizeof(*hdr->ftrace);
hdr->depth_limit = CONFIG_TRACE_CALL_DEPTH_LIMIT;
- puts("trace: enabled\n");
- trace_enabled = 1;
+ printf("trace: initialized, %senabled\n", enable ? "" : "not ");
+ trace_enabled = enable;
trace_inited = 1;
return 0;
}
+/**
+ * trace_init() - initialize the tracing system and enable it
+ *
+ * @buff: Pointer to trace buffer
+ * @buff_size: Size of trace buffer
+ * Return: 0 if ok
+ */
+int notrace trace_init(void *buff, size_t buff_size)
+{
+ /* If traces are enabled already, we may have early traces to copy */
+ return trace_init_(buff, buff_size, trace_enabled, true);
+}
+
+/**
+ * trace_clear() - clear accumulated traced data
+ *
+ * May be called with tracing enabled or disabled.
+ */
+int notrace trace_clear(void)
+{
+ bool was_enabled = trace_enabled;
+
+ if (trace_enabled)
+ trace_enabled = 0;
+ return trace_init_(gd->trace_buff, CONFIG_TRACE_BUFFER_SIZE,
+ false, was_enabled);
+}
+
#ifdef CONFIG_TRACE_EARLY
/**
* trace_early_init() - initialize the tracing system for early tracing