]> git.ipfire.org Git - collecty.git/commitdiff
graph: Measure the time it takes to generate a graph
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Oct 2025 11:06:34 +0000 (11:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Oct 2025 11:06:34 +0000 (11:06 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/graph.c

index 5cbb5e38eeebb7ae1d30f76b2d2cac82cfcf70c7..92f0889a4f258e35fec5094e387e2974e88f87ad 100644 (file)
@@ -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);