aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libcrystfel/src/profile.c35
-rw-r--r--src/im-sandbox.c2
2 files changed, 28 insertions, 9 deletions
diff --git a/libcrystfel/src/profile.c b/libcrystfel/src/profile.c
index 2bbebf1f..f20e4b7e 100644
--- a/libcrystfel/src/profile.c
+++ b/libcrystfel/src/profile.c
@@ -33,6 +33,7 @@
#include <string.h>
#include <time.h>
#include <assert.h>
+#include <unistd.h>
#include "profile.h"
@@ -128,15 +129,29 @@ void profile_init()
}
-static void print_profile_block(struct _profile_block *b)
+static char *format_profile_block(struct _profile_block *b)
{
int i;
- printf("(%s %.3f", b->name, b->total_time);
+ size_t total_len = 0;
+ char *subbufs[MAX_PROFILE_CHILDREN];
+ char *full_buf;
+
+ total_len = 32 + strlen(b->name);
+ for ( i=0; i<b->n_children; i++ ) {
+ subbufs[i] = format_profile_block(b->children[i]);
+ total_len += 1 + strlen(subbufs[i]);
+ }
+
+ full_buf = malloc(total_len);
+ snprintf(full_buf, 32, "(%s %.3f", b->name, b->total_time);
for ( i=0; i<b->n_children; i++ ) {
- printf(" ");
- print_profile_block(b->children[i]);
+ strcat(full_buf, " ");
+ strcat(full_buf, subbufs[i]);
+ free(subbufs[i]);
}
- printf(")");
+ strcat(full_buf, ")");
+
+ return full_buf;
}
@@ -153,6 +168,9 @@ static void free_profile_block(struct _profile_block *b)
void profile_print_and_reset()
{
+ char *buf;
+ char *buf2;
+
if ( pd == NULL ) {
fprintf(stderr, "Profiling not initialised yet!\n");
fflush(stderr);
@@ -168,8 +186,11 @@ void profile_print_and_reset()
stop_profile_block(pd->root);
- print_profile_block(pd->root);
- printf("\n");
+ buf = format_profile_block(pd->root);
+ buf2 = malloc(2+strlen(buf));
+ strcpy(buf2, buf);
+ strcat(buf2, "\n");
+ write(STDOUT_FILENO, buf2, strlen(buf2));
free_profile_block(pd->root);
pd->root = start_profile_block("root");
diff --git a/src/im-sandbox.c b/src/im-sandbox.c
index ace58499..bd3f47e7 100644
--- a/src/im-sandbox.c
+++ b/src/im-sandbox.c
@@ -463,9 +463,7 @@ static int run_work(const struct index_args *iargs, Stream *st,
* eventually be freed by image_free() under process_image() */
if ( sb->profile ) {
- pthread_mutex_lock(&sb->shared->term_lock);
profile_print_and_reset();
- pthread_mutex_unlock(&sb->shared->term_lock);
}
}