aboutsummaryrefslogtreecommitdiff
path: root/src/im-sandbox.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2022-04-29 16:53:49 +0200
committerThomas White <taw@physics.org>2022-05-04 14:47:35 +0200
commit3fb81ddf7059599dba9b8b223156801af6885fc1 (patch)
tree23fb95dbf4279c164b5f564082fb4b9b40e5bbf2 /src/im-sandbox.c
parentcdb51dbec109ccde45c8a4ceb29ea925d01e2920 (diff)
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
Diffstat (limited to 'src/im-sandbox.c')
-rw-r--r--src/im-sandbox.c12
1 files changed, 11 insertions, 1 deletions
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);
}
}