Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
source_report.h
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_SOURCE_REPORT_H_
6#define RUNTIME_VM_SOURCE_REPORT_H_
7
8#include "vm/globals.h"
9#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
10
11#include "vm/allocation.h"
12#include "vm/flags.h"
13#include "vm/hash_map.h"
14#include "vm/object.h"
15#include "vm/profiler_service.h"
16#include "vm/token_position.h"
17
18namespace dart {
19
20// A SourceReport object is used to generate reports about the program
21// source code, with information associated with source token
22// positions. There are multiple possible kinds of reports.
24 public:
32
33 static const char* kCallSitesStr;
34 static const char* kCoverageStr;
35 static const char* kPossibleBreakpointsStr;
36 static const char* kProfileStr;
37 static const char* kBranchCoverageStr;
38
40
41 // report_set is a bitvector indicating which reports to generate
42 // (e.g. kCallSites | kCoverage).
43 //
44 // If library_filters is not null, then the report will only include libraries
45 // whose URIs start with one of the filter strings.
46 explicit SourceReport(intptr_t report_set,
48 bool report_lines = false);
49 explicit SourceReport(intptr_t report_set,
50 const GrowableObjectArray& library_filters,
51 ZoneCStringSet* libraries_already_compiled = nullptr,
53 bool report_lines = false);
55
56 // Generate a source report for (some subrange of) a script.
57 //
58 // If script is null, then the report is generated for all scripts
59 // in the isolate.
60 void PrintJSON(JSONStream* js,
61 const Script& script,
64
65 private:
66 void ClearScriptTable();
67 void Init(Thread* thread,
68 const Script* script,
69 TokenPosition start_pos,
70 TokenPosition end_pos);
71
72 Thread* thread() const { return thread_; }
73 Zone* zone() const { return thread_->zone(); }
74 Isolate* isolate() const { return thread_->isolate(); }
75
76 bool IsReportRequested(ReportKind report_kind);
77 bool ShouldSkipFunction(const Function& func);
78 bool ShouldSkipField(const Field& field);
79 intptr_t GetScriptIndex(const Script& script);
80 bool ScriptIsLoadedByLibrary(const Script& script, const Library& lib);
81 intptr_t GetTokenPosOrLine(const Script& script,
82 const TokenPosition& token_pos);
83 bool IsLibraryAlreadyCompiled(const Library& lib);
84 bool ShouldFiltersIncludeScript(const Script& script);
85 bool ShouldFiltersIncludeUrl(const String& url);
86
87 void PrintCallSitesData(JSONObject* jsobj,
88 const Function& func,
89 const Code& code);
90 void PrintCoverageData(JSONObject* jsobj,
91 const Function& func,
92 const Code& code,
93 bool report_branch_coverage);
94 void PrintPossibleBreakpointsData(JSONObject* jsobj,
95 const Function& func,
96 const Code& code);
97 void PrintProfileData(JSONObject* jsobj, ProfileFunction* profile_function);
98#if defined(DEBUG)
99 void VerifyScriptTable();
100#endif
101 void PrintScriptTable(JSONArray* jsarr);
102
103 void VisitFunction(JSONArray* jsarr,
104 const Function& func,
105 CompileMode compile_mode);
106 void VisitField(JSONArray* jsarr,
107 const Field& field,
108 CompileMode compile_mode);
109 void VisitLibrary(JSONArray* jsarr, const Library& lib);
110 void VisitClosures(JSONArray* jsarr);
111 // An entry in the script table.
112 struct ScriptTableEntry {
113 ScriptTableEntry() : key(nullptr), index(-1), script(nullptr) {}
114
115 const String* key;
116 intptr_t index;
117 const Script* script;
118 };
119
120 // Needed for DirectChainedHashMap.
121 struct ScriptTableTrait {
122 typedef ScriptTableEntry* Value;
123 typedef const ScriptTableEntry* Key;
124 typedef ScriptTableEntry* Pair;
125
126 static Key KeyOf(Pair kv) { return kv; }
127
128 static Value ValueOf(Pair kv) { return kv; }
129
130 static inline uword Hash(Key key) { return key->key->Hash(); }
131
132 static inline bool IsKeyEqual(Pair kv, Key key) {
133 return kv->script->ptr() == key->script->ptr();
134 }
135 };
136
137 void CollectAllScripts(
138 DirectChainedHashMap<ScriptTableTrait>* local_script_table,
139 GrowableArray<ScriptTableEntry*>* local_script_table_entries);
140
141 void CleanupCollectedScripts(
142 DirectChainedHashMap<ScriptTableTrait>* local_script_table,
143 GrowableArray<ScriptTableEntry*>* local_script_table_entries);
144
145 void CollectConstConstructorCoverageFromScripts(
146 GrowableArray<ScriptTableEntry*>* local_script_table_entries,
147 JSONArray* ranges);
148
149 intptr_t report_set_;
150 CompileMode compile_mode_;
151 bool report_lines_;
152 const GrowableObjectArray& library_filters_;
153 ZoneCStringSet* libraries_already_compiled_;
154 Thread* thread_;
155 const Script* script_;
156 TokenPosition start_pos_;
157 TokenPosition end_pos_;
158 Profile profile_;
159 GrowableArray<ScriptTableEntry*> script_table_entries_;
160 DirectChainedHashMap<ScriptTableTrait> script_table_;
161 intptr_t next_script_index_;
162 intptr_t late_error_class_id_ = ClassId::kIllegalCid;
163};
164
165} // namespace dart
166
167#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
168#endif // RUNTIME_VM_SOURCE_REPORT_H_
TArray< uint32_t > Key
void PrintJSON(JSONStream *js, const Script &script, TokenPosition start_pos=TokenPosition::kMinSource, TokenPosition end_pos=TokenPosition::kMaxSource)
static const char * kPossibleBreakpointsStr
static const char * kCallSitesStr
static const char * kCoverageStr
static const char * kBranchCoverageStr
static const char * kProfileStr
Zone * zone() const
Isolate * isolate() const
Definition thread.h:533
static const TokenPosition kMaxSource
static const TokenPosition kMinSource
void Init()
@ kIllegalCid
Definition class_id.h:214
uintptr_t uword
Definition globals.h:501