[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23419] trunk/blender/source/blender: Changes to allow python to do redraws through the timer operator, a reliable way to test the overhead of the python api ( printed to the consoel on exit).

Campbell Barton ideasman42 at gmail.com
Tue Sep 22 11:12:39 CEST 2009


Revision: 23419
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23419
Author:   campbellbarton
Date:     2009-09-22 11:12:39 +0200 (Tue, 22 Sep 2009)

Log Message:
-----------
Changes to allow python to do redraws through the timer operator, a reliable way to test the overhead of the python api (printed to the consoel on exit).

- rename WM_OT_ten_timer to WM_OT_redraw_timer
- added iterations argument to run more then 10 times (10 is default still)
- use report api rather then always calling a popup directly.
- added a new test that draws every region without swapping.
- dont show the info popup when operators are called from python.
- operators called from python now print reports, useful with the interactive console.

 eg. 
>>> bpy.ops.wm.redraw_timer(type='DRAW_WIN', iterations=300)
Info: 300 x Draw Window: 4168.56 ms,  average: 13.8952

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/report.c
    trunk/blender/source/blender/makesrna/intern/rna_sequence.c
    trunk/blender/source/blender/python/intern/bpy_operator.c
    trunk/blender/source/blender/windowmanager/intern/wm_event_system.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/blenkernel/intern/report.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/report.c	2009-09-22 09:04:43 UTC (rev 23418)
+++ trunk/blender/source/blender/blenkernel/intern/report.c	2009-09-22 09:12:39 UTC (rev 23419)
@@ -230,7 +230,7 @@
 	DynStr *ds;
 	char *cstring;
 
-	if(!reports)
+	if(!reports || !reports->list.first)
 		return NULL;
 
 	ds= BLI_dynstr_new();

Modified: trunk/blender/source/blender/makesrna/intern/rna_sequence.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_sequence.c	2009-09-22 09:04:43 UTC (rev 23418)
+++ trunk/blender/source/blender/makesrna/intern/rna_sequence.c	2009-09-22 09:12:39 UTC (rev 23419)
@@ -520,6 +520,7 @@
 	
 	prop= RNA_def_property(srna, "channel", PROP_INT, PROP_UNSIGNED);
 	RNA_def_property_int_sdna(prop, NULL, "machine");
+	RNA_def_property_range(prop, 0, MAXSEQ-1);
 	RNA_def_property_ui_text(prop, "Channel", "Y position of the sequence strip.");
 	RNA_def_property_int_funcs(prop, NULL, "rna_SequenceEditor_channel_set",NULL); // overlap test
 	RNA_def_property_update(prop, NC_SCENE|ND_SEQUENCER, NULL);

Modified: trunk/blender/source/blender/python/intern/bpy_operator.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_operator.c	2009-09-22 09:04:43 UTC (rev 23418)
+++ trunk/blender/source/blender/python/intern/bpy_operator.c	2009-09-22 09:12:39 UTC (rev 23419)
@@ -89,6 +89,16 @@
 		if(BPy_reports_to_error(reports))
 			error_val = -1;
 
+		/* operator output is nice to have in the terminal/console too */
+		if(reports->list.first) {
+			char *report_str= BKE_reports_string(reports, 0); /* all reports */
+
+			if(report_str) {
+				PySys_WriteStdout(report_str);
+				MEM_freeN(report_str);
+			}
+		}
+
 		BKE_reports_clear(reports);
 		if ((reports->flag & RPT_FREE) == 0)
 		{

Modified: trunk/blender/source/blender/windowmanager/intern/wm_event_system.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_event_system.c	2009-09-22 09:04:43 UTC (rev 23418)
+++ trunk/blender/source/blender/windowmanager/intern/wm_event_system.c	2009-09-22 09:12:39 UTC (rev 23419)
@@ -415,7 +415,9 @@
 		else
 			printf("invalid operator call %s\n", ot->idname); /* debug, important to leave a while, should never happen */
 
-		if(!(retval & OPERATOR_RUNNING_MODAL)) {
+		/* Note, if the report is given as an argument then assume the caller will deal with displaying them
+		 * currently python only uses this */
+		if(!(retval & OPERATOR_RUNNING_MODAL) && reports==NULL) {
 			if(op->reports->list.first) /* only show the report if the report list was not given in the function */
 				uiPupMenuReports(C, op->reports);
 		

Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2009-09-22 09:04:43 UTC (rev 23418)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2009-09-22 09:12:39 UTC (rev 23419)
@@ -1979,17 +1979,19 @@
 
 /* uses no type defines, fully local testing function anyway... ;) */
 
-static int ten_timer_exec(bContext *C, wmOperator *op)
+static int redraw_timer_exec(bContext *C, wmOperator *op)
 {
 	ARegion *ar= CTX_wm_region(C);
 	double stime= PIL_check_seconds_timer();
 	int type = RNA_int_get(op->ptr, "type");
-	int a, time;
-	char tmpstr[128];
+	int iter = RNA_int_get(op->ptr, "iterations");
+	int a;
+	float time;
+	char *infostr= "";
 	
 	WM_cursor_wait(1);
-	
-	for(a=0; a<10; a++) {
+
+	for(a=0; a<iter; a++) {
 		if (type==0) {
 			ED_region_do_draw(C, ar);
 		} 
@@ -2005,13 +2007,35 @@
 			wmWindow *win= CTX_wm_window(C);
 			ScrArea *sa;
 			
+			ScrArea *sa_back= CTX_wm_area(C);
+			ARegion *ar_back= CTX_wm_region(C);
+
+			for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next) {
+				ARegion *ar_iter;
+				CTX_wm_area_set(C, sa);
+
+				for(ar_iter= sa->regionbase.first; ar_iter; ar_iter= ar_iter->next) {
+					CTX_wm_region_set(C, ar_iter);
+					ED_region_do_draw(C, ar_iter);
+				}
+			}
+
+			CTX_wm_window_set(C, win);	/* XXX context manipulation warning! */
+
+			CTX_wm_area_set(C, sa_back);
+			CTX_wm_region_set(C, ar_back);
+		}
+		else if (type==3) {
+			wmWindow *win= CTX_wm_window(C);
+			ScrArea *sa;
+
 			for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next)
 				ED_area_tag_redraw(sa);
 			wm_draw_update(C);
 			
 			CTX_wm_window_set(C, win);	/* XXX context manipulation warning! */
 		}
-		else if (type==3) {
+		else if (type==4) {
 			Scene *scene= CTX_data_scene(C);
 			
 			if(a & 1) scene->r.cfra--;
@@ -2024,40 +2048,43 @@
 		}
 	}
 	
-	time= (int) ((PIL_check_seconds_timer()-stime)*1000);
+	time= ((PIL_check_seconds_timer()-stime)*1000);
 	
-	if(type==0) sprintf(tmpstr, "10 x Draw Region: %d ms", time);
-	if(type==1) sprintf(tmpstr, "10 x Draw Region and Swap: %d ms", time);
-	if(type==2) sprintf(tmpstr, "10 x Draw Window and Swap: %d ms", time);
-	if(type==3) sprintf(tmpstr, "Anim Step: %d ms", time);
-	if(type==4) sprintf(tmpstr, "10 x Undo/Redo: %d ms", time);
+	if(type==0) infostr= "Draw Region";
+	if(type==1) infostr= "Draw Region and Swap";
+	if(type==2) infostr= "Draw Window";
+	if(type==3) infostr= "Draw Window and Swap";
+	if(type==4) infostr= "Animation Steps";
+	if(type==5) infostr= "Undo/Redo";
 	
 	WM_cursor_wait(0);
 	
-	uiPupMenuNotice(C, tmpstr);
+	BKE_reportf(op->reports, RPT_INFO, "%d x %s: %.2f ms,  average: %.4f", iter, infostr, time, time/iter);
 	
 	return OPERATOR_FINISHED;
 }
 
-static void WM_OT_ten_timer(wmOperatorType *ot)
+static void WM_OT_redraw_timer(wmOperatorType *ot)
 {
 	static EnumPropertyItem prop_type_items[] = {
 	{0, "DRAW", 0, "Draw Region", ""},
-	{1, "DRAWSWAP", 0, "Draw Region + Swap", ""},
-	{2, "DRAWWINSWAP", 0, "Draw Window + Swap", ""},
-	{3, "ANIMSTEP", 0, "Anim Step", ""},
-	{4, "UNDO", 0, "Undo/Redo", ""},
+	{1, "DRAW_SWAP", 0, "Draw Region + Swap", ""},
+	{2, "DRAW_WIN", 0, "Draw Window", ""},
+	{3, "DRAW_WIN_SWAP", 0, "Draw Window + Swap", ""},
+	{4, "ANIM_STEP", 0, "Anim Step", ""},
+	{5, "UNDO", 0, "Undo/Redo", ""},
 	{0, NULL, 0, NULL, NULL}};
 	
-	ot->name= "Ten Timer";
-	ot->idname= "WM_OT_ten_timer";
-	ot->description="Ten Timer operator.";
+	ot->name= "Redraw Timer";
+	ot->idname= "WM_OT_redraw_timer";
+	ot->description="Simple redraw timer to test the speed of updating the interface.";
 	
 	ot->invoke= WM_menu_invoke;
-	ot->exec= ten_timer_exec;
+	ot->exec= redraw_timer_exec;
 	ot->poll= WM_operator_winactive;
 	
 	RNA_def_enum(ot->srna, "type", prop_type_items, 0, "Type", "");
+	RNA_def_int(ot->srna, "iterations", 10, 1,INT_MAX, "Iterations", "Number of times to redraw", 1,1000);
 
 }
 
@@ -2092,7 +2119,7 @@
 	WM_operatortype_append(WM_OT_jobs_timer);
 	WM_operatortype_append(WM_OT_save_as_mainfile);
 	WM_operatortype_append(WM_OT_save_mainfile);
-	WM_operatortype_append(WM_OT_ten_timer);
+	WM_operatortype_append(WM_OT_redraw_timer);
 	WM_operatortype_append(WM_OT_debug_menu);
 	WM_operatortype_append(WM_OT_search_menu);
 }
@@ -2127,7 +2154,7 @@
 	WM_keymap_add_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
 
 	/* debug/testing */
-	WM_keymap_verify_item(keymap, "WM_OT_ten_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
+	WM_keymap_verify_item(keymap, "WM_OT_redraw_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
 	WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
 	WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0);
 	





More information about the Bf-blender-cvs mailing list