[svn:parrot] r40542 - in branches/pluggable_runcore: include/parrot src/runcore
cotto at svn.parrot.org
cotto at svn.parrot.org
Fri Aug 14 01:57:10 UTC 2009
Author: cotto
Date: Fri Aug 14 01:57:08 2009
New Revision: 40542
URL: https://trac.parrot.org/parrot/changeset/40542
Log:
[profiling] start putting runcore-specific data into a Parrot_profiling_runcore_t and using init/destroy
Modified:
branches/pluggable_runcore/include/parrot/runcore_api.h
branches/pluggable_runcore/src/runcore/cores.c
Modified: branches/pluggable_runcore/include/parrot/runcore_api.h
==============================================================================
--- branches/pluggable_runcore/include/parrot/runcore_api.h Fri Aug 14 01:24:23 2009 (r40541)
+++ branches/pluggable_runcore/include/parrot/runcore_api.h Fri Aug 14 01:57:08 2009 (r40542)
@@ -11,6 +11,8 @@
struct runcore_t;
typedef struct runcore_t Parrot_runcore_t;
+struct profiling_runcore_t;
+typedef struct profiling_runcore_t Parrot_profiling_runcore_t;
#include "parrot/parrot.h"
#include "parrot/op.h"
@@ -30,6 +32,19 @@
INTVAL flags;
};
+struct profiling_runcore_t {
+ STRING *name;
+ oplib_init_f opinit;
+ runcore_runops_fn_type runops;
+ runcore_destroy_fn_type destroy;
+ runcore_prepare_fn_type prepare_run;
+ INTVAL flags;
+
+ /* end of common members */
+ FILE *prof_fd;
+ INTVAL nesting_counter;
+};
+
typedef enum Parrot_runcore_flags {
RUNCORE_REENTRANT_FLAG = 1 << 0,
RUNCORE_FUNC_TABLE_FLAG = 1 << 1,
@@ -167,7 +182,7 @@
PARROT_CAN_RETURN_NULL
void * destroy_profiling_core(PARROT_INTERP,
- ARGIN(Parrot_runcore_t *runcore))
+ ARGIN(Parrot_profiling_runcore_t *runcore))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
Modified: branches/pluggable_runcore/src/runcore/cores.c
==============================================================================
--- branches/pluggable_runcore/src/runcore/cores.c Fri Aug 14 01:24:23 2009 (r40541)
+++ branches/pluggable_runcore/src/runcore/cores.c Fri Aug 14 01:57:08 2009 (r40542)
@@ -274,7 +274,7 @@
PARROT_CAN_RETURN_NULL
static void * init_profiling_core(PARROT_INTERP,
- ARGIN(Parrot_runcore_t *runcore),
+ ARGIN(Parrot_profiling_runcore_t *runcore),
ARGIN(opcode_t *pc))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
@@ -346,7 +346,7 @@
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static opcode_t * runops_profiling_core(PARROT_INTERP,
- ARGIN(Parrot_runcore_t *runcore),
+ ARGIN(Parrot_profiling_runcore_t *runcore),
ARGIN(opcode_t *pc))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
@@ -1020,8 +1020,8 @@
/*
-=item C<static void * init_profiling_core(PARROT_INTERP, Parrot_runcore_t
-*runcore, opcode_t *pc)>
+=item C<static void * init_profiling_core(PARROT_INTERP,
+Parrot_profiling_runcore_t *runcore, opcode_t *pc)>
Perform initialization for the profiling runcore.
@@ -1031,22 +1031,27 @@
PARROT_CAN_RETURN_NULL
static void *
-init_profiling_core(PARROT_INTERP, ARGIN(Parrot_runcore_t *runcore), ARGIN(opcode_t *pc))
+init_profiling_core(PARROT_INTERP, ARGIN(Parrot_profiling_runcore_t *runcore), ARGIN(opcode_t *pc))
{
ASSERT_ARGS(init_profiling_core)
runcore->runops = runops_profiling_core;
runcore->destroy = destroy_profiling_core;
- fprintf(stderr, "PROFILING INIT CALLED\n");
+ runcore->nesting_counter = 0;
+ runcore->prof_fd = fopen("parrot.pprof", "w");
+ if (!runcore->prof_fd) {
+ fprintf(stderr, "unable to open parrot_prof.out for writing");
+ exit(1);
+ }
return runops_profiling_core(interp, runcore, pc);
}
/*
-=item C<static opcode_t * runops_profiling_core(PARROT_INTERP, Parrot_runcore_t
-*runcore, opcode_t *pc)>
+=item C<static opcode_t * runops_profiling_core(PARROT_INTERP,
+Parrot_profiling_runcore_t *runcore, opcode_t *pc)>
Runs the Parrot operations starting at C<pc> until there are no more
operations, with tracing, bounds checking, and profiling enabled.
@@ -1058,7 +1063,7 @@
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static opcode_t *
-runops_profiling_core(PARROT_INTERP, ARGIN(Parrot_runcore_t *runcore), ARGIN(opcode_t *pc))
+runops_profiling_core(PARROT_INTERP, ARGIN(Parrot_profiling_runcore_t *runcore), ARGIN(opcode_t *pc))
{
ASSERT_ARGS(runops_profiling_core)
Parrot_Context_info prev_info, curr_info;
@@ -1069,26 +1074,14 @@
HUGEINTVAL op_time;
char unknown_sub[] = "(unknown sub)";
char unknown_file[] = "(unknown file)";
- static int interp_counter = 0;
- /* Hilarity ensues if an inner runloops opens and writes to a separate
- * FILE*, so use a simple static counter to ensure that the FILE* only gets
- * opened and closed once. */
- if (interp_counter == 0) {
- prof_fd = fopen("parrot.pprof", "w");
- if (!prof_fd) {
- fprintf(stderr, "unable to open parrot_prof.out for writing");
- exit(1);
- }
- }
-
- interp_counter++;
- fprintf(prof_fd, "#NEW RUNLOOP (%d)\n", interp_counter);
+ runcore->nesting_counter++;
+ fprintf(runcore->prof_fd, "#NEW RUNLOOP (%d)\n", runcore->nesting_counter);
prev_ctx = CONTEXT(interp);
Parrot_Context_get_info(interp, CONTEXT(interp), &curr_info);
- fprintf(prof_fd, "F:%s\n", curr_info.file->strstart);
- fprintf(prof_fd, "S:%s;%s\n",
+ fprintf(runcore->prof_fd, "F:%s\n", curr_info.file->strstart);
+ fprintf(runcore->prof_fd, "S:%s;%s\n",
VTABLE_get_string(interp, prev_ctx->current_namespace)->strstart,
curr_info.subname->strstart);
@@ -1133,9 +1126,9 @@
Parrot_Context_info info;
if (strcmp(file_preop, file_postop))
- fprintf(prof_fd, "F:%s\n", file_postop);
+ fprintf(runcore->prof_fd, "F:%s\n", file_postop);
if (strcmp(sub_preop, sub_postop))
- fprintf(prof_fd, "S:%s;%s\n",
+ fprintf(runcore->prof_fd, "S:%s;%s\n",
VTABLE_get_string(interp, prev_ctx->current_namespace)->strstart,
sub_postop);
@@ -1155,7 +1148,7 @@
Parrot_Context_get_info(interp, CONTEXT(interp), &info);
if (info.subname->strstart && strcmp(sub_postop, info.subname->strstart)) {
- fprintf(prof_fd, "%d:%lli:%s calls to %s\n",
+ fprintf(runcore->prof_fd, "%d:%lli:%s calls to %s\n",
curr_info.line, op_time,
(interp->op_info_table)[*prev_pc].name,
info.fullname->strstart);
@@ -1173,7 +1166,7 @@
Parrot_Context_get_info(interp, CONTEXT(interp), &info);
if (info.subname->strstart && strcmp(sub_postop, info.subname->strstart)) {
- fprintf(prof_fd, "%d:%lli:%s returns to %s\n",
+ fprintf(runcore->prof_fd, "%d:%lli:%s returns to %s\n",
curr_info.line, op_time,
(interp->op_info_table)[*prev_pc].name,
info.fullname->strstart);
@@ -1182,7 +1175,7 @@
/* intentional fallthrough if we're not in a new sub */
default:
- fprintf(prof_fd, "%d:%lli:%s\n",
+ fprintf(runcore->prof_fd, "%d:%lli:%s\n",
curr_info.line, op_time,
(interp->op_info_table)[*prev_pc].name);
}
@@ -1190,11 +1183,9 @@
}
}
- fprintf(prof_fd, "#END OF RUNLOOP (%d)\n", interp_counter);
- interp_counter--;
+ fprintf(runcore->prof_fd, "#END OF RUNLOOP (%d)\n", runcore->nesting_counter);
+ runcore->nesting_counter--;
- if (interp_counter == 0)
- fclose(prof_fd);
return pc;
}
@@ -1202,7 +1193,8 @@
/*
-=item C<void * destroy_profiling_core(PARROT_INTERP, Parrot_runcore_t *runcore)>
+=item C<void * destroy_profiling_core(PARROT_INTERP, Parrot_profiling_runcore_t
+*runcore)>
Perform initialization for the profiling runcore.
@@ -1212,11 +1204,11 @@
PARROT_CAN_RETURN_NULL
void *
-destroy_profiling_core(PARROT_INTERP, ARGIN(Parrot_runcore_t *runcore))
+destroy_profiling_core(PARROT_INTERP, ARGIN(Parrot_profiling_runcore_t *runcore))
{
ASSERT_ARGS(destroy_profiling_core)
- fprintf(stderr, "PROFILING DESTRUCTOR CALLED\n");
+ fclose(runcore->prof_fd);
return NULL;
}
More information about the parrot-commits
mailing list