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
This commit is contained in:
Campbell Barton 2009-09-22 09:12:39 +00:00
parent 3c8d34b94e
commit 92145d5950
5 changed files with 66 additions and 26 deletions

@ -230,7 +230,7 @@ char *BKE_reports_string(ReportList *reports, ReportType level)
DynStr *ds; DynStr *ds;
char *cstring; char *cstring;
if(!reports) if(!reports || !reports->list.first)
return NULL; return NULL;
ds= BLI_dynstr_new(); ds= BLI_dynstr_new();

@ -520,6 +520,7 @@ static void rna_def_sequence(BlenderRNA *brna)
prop= RNA_def_property(srna, "channel", PROP_INT, PROP_UNSIGNED); prop= RNA_def_property(srna, "channel", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "machine"); 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_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_int_funcs(prop, NULL, "rna_SequenceEditor_channel_set",NULL); // overlap test
RNA_def_property_update(prop, NC_SCENE|ND_SEQUENCER, NULL); RNA_def_property_update(prop, NC_SCENE|ND_SEQUENCER, NULL);

@ -89,6 +89,16 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
if(BPy_reports_to_error(reports)) if(BPy_reports_to_error(reports))
error_val = -1; 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); BKE_reports_clear(reports);
if ((reports->flag & RPT_FREE) == 0) if ((reports->flag & RPT_FREE) == 0)
{ {

@ -415,7 +415,9 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, P
else else
printf("invalid operator call %s\n", ot->idname); /* debug, important to leave a while, should never happen */ 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 */ if(op->reports->list.first) /* only show the report if the report list was not given in the function */
uiPupMenuReports(C, op->reports); uiPupMenuReports(C, op->reports);

@ -1979,17 +1979,19 @@ void WM_OT_radial_control_partial(wmOperatorType *ot)
/* uses no type defines, fully local testing function anyway... ;) */ /* 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); ARegion *ar= CTX_wm_region(C);
double stime= PIL_check_seconds_timer(); double stime= PIL_check_seconds_timer();
int type = RNA_int_get(op->ptr, "type"); int type = RNA_int_get(op->ptr, "type");
int a, time; int iter = RNA_int_get(op->ptr, "iterations");
char tmpstr[128]; int a;
float time;
char *infostr= "";
WM_cursor_wait(1); WM_cursor_wait(1);
for(a=0; a<10; a++) { for(a=0; a<iter; a++) {
if (type==0) { if (type==0) {
ED_region_do_draw(C, ar); ED_region_do_draw(C, ar);
} }
@ -2005,13 +2007,35 @@ static int ten_timer_exec(bContext *C, wmOperator *op)
wmWindow *win= CTX_wm_window(C); wmWindow *win= CTX_wm_window(C);
ScrArea *sa; 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) for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next)
ED_area_tag_redraw(sa); ED_area_tag_redraw(sa);
wm_draw_update(C); wm_draw_update(C);
CTX_wm_window_set(C, win); /* XXX context manipulation warning! */ CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
} }
else if (type==3) { else if (type==4) {
Scene *scene= CTX_data_scene(C); Scene *scene= CTX_data_scene(C);
if(a & 1) scene->r.cfra--; if(a & 1) scene->r.cfra--;
@ -2024,40 +2048,43 @@ static int ten_timer_exec(bContext *C, wmOperator *op)
} }
} }
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==0) infostr= "Draw Region";
if(type==1) sprintf(tmpstr, "10 x Draw Region and Swap: %d ms", time); if(type==1) infostr= "Draw Region and Swap";
if(type==2) sprintf(tmpstr, "10 x Draw Window and Swap: %d ms", time); if(type==2) infostr= "Draw Window";
if(type==3) sprintf(tmpstr, "Anim Step: %d ms", time); if(type==3) infostr= "Draw Window and Swap";
if(type==4) sprintf(tmpstr, "10 x Undo/Redo: %d ms", time); if(type==4) infostr= "Animation Steps";
if(type==5) infostr= "Undo/Redo";
WM_cursor_wait(0); 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; return OPERATOR_FINISHED;
} }
static void WM_OT_ten_timer(wmOperatorType *ot) static void WM_OT_redraw_timer(wmOperatorType *ot)
{ {
static EnumPropertyItem prop_type_items[] = { static EnumPropertyItem prop_type_items[] = {
{0, "DRAW", 0, "Draw Region", ""}, {0, "DRAW", 0, "Draw Region", ""},
{1, "DRAWSWAP", 0, "Draw Region + Swap", ""}, {1, "DRAW_SWAP", 0, "Draw Region + Swap", ""},
{2, "DRAWWINSWAP", 0, "Draw Window + Swap", ""}, {2, "DRAW_WIN", 0, "Draw Window", ""},
{3, "ANIMSTEP", 0, "Anim Step", ""}, {3, "DRAW_WIN_SWAP", 0, "Draw Window + Swap", ""},
{4, "UNDO", 0, "Undo/Redo", ""}, {4, "ANIM_STEP", 0, "Anim Step", ""},
{5, "UNDO", 0, "Undo/Redo", ""},
{0, NULL, 0, NULL, NULL}}; {0, NULL, 0, NULL, NULL}};
ot->name= "Ten Timer"; ot->name= "Redraw Timer";
ot->idname= "WM_OT_ten_timer"; ot->idname= "WM_OT_redraw_timer";
ot->description="Ten Timer operator."; ot->description="Simple redraw timer to test the speed of updating the interface.";
ot->invoke= WM_menu_invoke; ot->invoke= WM_menu_invoke;
ot->exec= ten_timer_exec; ot->exec= redraw_timer_exec;
ot->poll= WM_operator_winactive; ot->poll= WM_operator_winactive;
RNA_def_enum(ot->srna, "type", prop_type_items, 0, "Type", ""); 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 @@ void wm_operatortype_init(void)
WM_operatortype_append(WM_OT_jobs_timer); WM_operatortype_append(WM_OT_jobs_timer);
WM_operatortype_append(WM_OT_save_as_mainfile); WM_operatortype_append(WM_OT_save_as_mainfile);
WM_operatortype_append(WM_OT_save_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_debug_menu);
WM_operatortype_append(WM_OT_search_menu); WM_operatortype_append(WM_OT_search_menu);
} }
@ -2127,7 +2154,7 @@ void wm_window_keymap(wmWindowManager *wm)
WM_keymap_add_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
/* debug/testing */ /* 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_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0); WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0);