Skip to content

Commit

Permalink
Release 0.4.3, profiling branch.
Browse files Browse the repository at this point in the history
    (### see comments in profile.c)
    (Jan-2-2009: added memset calls to zero out profiling mallocs)
  • Loading branch information
Andrew Plotkin committed Mar 22, 2009
1 parent a8831a6 commit c705ca6
Show file tree
Hide file tree
Showing 8 changed files with 793 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -31,7 +31,7 @@ CFLAGS = $(OPTIONS) -I$(GLKINCLUDEDIR)
LIBS = -L$(GLKLIBDIR) $(GLKLIB) $(LINKLIBS) LIBS = -L$(GLKLIBDIR) $(GLKLIB) $(LINKLIBS)


OBJS = main.o files.o vm.o exec.o funcs.o operand.o string.o glkop.o \ OBJS = main.o files.o vm.o exec.o funcs.o operand.o string.o glkop.o \
heap.o serial.o search.o gestalt.o osdepend.o heap.o serial.o search.o gestalt.o osdepend.o profile.o


all: glulxe all: glulxe


Expand Down
6 changes: 5 additions & 1 deletion README
@@ -1,5 +1,5 @@
Glulxe: the Glulx VM interpreter Glulxe: the Glulx VM interpreter
Version 0.4.3 Version 0.4.3 PROFILING


Designed by Andrew Plotkin <erkyrath@eblong.com> Designed by Andrew Plotkin <erkyrath@eblong.com>
http://eblong.com/zarf/glulx/index.html http://eblong.com/zarf/glulx/index.html
Expand Down Expand Up @@ -32,6 +32,10 @@ Ditto for Windows, using "winstart.c".


* Version * Version


PROFILING:
(### see comments in profile.c)
(Jan-2-2009: added memset calls to zero out profiling mallocs)

0.4.3: 0.4.3:
Verify the presence of Unicode calls in the Glk library at runtime. Verify the presence of Unicode calls in the Glk library at runtime.
(Thanks Simon Baldwin.) (Thanks Simon Baldwin.)
Expand Down
15 changes: 15 additions & 0 deletions exec.c
Expand Up @@ -24,6 +24,7 @@ void execute_loop()


while (!done_executing) { while (!done_executing) {


profile_tick();
/* Do OS-specific processing, if appropriate. */ /* Do OS-specific processing, if appropriate. */
glk_tick(); glk_tick();


Expand Down Expand Up @@ -322,6 +323,7 @@ void execute_loop()
goto PerformJump; goto PerformJump;
break; break;
case op_throw: case op_throw:
profile_fail("throw");
value = inst.value[0]; value = inst.value[0];
stackptr = inst.value[1]; stackptr = inst.value[1];
pop_callstub(value); pop_callstub(value);
Expand Down Expand Up @@ -496,19 +498,27 @@ void execute_loop()
break; break;


case op_streamchar: case op_streamchar:
profile_in(2);
value = inst.value[0] & 0xFF; value = inst.value[0] & 0xFF;
(*stream_char_handler)(value); (*stream_char_handler)(value);
profile_out();
break; break;
case op_streamunichar: case op_streamunichar:
profile_in(2);
value = inst.value[0]; value = inst.value[0];
(*stream_unichar_handler)(value); (*stream_unichar_handler)(value);
profile_out();
break; break;
case op_streamnum: case op_streamnum:
profile_in(2);
vals0 = inst.value[0]; vals0 = inst.value[0];
stream_num(vals0, FALSE, 0); stream_num(vals0, FALSE, 0);
profile_out();
break; break;
case op_streamstr: case op_streamstr:
profile_in(2);
stream_string(inst.value[0], 0, 0); stream_string(inst.value[0], 0, 0);
profile_out();
break; break;


default: default:
Expand Down Expand Up @@ -580,10 +590,12 @@ void execute_loop()
break; break;


case op_glk: case op_glk:
profile_in(1);
value = inst.value[1]; value = inst.value[1];
arglist = pop_arguments(value, 0); arglist = pop_arguments(value, 0);
val0 = perform_glk(inst.value[0], value, arglist); val0 = perform_glk(inst.value[0], value, arglist);
store_operand(inst.desttype, inst.value[2], val0); store_operand(inst.desttype, inst.value[2], val0);
profile_out();
break; break;


case op_random: case op_random:
Expand All @@ -606,6 +618,7 @@ void execute_loop()
break; break;


case op_restart: case op_restart:
profile_fail("restart");
vm_restart(); vm_restart();
break; break;


Expand All @@ -627,6 +640,7 @@ void execute_loop()
break; break;


case op_restore: case op_restore:
profile_fail("restore");
value = perform_restore(find_stream_by_id(inst.value[0])); value = perform_restore(find_stream_by_id(inst.value[0]));
if (value == 0) { if (value == 0) {
/* We've succeeded, and the stack now contains the callstub /* We've succeeded, and the stack now contains the callstub
Expand All @@ -648,6 +662,7 @@ void execute_loop()
break; break;


case op_restoreundo: case op_restoreundo:
profile_fail("restoreundo");
value = perform_restoreundo(); value = perform_restoreundo();
if (value == 0) { if (value == 0) {
/* We've succeeded, and the stack now contains the callstub /* We've succeeded, and the stack now contains the callstub
Expand Down
3 changes: 3 additions & 0 deletions funcs.c
Expand Up @@ -19,6 +19,8 @@ void enter_function(glui32 addr, glui32 argc, glui32 *argv)
int functype; int functype;
glui32 modeaddr, opaddr, val; glui32 modeaddr, opaddr, val;
int loctype, locnum; int loctype, locnum;

profile_in(addr);


/* Check the Glulx type identifier byte. */ /* Check the Glulx type identifier byte. */
functype = Mem1(addr); functype = Mem1(addr);
Expand Down Expand Up @@ -179,6 +181,7 @@ void enter_function(glui32 addr, glui32 argc, glui32 *argv)
void leave_function() void leave_function()
{ {
stackptr = frameptr; stackptr = frameptr;
profile_out();
} }


/* push_callstub(): /* push_callstub():
Expand Down
9 changes: 9 additions & 0 deletions glulxe.h
Expand Up @@ -238,4 +238,13 @@ extern int init_dispatch(void);
extern glui32 perform_glk(glui32 funcnum, glui32 numargs, glui32 *arglist); extern glui32 perform_glk(glui32 funcnum, glui32 numargs, glui32 *arglist);
extern strid_t find_stream_by_id(glui32 objid); extern strid_t find_stream_by_id(glui32 objid);


/* profile.c */
extern glui32 profile_opcount;
#define profile_tick() (profile_opcount++)
extern int init_profile(void);
extern void profile_in(glui32 addr);
extern void profile_out(void);
extern void profile_fail(char *reason);
extern void profile_quit(void);

#endif /* _GLULXE_H */ #endif /* _GLULXE_H */
4 changes: 4 additions & 0 deletions main.c
Expand Up @@ -36,11 +36,15 @@ void glk_main()
if (!init_dispatch()) { if (!init_dispatch()) {
return; return;
} }
if (!init_profile()) {
return;
}


setup_vm(); setup_vm();
execute_loop(); execute_loop();
finalize_vm(); finalize_vm();


profile_quit();
glk_exit(); glk_exit();
} }


Expand Down

0 comments on commit c705ca6

Please sign in to comment.