From 97ae0f22cd5709e4a1af532d594012426c2b364e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 13 Apr 2015 14:37:12 +0500 Subject: Depsgraph debug: Remove hardcoded array of BLENDER_MAX_THREADS elements Allocate statistics array dynamically, so increasing max number of threads does not increase sloppyness of the memory usage. For the further cleanups: we can try alloca-ing this array, but it's also not really safe because we can have quite huge number of threads in the future. Plus statistics will allocate memory for each individual entry, so using alloca is not going to give anything beneficial here. --- source/blender/blenkernel/intern/scene.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 443671f5a61..60b05cea21b 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -1373,13 +1373,13 @@ typedef struct ThreadedObjectUpdateState { Scene *scene_parent; double base_time; - /* Execution statistics */ - ListBase statistics[BLENDER_MAX_THREADS]; - bool has_updated_objects; - #ifdef MBALL_SINGLETHREAD_HACK bool has_mballs; #endif + + /* Execution statistics */ + bool has_updated_objects; + ListBase *statistics; } ThreadedObjectUpdateState; static void scene_update_object_add_task(void *node, void *user_data); @@ -1448,6 +1448,8 @@ static void scene_update_object_func(TaskPool *pool, void *taskdata, int threadi if (add_to_stats) { StatisicsEntry *entry; + BLI_assert(threadid < BLI_pool_get_num_threads(pool)); + entry = MEM_mallocN(sizeof(StatisicsEntry), "update thread statistics"); entry->object = object; entry->start_time = start_time; @@ -1576,7 +1578,9 @@ static void scene_update_objects(EvaluationContext *eval_ctx, Main *bmain, Scene /* Those are only needed when blender is run with --debug argument. */ if (G.debug & G_DEBUG_DEPSGRAPH) { - memset(state.statistics, 0, sizeof(state.statistics)); + const int tot_thread = BLI_task_scheduler_num_threads(task_scheduler); + state.statistics = MEM_callocN(tot_thread * sizeof(*state.statistics), + "scene update objects stats"); state.has_updated_objects = false; state.base_time = PIL_check_seconds_timer(); } @@ -1593,6 +1597,7 @@ static void scene_update_objects(EvaluationContext *eval_ctx, Main *bmain, Scene if (G.debug & G_DEBUG_DEPSGRAPH) { print_threads_statistics(&state); + MEM_freeN(state.statistics); } /* We do single thread pass to update all the objects which are in cyclic dependency. -- cgit v1.2.3