From d9dc59e6502a134349f44902d65c69ced82c55b5 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 3 Oct 2025 11:06:34 +0000 Subject: [PATCH] graph: Measure the time it takes to generate a graph Signed-off-by: Michael Tremer --- src/daemon/graph.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/daemon/graph.c b/src/daemon/graph.c index 5cbb5e3..92f0889 100644 --- a/src/daemon/graph.c +++ b/src/daemon/graph.c @@ -213,6 +213,10 @@ int collecty_graph_render(collecty_graph* self, const char* object, double ymax = 0; int r; + // Measure the runtime + clock_t t_start = 0; + clock_t t_end = 0; + // Log action DEBUG(self->ctx, "Rendering %s...\n", collecty_graph_get_name(self)); @@ -220,6 +224,14 @@ int collecty_graph_render(collecty_graph* self, const char* object, if (!self->impl->render) return -ENOTSUP; + // Store the start time + t_start = clock(); + if (t_start < 0) { + ERROR(self->ctx, "clock() has failed: %m\n"); + r = -errno; + goto ERROR; + } + // Open a file handle to the output buffer f = open_memstream(buffer, length); if (!f) { @@ -332,8 +344,17 @@ int collecty_graph_render(collecty_graph* self, const char* object, goto ERROR; } + // Store the end time + t_end = clock(); + if (t_end < 0) { + ERROR(self->ctx, "clock() has failed: %m\n"); + r = -errno; + goto ERROR; + } + // Log action - DEBUG(self->ctx, "Rendered graph %s:\n", collecty_graph_get_name(self)); + DEBUG(self->ctx, "Rendered graph %s in %.2fms:\n", + collecty_graph_get_name(self), (double)(t_end - t_start) / CLOCKS_PER_SEC * 1000); DEBUG(self->ctx, " size : %d byte(s)\n", ftell(f)); DEBUG(self->ctx, " width : %d\n", w); DEBUG(self->ctx, " height : %d\n", h); -- 2.47.3