-
-
Save MasterDuke17/2dac190140c56447eeb175b58151f8b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/core/instance.h b/src/core/instance.h | |
index 7c2028e5a..ae901814c 100644 | |
--- a/src/core/instance.h | |
+++ b/src/core/instance.h | |
@@ -503,6 +503,9 @@ struct MVMInstance { | |
FILE *coverage_log_fh; | |
MVMuint32 coverage_control; | |
+ /* The time it takes to run the profiler instrumentation. */ | |
+ MVMuint64 profiling_overhead; | |
+ | |
/************************************************************************ | |
* Debugging | |
************************************************************************/ | |
diff --git a/src/profiler/instrument.c b/src/profiler/instrument.c | |
index aa6950209..86b49765e 100644 | |
--- a/src/profiler/instrument.c | |
+++ b/src/profiler/instrument.c | |
@@ -390,19 +390,34 @@ static void bind_extra_info(MVMThreadContext *tc, MVMObject *storage, MVMString | |
static MVMObject * dump_call_graph_node(MVMThreadContext *tc, ProfDumpStrs *pds, const MVMProfileCallNode *pcn, MVMObject *types_array); | |
static MVMObject * dump_call_graph_node_loop(ProfTcPdsStruct *tcpds, const MVMProfileCallNode *pcn) { | |
MVMuint32 i; | |
+ MVMuint64 exclusive_time = pcn->total_time; | |
+ MVMuint64 overhead = pcn->total_entries * tcpds->tc->instance->profiling_overhead; | |
MVMObject *node_hash; | |
+ if (exclusive_time - overhead > exclusive_time) | |
+ exclusive_time = 0; | |
+ else | |
+ exclusive_time -= overhead; | |
+ | |
node_hash = dump_call_graph_node(tcpds->tc, tcpds->pds, pcn, tcpds->types_array); | |
/* Visit successors in the call graph, dumping them and working out the | |
* exclusive time. */ | |
if (pcn->num_succ) { | |
- MVMObject *callees = new_array(tcpds->tc); | |
- MVMuint64 exclusive_time = pcn->total_time; | |
+ MVMObject *callees = new_array(tcpds->tc); | |
for (i = 0; i < pcn->num_succ; i++) { | |
+ MVMuint64 succ_exclusive_time = pcn->succ[i]->total_time; | |
+ MVMuint64 succ_overhead = pcn->succ[i]->total_entries * tcpds->tc->instance->profiling_overhead; | |
+ | |
MVM_repr_push_o(tcpds->tc, callees, | |
dump_call_graph_node_loop(tcpds, pcn->succ[i])); | |
- exclusive_time -= pcn->succ[i]->total_time; | |
+ | |
+ if (succ_exclusive_time - succ_overhead > succ_exclusive_time) | |
+ succ_exclusive_time = 0; | |
+ else | |
+ succ_exclusive_time -= succ_overhead; | |
+ | |
+ exclusive_time -= succ_exclusive_time; | |
} | |
MVM_repr_bind_key_o(tcpds->tc, node_hash, tcpds->pds->exclusive_time, | |
box_i(tcpds->tc, exclusive_time / 1000)); | |
@@ -410,7 +425,7 @@ static MVMObject * dump_call_graph_node_loop(ProfTcPdsStruct *tcpds, const MVMPr | |
} | |
else { | |
MVM_repr_bind_key_o(tcpds->tc, node_hash, tcpds->pds->exclusive_time, | |
- box_i(tcpds->tc, pcn->total_time / 1000)); | |
+ box_i(tcpds->tc, exclusive_time / 1000)); | |
} | |
return node_hash; | |
diff --git a/src/profiler/profile.c b/src/profiler/profile.c | |
index c62ea32e1..743c18f91 100644 | |
--- a/src/profiler/profile.c | |
+++ b/src/profiler/profile.c | |
@@ -8,8 +8,31 @@ void MVM_profile_start(MVMThreadContext *tc, MVMObject *config) { | |
if (MVM_repr_exists_key(tc, config, tc->instance->str_consts.kind)) { | |
MVMString *kind = MVM_repr_get_str(tc, | |
MVM_repr_at_key_o(tc, config, tc->instance->str_consts.kind)); | |
- if (MVM_string_equal(tc, kind, tc->instance->str_consts.instrumented)) | |
+ if (MVM_string_equal(tc, kind, tc->instance->str_consts.instrumented)) { | |
+ MVMuint64 s, e; | |
MVM_profile_instrumented_start(tc, config); | |
+ | |
+ s = uv_hrtime(); | |
+ for (int i = 0; i < 1000; i++) { | |
+ MVM_profile_log_enter(tc, tc->cur_frame->static_info, MVM_PROFILE_ENTER_NORMAL); | |
+ MVM_profile_log_exit(tc); | |
+ } | |
+ e = uv_hrtime(); | |
+ tc->instance->profiling_overhead = (MVMuint64) (e - s) / 1000; | |
+ | |
+ /* Disable profiling. */ | |
+ uv_mutex_lock(&(tc->instance->mutex_spesh_sync)); | |
+ while (tc->instance->spesh_working != 0) | |
+ uv_cond_wait(&(tc->instance->cond_spesh_sync), &(tc->instance->mutex_spesh_sync)); | |
+ tc->instance->profiling = 0; | |
+ MVM_free(tc->prof_data->collected_data); | |
+ tc->prof_data->collected_data = NULL; | |
+ MVM_free(tc->prof_data); | |
+ tc->prof_data = NULL; | |
+ uv_mutex_unlock(&(tc->instance->mutex_spesh_sync)); | |
+ | |
+ MVM_profile_instrumented_start(tc, config); | |
+ } | |
else if (MVM_string_equal(tc, kind, tc->instance->str_consts.heap)) | |
MVM_profile_heap_start(tc, config); | |
else |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment