OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_SOURCE_REPORT_H_ | 5 #ifndef VM_SOURCE_REPORT_H_ |
6 #define VM_SOURCE_REPORT_H_ | 6 #define VM_SOURCE_REPORT_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
10 #include "vm/hash_map.h" | 10 #include "vm/hash_map.h" |
11 #include "vm/object.h" | 11 #include "vm/object.h" |
| 12 #include "vm/profiler_service.h" |
12 #include "vm/token_position.h" | 13 #include "vm/token_position.h" |
13 | 14 |
14 namespace dart { | 15 namespace dart { |
15 | 16 |
16 // A SourceReport object is used to generate reports about the program | 17 // A SourceReport object is used to generate reports about the program |
17 // source code, with information associated with source token | 18 // source code, with information associated with source token |
18 // positions. There are multiple possible kinds of reports. | 19 // positions. There are multiple possible kinds of reports. |
19 class SourceReport { | 20 class SourceReport { |
20 public: | 21 public: |
21 enum ReportKind { | 22 enum ReportKind { |
22 kCallSites = 0x1, | 23 kCallSites = 0x1, |
23 kCoverage = 0x2, | 24 kCoverage = 0x2, |
24 kPossibleBreakpoints = 0x4, | 25 kPossibleBreakpoints = 0x4, |
| 26 kProfile = 0x8, |
25 }; | 27 }; |
26 | 28 |
27 enum CompileMode { | 29 enum CompileMode { |
28 kNoCompile, | 30 kNoCompile, |
29 kForceCompile | 31 kForceCompile |
30 }; | 32 }; |
31 | 33 |
32 // report_set is a bitvector indicating which reports to generate | 34 // report_set is a bitvector indicating which reports to generate |
33 // (e.g. kCallSites | kCoverage). | 35 // (e.g. kCallSites | kCoverage). |
34 explicit SourceReport(intptr_t report_set, | 36 explicit SourceReport(intptr_t report_set, |
35 CompileMode compile = kNoCompile); | 37 CompileMode compile = kNoCompile); |
36 | 38 |
37 // Generate a source report for (some subrange of) a script. | 39 // Generate a source report for (some subrange of) a script. |
38 // | 40 // |
39 // If script is null, then the report is generated for all scripts | 41 // If script is null, then the report is generated for all scripts |
40 // in the isolate. | 42 // in the isolate. |
41 void PrintJSON(JSONStream* js, const Script& script, | 43 void PrintJSON(JSONStream* js, const Script& script, |
42 TokenPosition start_pos = TokenPosition::kNoSource, | 44 TokenPosition start_pos = TokenPosition::kNoSource, |
43 TokenPosition end_pos = TokenPosition::kNoSource); | 45 TokenPosition end_pos = TokenPosition::kNoSource); |
44 | 46 |
45 private: | 47 private: |
46 void Init(Thread* thread, const Script* script, | 48 void Init(Thread* thread, const Script* script, |
47 TokenPosition start_pos, TokenPosition end_pos); | 49 TokenPosition start_pos, TokenPosition end_pos); |
48 | 50 |
49 Thread* thread() const { return thread_; } | 51 Thread* thread() const { return thread_; } |
50 Zone* zone() const { return thread_->zone(); } | 52 Zone* zone() const { return thread_->zone(); } |
| 53 Isolate* isolate() const { return thread_->isolate(); } |
51 | 54 |
52 bool IsReportRequested(ReportKind report_kind); | 55 bool IsReportRequested(ReportKind report_kind); |
53 bool ShouldSkipFunction(const Function& func); | 56 bool ShouldSkipFunction(const Function& func); |
54 intptr_t GetScriptIndex(const Script& script); | 57 intptr_t GetScriptIndex(const Script& script); |
55 bool ScriptIsLoadedByLibrary(const Script& script, const Library& lib); | 58 bool ScriptIsLoadedByLibrary(const Script& script, const Library& lib); |
56 | 59 |
57 void PrintCallSitesData(JSONObject* jsobj, | 60 void PrintCallSitesData(JSONObject* jsobj, |
58 const Function& func, const Code& code); | 61 const Function& func, const Code& code); |
59 void PrintCoverageData(JSONObject* jsobj, | 62 void PrintCoverageData(JSONObject* jsobj, |
60 const Function& func, const Code& code); | 63 const Function& func, const Code& code); |
61 void PrintPossibleBreakpointsData(JSONObject* jsobj, | 64 void PrintPossibleBreakpointsData(JSONObject* jsobj, |
62 const Function& func, const Code& code); | 65 const Function& func, const Code& code); |
| 66 void PrintProfileData(JSONObject* jsobj, ProfileFunction* profile_function); |
63 void PrintScriptTable(JSONArray* jsarr); | 67 void PrintScriptTable(JSONArray* jsarr); |
64 | 68 |
65 void VisitFunction(JSONArray* jsarr, const Function& func); | 69 void VisitFunction(JSONArray* jsarr, const Function& func); |
66 void VisitLibrary(JSONArray* jsarr, const Library& lib); | 70 void VisitLibrary(JSONArray* jsarr, const Library& lib); |
67 void VisitClosures(JSONArray* jsarr); | 71 void VisitClosures(JSONArray* jsarr); |
68 | 72 |
69 // An entry in the script table. | 73 // An entry in the script table. |
70 struct ScriptTableEntry { | 74 struct ScriptTableEntry { |
71 ScriptTableEntry() : key(NULL), index(-1), script(NULL) {} | 75 ScriptTableEntry() : key(NULL), index(-1), script(NULL) {} |
72 | 76 |
(...skipping 24 matching lines...) Expand all Loading... |
97 return kv->key->Equals(*key); | 101 return kv->key->Equals(*key); |
98 } | 102 } |
99 }; | 103 }; |
100 | 104 |
101 intptr_t report_set_; | 105 intptr_t report_set_; |
102 CompileMode compile_mode_; | 106 CompileMode compile_mode_; |
103 Thread* thread_; | 107 Thread* thread_; |
104 const Script* script_; | 108 const Script* script_; |
105 TokenPosition start_pos_; | 109 TokenPosition start_pos_; |
106 TokenPosition end_pos_; | 110 TokenPosition end_pos_; |
| 111 Profile profile_; |
107 GrowableArray<ScriptTableEntry> script_table_entries_; | 112 GrowableArray<ScriptTableEntry> script_table_entries_; |
108 DirectChainedHashMap<ScriptTableTrait> script_table_; | 113 DirectChainedHashMap<ScriptTableTrait> script_table_; |
109 intptr_t next_script_index_; | 114 intptr_t next_script_index_; |
110 }; | 115 }; |
111 | 116 |
112 } // namespace dart | 117 } // namespace dart |
113 | 118 |
114 #endif // VM_SOURCE_REPORT_H_ | 119 #endif // VM_SOURCE_REPORT_H_ |
OLD | NEW |