Skip to content

Commit

Permalink
Activity log can now be started and dumped from Scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
feeley committed Apr 28, 2016
1 parent 85bade1 commit 0201a23
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 27 deletions.
21 changes: 21 additions & 0 deletions include/gambit.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -7728,6 +7728,7 @@ typedef struct ___vmstate_actlog
___MUTEX mut;
___actlog_activity *activities;
int nb_activities;
___BOOL auto_dump;
} ___vmstate_actlog;

typedef struct ___pstate_actlog
Expand Down Expand Up @@ -9614,6 +9615,16 @@ typedef struct ___global_state_struct
void (*___actlog_end_pstate)
___P((___processor_state ___ps),
());
void (*___actlog_start)
___P((___processor_state ___ps),
());
void (*___actlog_stop)
___P((___processor_state ___ps),
());
void (*___actlog_dump)
___P((___virtual_machine_state ___vms,
char *filename),
());
#endif
void (*___raise_interrupt_pstate)
___P((___processor_state ___ps,
Expand Down Expand Up @@ -10912,6 +10923,16 @@ ___IMP_FUNC(void,___actlog_begin_pstate)
___IMP_FUNC(void,___actlog_end_pstate)
___P((___processor_state ___ps),
());
___IMP_FUNC(void,___actlog_start)
___P((___processor_state ___ps),
());
___IMP_FUNC(void,___actlog_stop)
___P((___processor_state ___ps),
());
___IMP_FUNC(void,___actlog_dump)
___P((___virtual_machine_state ___vms,
char *filename),
());
#endif
___IMP_FUNC(void,___raise_interrupt_pstate)
___P((___processor_state ___ps,
Expand Down
2 changes: 1 addition & 1 deletion include/stamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*/

#define ___STAMP_YMD 20160428
#define ___STAMP_HMS 23242
#define ___STAMP_HMS 190735
34 changes: 34 additions & 0 deletions lib/_kernel.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3981,6 +3981,40 @@ end-of-code

;;;----------------------------------------------------------------------------

;;; Activity log operations.

(define-prim (##actlog-start)
((c-lambda ()
void
#<<end-of-code
#ifdef ___ACTIVITY_LOG
___actlog_start (___ps);
#endif
end-of-code
)))

(define-prim (##actlog-stop)
((c-lambda ()
void
#<<end-of-code
#ifdef ___ACTIVITY_LOG
___actlog_stop (___ps);
#endif
end-of-code
)))

(define-prim (##actlog-dump #!optional (filename #f))
((c-lambda (char-string)
void
#<<end-of-code
#ifdef ___ACTIVITY_LOG
___actlog_dump (___ps, ___arg1);
#endif
end-of-code
) filename))

;;;----------------------------------------------------------------------------

;;; Error message formatting.

(define-prim ##format-filepos
Expand Down
32 changes: 21 additions & 11 deletions lib/actlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ ___processor_state ___ps;)

___ps->actlog.transitions = t;
___ps->actlog.stack = s;
___ps->actlog.sp = 0;

___actlog_start_pstate (___ps);

Expand Down Expand Up @@ -103,6 +102,7 @@ ___virtual_machine_state ___vms;)
___MUTEX_INIT(___vms->actlog.mut);
___vms->actlog.activities = ptr;
___vms->actlog.nb_activities = 0;
___vms->actlog.auto_dump = 1;

#endif

Expand All @@ -117,9 +117,11 @@ ___virtual_machine_state ___vms;)
{
#ifdef ___ACTIVITY_LOG

/* TODO: allow generation of activity log at any moment */
___actlog_stop_pstate (&___vms->pstate[0]);
___actlog_dump (___vms);
if (___vms->actlog.auto_dump)
{
___actlog_stop_pstate (&___vms->pstate[0]);
___actlog_dump (___vms, NULL);
}

if (___vms->actlog.activities != NULL)
{
Expand Down Expand Up @@ -244,7 +246,8 @@ ___U32 color;)
name,
color);

___ps->actlog.stack[___ps->actlog.sp++] = last->type;
if (___ps->actlog.sp < ___ACTLOG_STACK_SIZE)
___ps->actlog.stack[___ps->actlog.sp++] = last->type;

___ps->actlog.last = --last;

Expand All @@ -269,7 +272,8 @@ ___processor_state ___ps;)
{
___ps->actlog.last = --last;

last->type = ___ps->actlog.stack[--___ps->actlog.sp];
if (___ps->actlog.sp > 0)
last->type = ___ps->actlog.stack[--___ps->actlog.sp];
last->stamp = ___time_get_monotonic_time ();
}

Expand All @@ -287,6 +291,7 @@ ___processor_state ___ps;)
___U16 type =___ACTIVITY_START_STOP;

___ps->actlog.last = ___ps->actlog.transitions + ___MAX_NB_ACTLOG_TRANSITIONS;
___ps->actlog.sp = 0;

___actlog_add_pstate (___ps, &type, NULL, 0);

Expand Down Expand Up @@ -417,20 +422,25 @@ ___HIDDEN ___U32 distinct_colors[] = {
#endif


void ___actlog_dump
___P((___virtual_machine_state ___vms),
(___vms)
___virtual_machine_state ___vms;)
___EXP_FUNC(void,___actlog_dump)
___P((___virtual_machine_state ___vms,
char *filename),
(___vms,
filename)
___virtual_machine_state ___vms;
char *filename;)
{
#ifdef ___ACTIVITY_LOG

int i;
int c = 0;
___FILE *out = ___fopen ("gambit.actlog", "w");
___FILE *out = ___fopen (filename == NULL ? "gambit.actlog" : filename, "w");

if (out == NULL)
return;

___vms->actlog.auto_dump = 0;

write_U64 (out, ___time_get_monotonic_time_frequency ());

write_U32 (out, ___vms->actlog.nb_activities);
Expand Down
3 changes: 2 additions & 1 deletion lib/actlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ extern void ___actlog_stop_pstate
());

extern void ___actlog_dump
___P((___virtual_machine_state ___vms),
___P((___virtual_machine_state ___vms,
char *filename),
());

/*---------------------------------------------------------------------------*/
Expand Down
31 changes: 17 additions & 14 deletions lib/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,35 +826,29 @@ ___SIZE_TS requested_words_still;)
}


___EXP_FUNC(___SCMOBJ,___actlog_start)
___P((___PSDNC),
(___PSVNC)
___PSDKR)
___EXP_FUNC(void,___actlog_start)
___P((___processor_state ___ps),
(___ps)
___processor_state ___ps;)
{
___PSGET
___sync_op_struct sop;

sop.op = OP_ACTLOG_START;

on_all_processors (___PSP &sop);

return ___FIX(___NO_ERR);
}


___EXP_FUNC(___SCMOBJ,___actlog_stop)
___P((___PSDNC),
(___PSVNC)
___PSDKR)
___EXP_FUNC(void,___actlog_stop)
___P((___processor_state ___ps),
(___ps)
___processor_state ___ps;)
{
___PSGET
___sync_op_struct sop;

sop.op = OP_ACTLOG_STOP;

on_all_processors (___PSP &sop);

return ___FIX(___NO_ERR);
}


Expand Down Expand Up @@ -3981,6 +3975,15 @@ ___HIDDEN void setup_dynamic_linking ___PVOID
___GSTATE->___actlog_end_pstate
= ___actlog_end_pstate;

___GSTATE->___actlog_start
= ___actlog_start;

___GSTATE->___actlog_stop
= ___actlog_stop;

___GSTATE->___actlog_dump
= ___actlog_dump;

#endif

___GSTATE->___raise_interrupt_pstate
Expand Down

0 comments on commit 0201a23

Please sign in to comment.