Permalink
Browse files

only call rdtsc when switching functions, fix off-by-one error, also …

…check debug section for file/line info
  • Loading branch information...
1 parent a5909f0 commit bdbfc213e5927f1954a353c63deea35dc98d6f79 @mlschroe mlschroe committed Sep 6, 2011
Showing with 77 additions and 74 deletions.
  1. +0 −2 frontend/parrot/main.c
  2. +0 −2 frontend/parrot2/main.c
  3. +0 −4 include/parrot/api.h
  4. +7 −7 include/parrot/runcore_subprof.h
  5. +1 −0 src/embed/api.c
  6. +0 −10 src/embed/bytecode.c
  7. +69 −49 src/runcore/subprof.c
View
@@ -227,8 +227,6 @@ main(int argc, const char *argv[])
show_last_error_and_exit(interp);
}
- Parrot_api_dump_profile_data(interp);
-
/* Clean-up after ourselves */
Parrot_api_destroy_interpreter(interp);
exit(EXIT_SUCCESS);
View
@@ -176,8 +176,6 @@ main(int argc, const char *argv[])
&& Parrot_api_run_bytecode(interp, bytecodepmc, sysargs, pirargs)))
show_last_error_and_exit(interp);
- Parrot_api_dump_profile_data(interp);
-
/* Clean-up after ourselves */
Parrot_api_destroy_interpreter(interp);
exit(EXIT_SUCCESS);
View
@@ -284,9 +284,6 @@ Parrot_Int Parrot_api_disassemble_bytecode(
Parrot_Int opts);
PARROT_API
-void Parrot_api_dump_profile_data (Parrot_PMC interp_pmc);
-
-PARROT_API
Parrot_Int Parrot_api_load_bytecode_bytes(
Parrot_PMC interp_pmc,
ARGIN(const unsigned char * const pbc),
@@ -336,7 +333,6 @@ Parrot_Int Parrot_api_write_bytecode_to_file(
#define ASSERT_ARGS_Parrot_api_disassemble_bytecode \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_Parrot_api_dump_profile_data __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_api_load_bytecode_bytes \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(pbc) \
@@ -52,20 +52,20 @@ struct subprofile {
uint64_t callerticks;
};
-subprofile *subprofilehash[32768];
+static int have_profile_data;
+
+static subprofile *subprofilehash[32768];
static PMC *cursubpmc;
static PMC *curctx;
static subprofile *cursp;
-uint64_t opstart;
+static uint64_t opstart;
-uint64_t *tickadd;
-uint64_t *tickadd2;
-uint64_t starttick;
+static uint64_t *tickadd;
+static uint64_t *tickadd2;
+static uint64_t starttick;
-unsigned int totalops;
-uint64_t totalticks;
/* HEADERIZER BEGIN: src/runcore/subprof.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
View
@@ -314,6 +314,7 @@ Parrot_api_destroy_interpreter(Parrot_PMC interp_pmc)
if (_oldtop == NULL)
interp->lo_var_ptr = &_oldtop;
interp->api_jmp_buf = &env;
+ dump_profile_data(interp);
Parrot_destroy(interp);
Parrot_x_exit(interp, 0);
/* Never reached, x_exit calls longjmp */
View
@@ -164,16 +164,6 @@ Parrot_api_run_bytecode(Parrot_PMC interp_pmc, Parrot_PMC pbc,
EMBED_API_CALLOUT(interp_pmc, interp)
}
-PARROT_API
-void
-Parrot_api_dump_profile_data (Parrot_PMC interp_pmc)
-{
- EMBED_API_CALLIN(interp_pmc, interp)
- dump_profile_data(interp);
- EMBED_API_CALLOUT(interp_pmc, interp)
-}
-
-
/*
=item C<Parrot_Int Parrot_api_disassemble_bytecode(Parrot_PMC interp_pmc,
View
@@ -101,6 +101,8 @@ sub2subprofile(PARROT_INTERP, PMC *ctx, PMC *subpmc)
sp->subattrs = subattrs;
sp->subpmc = subpmc;
*spp = sp;
+ if (!have_profile_data)
+ have_profile_data = 1;
}
lastsp = sp;
return sp;
@@ -265,44 +267,54 @@ printspname(PARROT_INTERP, subprofile *sp)
static void
printspline(PARROT_INTERP, subprofile *sp)
{
- PMC * annot;
- PackFile_Annotations *ann;
- PackFile_Annotations_Key *key;
- STRING *line_str = Parrot_str_new_constant(interp, "line");
int i;
- if (!sp->subattrs || !sp->subattrs->seg || !sp->subattrs->seg->annotations)
+ if (!sp->subattrs || !sp->subattrs->seg)
return;
- ann = sp->subattrs->seg->annotations;
- /* search for the first line annotation in our sub */
- for (i = 0; i < ann->num_keys; i++) {
- STRING * const test_key = ann->code->const_table->str.constants[ann->keys[i].name];
- if (STRING_equal(interp, test_key, line_str))
- break;
- }
- if (i < ann->num_keys) {
- /* ok, found the line key, now search for the sub */
- unsigned int j;
- key = ann->keys + i;
- for (j = key->start; j < key->start + key->len; j++) {
- if ((size_t)ann->base.data[j * 2 + ANN_ENTRY_OFF] < sp->subattrs->start_offs)
- continue;
- if ((size_t)ann->base.data[j * 2 + ANN_ENTRY_OFF] >= sp->subattrs->end_offs)
- continue;
- break;
+ /* try HLL annotations */
+ if (sp->subattrs->seg->annotations) {
+ PackFile_Annotations *ann = sp->subattrs->seg->annotations;
+ PackFile_Annotations_Key *key;
+ STRING *line_str = Parrot_str_new_constant(interp, "line");
+
+ /* search for the first line annotation in our sub */
+ for (i = 0; i < ann->num_keys; i++) {
+ STRING * const test_key = ann->code->const_table->str.constants[ann->keys[i].name];
+ if (STRING_equal(interp, test_key, line_str))
+ break;
+
}
- if (j < key->start + key->len) {
- /* found it! */
- INTVAL line = ann->base.data[j * 2 + ANN_ENTRY_VAL];
- /* need +1, sigh */
- PMC *pfile = PackFile_Annotations_lookup(interp, ann, ann->base.data[j * 2 + ANN_ENTRY_OFF] + 1, Parrot_str_new_constant(interp, "file"));
- if (PMC_IS_NULL(pfile))
- fprintf(stderr, "???:%d", (int)line);
- else
- fprintf(stderr, "%s:%d", str2cs(interp, VTABLE_get_string(interp, pfile)), (int)line);
+ if (i < ann->num_keys) {
+ /* ok, found the line key, now search for the sub */
+ unsigned int j;
+ key = ann->keys + i;
+ for (j = key->start; j < key->start + key->len; j++) {
+ if ((size_t)ann->base.data[j * 2 + ANN_ENTRY_OFF] < sp->subattrs->start_offs)
+ continue;
+ if ((size_t)ann->base.data[j * 2 + ANN_ENTRY_OFF] >= sp->subattrs->end_offs)
+ continue;
+ break;
+ }
+ if (j < key->start + key->len) {
+ /* found it! */
+ INTVAL line = ann->base.data[j * 2 + ANN_ENTRY_VAL];
+ /* need +1, sigh */
+ PMC *pfile = PackFile_Annotations_lookup(interp, ann, ann->base.data[j * 2 + ANN_ENTRY_OFF] + 1, Parrot_str_new_constant(interp, "file"));
+ if (PMC_IS_NULL(pfile))
+ fprintf(stderr, "???:%d", (int)line);
+ else
+ fprintf(stderr, "%s:%d", str2cs(interp, VTABLE_get_string(interp, pfile)), (int)line);
+ return;
+ }
}
}
+ /* try the debug section */
+ if (sp->subattrs->seg->debugs) {
+ STRING *file = Parrot_sub_get_filename_from_pc(interp, sp->subpmc, sp->subattrs->seg->base.data + sp->subattrs->start_offs);
+ INTVAL line = Parrot_sub_get_line_from_pc(interp, sp->subpmc, sp->subattrs->seg->base.data + sp->subattrs->start_offs);
+ fprintf(stderr, "%s:%d", str2cs(interp, file), (int)line);
+ }
}
/*
@@ -323,13 +335,27 @@ dump_profile_data(PARROT_INTERP)
int h;
size_t off;
- if (!totalops)
+ unsigned int totalops = 0;
+ uint64_t totalticks = 0;
+
+ if (!have_profile_data)
return;
+
+ for (h = 0; h < 32768; h++) {
+ subprofile *hsp;
+ for (hsp = subprofilehash[h]; hsp; hsp = hsp->hnext) {
+ subprofile *sp;
+ for (sp = hsp; sp; sp = sp->rnext) {
+ totalops += sp->ops;
+ totalticks += sp->ticks;
+ }
+ }
+ }
fprintf(stderr, "events: ops ticks\n");
fprintf(stderr, "summary: %d %lld\n", totalops, totalticks);
finishcallchain(interp); /* just in case... */
- for (h = 0; h < 32767; h++) {
+ for (h = 0; h < 32768; h++) {
subprofile *hsp;
for (hsp = subprofilehash[h]; hsp; hsp = hsp->hnext) {
subprofile *sp;
@@ -386,28 +412,23 @@ main entry point for this pile, does all accounting for a single op
void
profile(PARROT_INTERP, PMC *ctx, opcode_t *pc)
{
- PMC *subpmc;
- PackFile_ByteCode *code = interp->code;
+ PMC *subpmc = ((Parrot_Context *)PMC_data_typed(ctx, Parrot_Context*))->current_sub;
subprofile *sp;
- uint64_t tick;
-
- /* finish old ticks */
- tick = rdtsc();
- if (tickadd) {
- uint64_t tickdiff = tick - starttick;
- *tickadd += tickdiff;
- *tickadd2 += tickdiff;
- totalticks += tickdiff;
- starttick = tick;
- }
-
- subpmc = Parrot_pcc_get_sub(interp, ctx);
if (PMC_IS_NULL(subpmc))
return;
if (subpmc != cursubpmc || ctx != curctx) {
/* context changed! either called new sub or returned from sub */
+
+ /* finish old ticks */
+ uint64_t tick = rdtsc();
+ if (tickadd) {
+ uint64_t tickdiff = tick - starttick;
+ *tickadd += tickdiff;
+ *tickadd2 += tickdiff;
+ }
+
if (cursp) {
/* optimize common cases */
/* did we just return? */
@@ -447,7 +468,6 @@ profile(PARROT_INTERP, PMC *ctx, opcode_t *pc)
sp = cursp;
sp->ops++;
sp->callerops++; /* to distribute */
- totalops++;
}
/*

0 comments on commit bdbfc21

Please sign in to comment.