Index: runtime/vm/source_report.cc |
diff --git a/runtime/vm/source_report.cc b/runtime/vm/source_report.cc |
index bbd35ab83e52395f7427e1e11bbcecf224416e26..9dadff1dc3d81e154f6ab66c03f172365be035c8 100644 |
--- a/runtime/vm/source_report.cc |
+++ b/runtime/vm/source_report.cc |
@@ -5,8 +5,11 @@ |
#include "vm/source_report.h" |
#include "vm/compiler.h" |
+#include "vm/isolate.h" |
#include "vm/object.h" |
#include "vm/object_store.h" |
+#include "vm/profiler.h" |
+#include "vm/profiler_service.h" |
namespace dart { |
@@ -17,6 +20,7 @@ SourceReport::SourceReport(intptr_t report_set, CompileMode compile_mode) |
script_(NULL), |
start_pos_(TokenPosition::kNoSource), |
end_pos_(TokenPosition::kNoSource), |
+ profile_(Isolate::Current()), |
next_script_index_(0) { |
} |
@@ -32,6 +36,11 @@ void SourceReport::Init(Thread* thread, |
script_table_entries_.Clear(); |
script_table_.Clear(); |
next_script_index_ = 0; |
+ if (IsReportRequested(kProfile)) { |
+ SampleFilter samplesForIsolate(Isolate::Current(), -1, -1); |
turnidge
2016/03/11 18:31:57
Is thread_ the current thread? If so, can we use
Cutch
2016/03/11 20:20:00
Done.
|
+ // Build the profile. |
+ profile_.Build(thread, &samplesForIsolate, Profile::kNoTags); |
+ } |
} |
@@ -250,6 +259,53 @@ void SourceReport::PrintPossibleBreakpointsData(JSONObject* jsobj, |
} |
+void SourceReport::PrintProfileData(JSONObject* jsobj, |
+ ProfileFunction* profile_function) { |
+ ASSERT(profile_function != NULL); |
+ ASSERT(profile_function->NumSourcePositions() > 0); |
+ |
+ { |
+ JSONObject profile(jsobj, "profileTicks"); |
+ |
+ // Positions. |
+ { |
+ JSONArray positions(&profile, "positions"); |
+ for (intptr_t i = 0; i < profile_function->NumSourcePositions(); i++) { |
+ const ProfileFunctionSourcePosition& position = |
+ profile_function->GetSourcePosition(i); |
+ if (position.token_pos().IsSourcePosition() && |
+ !position.token_pos().IsNoSource()) { |
+ // Add as an integer. |
+ positions.AddValue(position.token_pos().Pos()); |
+ } else { |
+ // Add as a string. |
+ positions.AddValue(position.token_pos().ToCString()); |
+ } |
+ } |
+ } |
+ |
+ // Exclusive ticks. |
+ { |
+ JSONArray exclusiveTicks(&profile, "exclusiveTicks"); |
+ for (intptr_t i = 0; i < profile_function->NumSourcePositions(); i++) { |
+ const ProfileFunctionSourcePosition& position = |
+ profile_function->GetSourcePosition(i); |
+ exclusiveTicks.AddValue(position.exclusive_ticks()); |
+ } |
+ } |
+ // Inclusive ticks. |
+ { |
+ JSONArray inclusiveTicks(&profile, "inclusiveTicks"); |
+ for (intptr_t i = 0; i < profile_function->NumSourcePositions(); i++) { |
+ const ProfileFunctionSourcePosition& position = |
+ profile_function->GetSourcePosition(i); |
+ inclusiveTicks.AddValue(position.inclusive_ticks()); |
+ } |
+ } |
+ } |
+} |
+ |
+ |
void SourceReport::PrintScriptTable(JSONArray* scripts) { |
for (int i = 0; i < script_table_entries_.length(); i++) { |
const Script* script = script_table_entries_[i].script; |
@@ -311,6 +367,13 @@ void SourceReport::VisitFunction(JSONArray* jsarr, const Function& func) { |
if (IsReportRequested(kPossibleBreakpoints)) { |
PrintPossibleBreakpointsData(&range, func, code); |
} |
+ if (IsReportRequested(kProfile)) { |
+ ProfileFunction* profile_function = profile_.FindFunction(func); |
+ if ((profile_function != NULL) && |
+ (profile_function->NumSourcePositions() > 0)) { |
+ PrintProfileData(&range, profile_function); |
+ } |
+ } |
} |