From 3fb81ddf7059599dba9b8b223156801af6885fc1 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 29 Apr 2022 16:53:49 +0200 Subject: Add improved profiling Improvements: - Recursive, so we can see how things are working at different levels - Everything is profiled, even if not explicitly labelled - No possibility of losing time - Detects mistakes if routines aren't wrapped correctly --- src/im-sandbox.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/im-sandbox.c') diff --git a/src/im-sandbox.c b/src/im-sandbox.c index ad22d96f..ace58499 100644 --- a/src/im-sandbox.c +++ b/src/im-sandbox.c @@ -61,6 +61,7 @@ #include "im-sandbox.h" #include "process_image.h" #include "im-zmq.h" +#include "profile.h" struct sandbox @@ -330,6 +331,10 @@ static int run_work(const struct index_args *iargs, Stream *st, int allDone = 0; struct im_zmq *zmqstuff = NULL; + if ( sb->profile ) { + profile_init(); + } + /* Connect via ZMQ */ if ( sb->zmq ) { zmqstuff = im_zmq_connect(sb->zmq_address, @@ -356,10 +361,12 @@ static int run_work(const struct index_args *iargs, Stream *st, /* Wait until an event is ready */ sb->shared->pings[cookie]++; set_last_task(sb->shared->last_task[cookie], "wait_event"); + profile_start("wait-queue-semaphore"); if ( sem_wait(sb->queue_sem) != 0 ) { ERROR("Failed to wait on queue semaphore: %s\n", strerror(errno)); } + profile_end("wait-queue-semaphore"); /* Get the event from the queue */ set_last_task(sb->shared->last_task[cookie], "read_queue"); @@ -446,8 +453,10 @@ static int run_work(const struct index_args *iargs, Stream *st, } sb->shared->time_last_start[cookie] = get_monotonic_seconds(); + profile_start("process-image"); process_image(iargs, &pargs, st, cookie, tmpdir, ser, - sb->shared, taccs, sb->shared->last_task[cookie]); + sb->shared, sb->shared->last_task[cookie]); + profile_end("process-image"); /* pargs.zmq_data will be copied into the image structure, so * that it can be queried for "header" values etc. It will @@ -455,6 +464,7 @@ static int run_work(const struct index_args *iargs, Stream *st, if ( sb->profile ) { pthread_mutex_lock(&sb->shared->term_lock); + profile_print_and_reset(); pthread_mutex_unlock(&sb->shared->term_lock); } } -- cgit v1.2.3