[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58318] branches/soc-2013-depsgraph_mt/ source/blender/blenkernel/intern/scene.c: Statistics calculation for threaded update

Sergey Sharybin sergey.vfx at gmail.com
Tue Jul 16 22:11:05 CEST 2013


Revision: 58318
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58318
Author:   nazgul
Date:     2013-07-16 20:11:05 +0000 (Tue, 16 Jul 2013)
Log Message:
-----------
Statistics calculation for threaded update

This commit adds per-thread statics for object
update threads which would give you information
about:

- How much objects each thread handled
- How much overall time thread spend on running
  object_handle_update.
- How long each of object_handle_update took.

Enabled by ./blender -d

The code is surrounded by ifdef, so shall be
not a problem to drop the code when we don't
need it anymore.

Also added special value for rt (debug_value)
of 13666 which switches scene update to a
single thread. Useful for benchmarking.

Modified Paths:
--------------
    branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c

Modified: branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c	2013-07-16 20:06:22 UTC (rev 58317)
+++ branches/soc-2013-depsgraph_mt/source/blender/blenkernel/intern/scene.c	2013-07-16 20:11:05 UTC (rev 58318)
@@ -87,6 +87,8 @@
 
 #include "RE_engine.h"
 
+#include "PIL_time.h"
+
 #include "IMB_colormanagement.h"
 
 //XXX #include "BIF_previewrender.h"
@@ -1160,10 +1162,24 @@
 		BKE_rigidbody_do_simulation(scene, ctime);
 }
 
+#define ENABLE_THREAD_STATISTICS
+
+#ifdef ENABLE_THREAD_STATISTICS
+typedef struct StatisicsEntry {
+	struct StatisicsEntry *next, *prev;
+	Object *object;
+	double time;
+} StatisicsEntry;
+#endif
+
 typedef struct ThreadedObjectUpdateState {
 	Scene *scene;
 	Scene *scene_parent;
 	SpinLock lock;
+
+#ifdef ENABLE_THREAD_STATISTICS
+	ListBase statistics[64];
+#endif
 } ThreadedObjectUpdateState;
 
 static void scene_update_object_add_task(void *node, void *user_data);
@@ -1198,13 +1214,36 @@
 	Scene *scene_parent = state->scene_parent;
 
 	if (object) {
+#ifdef ENABLE_THREAD_STATISTICS
+		double start_time = 0.0;
+#endif
+
 		PRINT("Thread %d: update object %s\n", threadid, object->id.name);
 
+#ifdef ENABLE_THREAD_STATISTICS
+		if (G.debug & G_DEBUG) {
+			start_time = PIL_check_seconds_timer();
+		}
+#endif
+
 		/* We only update object itself here, dupli-group will be updated
 		 * separately from main thread because of we've got no idea about
 		 * dependnecies inside the group.
 		 */
 		BKE_object_handle_update_ex(scene_parent, object, scene->rigidbody_world);
+
+#ifdef ENABLE_THREAD_STATISTICS
+		/* Calculate statistics. */
+		if (G.debug & G_DEBUG) {
+			StatisicsEntry *entry;
+
+			entry = MEM_mallocN(sizeof(StatisicsEntry), "update thread statistics");
+			entry->object = object;
+			entry->time = PIL_check_seconds_timer() - start_time;
+
+			BLI_addtail(&state->statistics[threadid], entry);
+		}
+#endif
 	}
 	else {
 		PRINT("Threda %d: update node %s\n", threadid,
@@ -1226,6 +1265,38 @@
 	BLI_task_pool_push(task_pool, scene_update_object_func, node, false, TASK_PRIORITY_LOW);
 }
 
+#ifdef ENABLE_THREAD_STATISTICS
+static void print_threads_statistics(ThreadedObjectUpdateState *state, int tot_thread)
+{
+	int i;
+
+	for (i = 0; i < tot_thread; i++) {
+		int total_objects = 0;
+		double total_time = 0.0;
+		StatisicsEntry *entry;
+
+		for (entry = state->statistics[i].first;
+		     entry;
+		     entry = entry->next)
+		{
+			total_objects++;
+			total_time += entry->time;
+		}
+
+		printf("Thread %d: total %d objects in %f sec.\n", i, total_objects, total_time);
+
+		for (entry = state->statistics[i].first;
+		     entry;
+		     entry = entry->next)
+		{
+			printf("  %s in %f sec\n", entry->object->id.name + 2, entry->time);
+		}
+
+		BLI_freelistN(&state->statistics[i]);
+	}
+}
+#endif
+
 static void scene_update_objects_threaded(Scene *scene, Scene *scene_parent)
 {
 	TaskScheduler *task_scheduler;
@@ -1242,6 +1313,10 @@
 		return;
 	}
 
+	if (G.debug_value == 13666) {
+		tot_thread = 1;
+	}
+
 	/* Ensure malloc will go go fine from threads,
 	 * this is needed because we could be in main thread here
 	 * and malloc could be non-threda safe at this point because
@@ -1279,6 +1354,9 @@
 
 	state.scene = scene;
 	state.scene_parent = scene_parent;
+#ifdef ENABLE_THREAD_STATISTICS
+	memset(state.statistics, 0, sizeof(state.statistics));
+#endif
 	BLI_spin_init(&state.lock);
 
 	task_scheduler = BLI_task_scheduler_create(tot_thread);
@@ -1317,6 +1395,12 @@
 
 	BLI_spin_end(&state.lock);
 
+#ifdef ENABLE_THREAD_STATISTICS
+	if (G.debug & G_DEBUG) {
+		print_threads_statistics(&state, tot_thread);
+	}
+#endif
+
 	/* XXX: Weak, very weak!
 	 *
 	 * We update dupligroups in single thread! :S




More information about the Bf-blender-cvs mailing list