aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2023-06-06 14:51:57 +0200
committerThomas White <taw@physics.org>2023-06-06 14:51:57 +0200
commitf2c82d7f2eb45ca8c2c1a01dca2e3f8a017ec0e3 (patch)
tree1094a802fc0358cf6dfe54481d382f72cfcc2313 /libcrystfel
parentd1968971d3f1456df1af7d976d56aaf3a54ac1f2 (diff)
Remove limit on number of children in the profiling graph
Diffstat (limited to 'libcrystfel')
-rw-r--r--libcrystfel/src/profile.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/libcrystfel/src/profile.c b/libcrystfel/src/profile.c
index 82f0217f..75983af3 100644
--- a/libcrystfel/src/profile.c
+++ b/libcrystfel/src/profile.c
@@ -41,8 +41,6 @@
#define CLOCK_MONOTONIC_RAW (CLOCK_MONOTONIC)
#endif
-#define MAX_PROFILE_CHILDREN 256
-
struct _profile_block
{
char *name;
@@ -52,8 +50,9 @@ struct _profile_block
double total_time;
struct _profile_block *parent;
- struct _profile_block *children[MAX_PROFILE_CHILDREN];
+ struct _profile_block **children;
int n_children;
+ int max_children;
};
@@ -80,6 +79,8 @@ static struct _profile_block *start_profile_block(const char *name)
return NULL;
}
b->n_children = 0;
+ b->max_children = 0;
+ b->children = NULL;
#ifdef HAVE_CLOCK_GETTIME
struct timespec tp;
@@ -133,12 +134,16 @@ static char *format_profile_block(struct _profile_block *b)
{
int i;
size_t total_len = 0;
- char *subbufs[MAX_PROFILE_CHILDREN];
+ char **subbufs;
char *full_buf;
+ subbufs = malloc(b->n_children * sizeof(char *));
+ if ( subbufs == NULL ) return NULL;
+
total_len = 32 + strlen(b->name);
for ( i=0; i<b->n_children; i++ ) {
subbufs[i] = format_profile_block(b->children[i]);
+ if ( subbufs[i] == NULL ) return NULL;
total_len += 1 + strlen(subbufs[i]);
}
@@ -151,6 +156,8 @@ static char *format_profile_block(struct _profile_block *b)
}
strcat(full_buf, ")");
+ free(subbufs);
+
return full_buf;
}
@@ -207,12 +214,16 @@ void profile_start(const char *name)
if ( pd == NULL ) return;
- if ( pd->current->n_children >= MAX_PROFILE_CHILDREN ) {
- fprintf(stderr, "Too many profile children "
- "(opening %s inside %s).\n",
- pd->current->name, name);
- fflush(stderr);
- abort();
+ if ( pd->current->n_children >= pd->current->max_children ) {
+ struct _profile_block **nblock;
+ int nmax = pd->current->n_children + 64;
+ nblock = realloc(pd->current->children, nmax*sizeof(struct _profile_block));
+ if ( nblock == NULL ) {
+ fprintf(stderr, "Failed to allocate profiling record. Try again without --profile.\n");
+ abort();
+ }
+ pd->current->children = nblock;
+ pd->current->max_children = nmax;
}
b = start_profile_block(name);