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 RUNTIME_VM_SOURCE_REPORT_H_ | 5 #ifndef RUNTIME_VM_SOURCE_REPORT_H_ |
6 #define RUNTIME_VM_SOURCE_REPORT_H_ | 6 #define RUNTIME_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/profiler_service.h" |
13 #include "vm/token_position.h" | 13 #include "vm/token_position.h" |
14 | 14 |
15 namespace dart { | 15 namespace dart { |
16 | 16 |
17 // A SourceReport object is used to generate reports about the program | 17 // A SourceReport object is used to generate reports about the program |
18 // source code, with information associated with source token | 18 // source code, with information associated with source token |
19 // positions. There are multiple possible kinds of reports. | 19 // positions. There are multiple possible kinds of reports. |
20 class SourceReport { | 20 class SourceReport { |
21 public: | 21 public: |
22 enum ReportKind { | 22 enum ReportKind { |
23 kCallSites = 0x1, | 23 kCallSites = 0x1, |
24 kCoverage = 0x2, | 24 kCoverage = 0x2, |
25 kPossibleBreakpoints = 0x4, | 25 kPossibleBreakpoints = 0x4, |
26 kProfile = 0x8, | 26 kProfile = 0x8, |
27 }; | 27 }; |
28 | 28 |
29 static const char* kCallSitesStr; | 29 static const char* kCallSitesStr; |
30 static const char* kCoverageStr; | 30 static const char* kCoverageStr; |
31 static const char* kPossibleBreakpointsStr; | 31 static const char* kPossibleBreakpointsStr; |
32 static const char* kProfileStr; | 32 static const char* kProfileStr; |
33 | 33 |
34 enum CompileMode { | 34 enum CompileMode { kNoCompile, kForceCompile }; |
35 kNoCompile, | |
36 kForceCompile | |
37 }; | |
38 | 35 |
39 // report_set is a bitvector indicating which reports to generate | 36 // report_set is a bitvector indicating which reports to generate |
40 // (e.g. kCallSites | kCoverage). | 37 // (e.g. kCallSites | kCoverage). |
41 explicit SourceReport(intptr_t report_set, | 38 explicit SourceReport(intptr_t report_set, CompileMode compile = kNoCompile); |
42 CompileMode compile = kNoCompile); | |
43 ~SourceReport(); | 39 ~SourceReport(); |
44 | 40 |
45 // Generate a source report for (some subrange of) a script. | 41 // Generate a source report for (some subrange of) a script. |
46 // | 42 // |
47 // If script is null, then the report is generated for all scripts | 43 // If script is null, then the report is generated for all scripts |
48 // in the isolate. | 44 // in the isolate. |
49 void PrintJSON(JSONStream* js, const Script& script, | 45 void PrintJSON(JSONStream* js, |
| 46 const Script& script, |
50 TokenPosition start_pos = TokenPosition::kNoSource, | 47 TokenPosition start_pos = TokenPosition::kNoSource, |
51 TokenPosition end_pos = TokenPosition::kNoSource); | 48 TokenPosition end_pos = TokenPosition::kNoSource); |
52 | 49 |
53 private: | 50 private: |
54 void ClearScriptTable(); | 51 void ClearScriptTable(); |
55 void Init(Thread* thread, const Script* script, | 52 void Init(Thread* thread, |
56 TokenPosition start_pos, TokenPosition end_pos); | 53 const Script* script, |
| 54 TokenPosition start_pos, |
| 55 TokenPosition end_pos); |
57 | 56 |
58 Thread* thread() const { return thread_; } | 57 Thread* thread() const { return thread_; } |
59 Zone* zone() const { return thread_->zone(); } | 58 Zone* zone() const { return thread_->zone(); } |
60 Isolate* isolate() const { return thread_->isolate(); } | 59 Isolate* isolate() const { return thread_->isolate(); } |
61 | 60 |
62 bool IsReportRequested(ReportKind report_kind); | 61 bool IsReportRequested(ReportKind report_kind); |
63 bool ShouldSkipFunction(const Function& func); | 62 bool ShouldSkipFunction(const Function& func); |
64 intptr_t GetScriptIndex(const Script& script); | 63 intptr_t GetScriptIndex(const Script& script); |
65 bool ScriptIsLoadedByLibrary(const Script& script, const Library& lib); | 64 bool ScriptIsLoadedByLibrary(const Script& script, const Library& lib); |
66 | 65 |
67 void PrintCallSitesData(JSONObject* jsobj, | 66 void PrintCallSitesData(JSONObject* jsobj, |
68 const Function& func, const Code& code); | 67 const Function& func, |
| 68 const Code& code); |
69 void PrintCoverageData(JSONObject* jsobj, | 69 void PrintCoverageData(JSONObject* jsobj, |
70 const Function& func, const Code& code); | 70 const Function& func, |
| 71 const Code& code); |
71 void PrintPossibleBreakpointsData(JSONObject* jsobj, | 72 void PrintPossibleBreakpointsData(JSONObject* jsobj, |
72 const Function& func, const Code& code); | 73 const Function& func, |
| 74 const Code& code); |
73 void PrintProfileData(JSONObject* jsobj, ProfileFunction* profile_function); | 75 void PrintProfileData(JSONObject* jsobj, ProfileFunction* profile_function); |
74 #if defined(DEBUG) | 76 #if defined(DEBUG) |
75 void VerifyScriptTable(); | 77 void VerifyScriptTable(); |
76 #endif | 78 #endif |
77 void PrintScriptTable(JSONArray* jsarr); | 79 void PrintScriptTable(JSONArray* jsarr); |
78 | 80 |
79 void VisitFunction(JSONArray* jsarr, const Function& func); | 81 void VisitFunction(JSONArray* jsarr, const Function& func); |
80 void VisitLibrary(JSONArray* jsarr, const Library& lib); | 82 void VisitLibrary(JSONArray* jsarr, const Library& lib); |
81 void VisitClosures(JSONArray* jsarr); | 83 void VisitClosures(JSONArray* jsarr); |
82 | 84 |
83 // An entry in the script table. | 85 // An entry in the script table. |
84 struct ScriptTableEntry { | 86 struct ScriptTableEntry { |
85 ScriptTableEntry() : key(NULL), index(-1), script(NULL) {} | 87 ScriptTableEntry() : key(NULL), index(-1), script(NULL) {} |
86 | 88 |
87 const String* key; | 89 const String* key; |
88 intptr_t index; | 90 intptr_t index; |
89 const Script* script; | 91 const Script* script; |
90 }; | 92 }; |
91 | 93 |
92 // Needed for DirectChainedHashMap. | 94 // Needed for DirectChainedHashMap. |
93 struct ScriptTableTrait { | 95 struct ScriptTableTrait { |
94 typedef ScriptTableEntry* Value; | 96 typedef ScriptTableEntry* Value; |
95 typedef const String* Key; | 97 typedef const String* Key; |
96 typedef ScriptTableEntry* Pair; | 98 typedef ScriptTableEntry* Pair; |
97 | 99 |
98 static Key KeyOf(Pair kv) { | 100 static Key KeyOf(Pair kv) { return kv->key; } |
99 return kv->key; | |
100 } | |
101 | 101 |
102 static Value ValueOf(Pair kv) { | 102 static Value ValueOf(Pair kv) { return kv; } |
103 return kv; | |
104 } | |
105 | 103 |
106 static inline intptr_t Hashcode(Key key) { | 104 static inline intptr_t Hashcode(Key key) { return key->Hash(); } |
107 return key->Hash(); | |
108 } | |
109 | 105 |
110 static inline bool IsKeyEqual(Pair kv, Key key) { | 106 static inline bool IsKeyEqual(Pair kv, Key key) { |
111 return kv->key->Equals(*key); | 107 return kv->key->Equals(*key); |
112 } | 108 } |
113 }; | 109 }; |
114 | 110 |
115 intptr_t report_set_; | 111 intptr_t report_set_; |
116 CompileMode compile_mode_; | 112 CompileMode compile_mode_; |
117 Thread* thread_; | 113 Thread* thread_; |
118 const Script* script_; | 114 const Script* script_; |
119 TokenPosition start_pos_; | 115 TokenPosition start_pos_; |
120 TokenPosition end_pos_; | 116 TokenPosition end_pos_; |
121 Profile profile_; | 117 Profile profile_; |
122 GrowableArray<ScriptTableEntry*> script_table_entries_; | 118 GrowableArray<ScriptTableEntry*> script_table_entries_; |
123 DirectChainedHashMap<ScriptTableTrait> script_table_; | 119 DirectChainedHashMap<ScriptTableTrait> script_table_; |
124 intptr_t next_script_index_; | 120 intptr_t next_script_index_; |
125 }; | 121 }; |
126 | 122 |
127 } // namespace dart | 123 } // namespace dart |
128 | 124 |
129 #endif // RUNTIME_VM_SOURCE_REPORT_H_ | 125 #endif // RUNTIME_VM_SOURCE_REPORT_H_ |
OLD | NEW |