1 : // Copyright 2012 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Implementation of call-trace parsing.
16 :
17 : #include "syzygy/trace/parse/parser.h"
18 :
19 : #include "base/logging.h"
20 : #include "syzygy/common/buffer_parser.h"
21 : #include "syzygy/trace/parse/parse_engine_rpc.h"
22 :
23 : namespace trace {
24 : namespace parser {
25 :
26 : using ::common::BinaryBufferParser;
27 :
28 E : Parser::Parser() : active_parse_engine_(NULL) {
29 E : }
30 :
31 E : Parser::~Parser() {
32 E : ignore_result(Close());
33 :
34 E : ParseEngineIter it = parse_engine_set_.begin();
35 E : for (; it != parse_engine_set_.end(); ++it) {
36 E : delete *it;
37 E : }
38 E : parse_engine_set_.clear();
39 E : }
40 :
41 E : void Parser::AddParseEngine(ParseEngine* parse_engine) {
42 E : DCHECK(parse_engine != NULL);
43 E : parse_engine_set_.push_front(parse_engine);
44 E : }
45 :
46 E : bool Parser::Init(ParseEventHandler* event_handler) {
47 E : DCHECK(event_handler != NULL);
48 E : DCHECK(active_parse_engine_ == NULL);
49 :
50 E : ParseEngine* engine = NULL;
51 :
52 : // Create the RPC call-trace parse engine.
53 E : LOG(INFO) << "Initializing RPC call-trace parse engine.";
54 E : engine = new ParseEngineRpc;
55 E : if (engine == NULL) {
56 i : LOG(ERROR) << "Failed to initialize RPC call-trace parse engine.";
57 i : return false;
58 : }
59 E : parse_engine_set_.push_back(engine);
60 :
61 : // Setup the event handler for all of the engines.
62 E : ParseEngineIter it = parse_engine_set_.begin();
63 E : for (; it != parse_engine_set_.end(); ++it) {
64 E : (*it)->set_event_handler(event_handler);
65 E : }
66 :
67 E : return true;
68 E : }
69 :
70 E : bool Parser::error_occurred() const {
71 E : DCHECK(active_parse_engine_ != NULL);
72 E : return active_parse_engine_->error_occurred();
73 E : }
74 :
75 i : void Parser::set_error_occurred(bool value) {
76 i : DCHECK(active_parse_engine_ != NULL);
77 i : active_parse_engine_->set_error_occurred(value);
78 i : }
79 :
80 E : bool Parser::OpenTraceFile(const base::FilePath& trace_file_path) {
81 E : DCHECK(!trace_file_path.empty());
82 :
83 E : if (active_parse_engine_ == NULL && !SetActiveParseEngine(trace_file_path)) {
84 E : return false;
85 : }
86 :
87 E : DCHECK(active_parse_engine_ != NULL);
88 E : return active_parse_engine_->OpenTraceFile(trace_file_path);
89 E : }
90 :
91 E : bool Parser::Consume() {
92 E : if (active_parse_engine_ == NULL) {
93 i : LOG(ERROR) << "No open trace files to consume.";
94 i : return false;
95 : }
96 E : return active_parse_engine_->ConsumeAllEvents();
97 E : }
98 :
99 : const ModuleInformation* Parser::GetModuleInformation(
100 : uint32_t process_id,
101 E : AbsoluteAddress64 addr) const {
102 E : DCHECK(active_parse_engine_ != NULL);
103 E : return active_parse_engine_->GetModuleInformation(process_id, addr);
104 E : }
105 :
106 E : bool Parser::Close() {
107 E : bool result = true;
108 E : if (active_parse_engine_ != NULL) {
109 E : result = active_parse_engine_->CloseAllTraceFiles();
110 E : active_parse_engine_ = NULL;
111 : }
112 E : return result;
113 E : }
114 :
115 E : bool Parser::SetActiveParseEngine(const base::FilePath& trace_file_path) {
116 E : DCHECK(!trace_file_path.empty());
117 E : DCHECK(active_parse_engine_ == NULL);
118 :
119 E : ParseEngineIter it = parse_engine_set_.begin();
120 E : for (; it != parse_engine_set_.end(); ++it) {
121 E : ParseEngine* engine = *it;
122 E : if (engine->IsRecognizedTraceFile(trace_file_path)) {
123 E : LOG(INFO) << "Using " << engine->name() << " Call-Trace Parser.";
124 E : active_parse_engine_ = engine;
125 E : return true;
126 : }
127 E : }
128 :
129 E : LOG(ERROR) << "Failed to find a parse engine for \""
130 : << trace_file_path.value()
131 : << "\".";
132 :
133 E : return false;
134 E : }
135 :
136 : void ParseEventHandlerImpl::OnProcessStarted(base::Time time,
137 : DWORD process_id,
138 E : const TraceSystemInfo* data) {
139 E : }
140 :
141 E : void ParseEventHandlerImpl::OnProcessEnded(base::Time time, DWORD process_id) {
142 E : }
143 :
144 : void ParseEventHandlerImpl::OnFunctionEntry(
145 : base::Time time,
146 : DWORD process_id,
147 : DWORD thread_id,
148 i : const TraceEnterExitEventData* data) {
149 i : }
150 :
151 : void ParseEventHandlerImpl::OnFunctionExit(
152 : base::Time time,
153 : DWORD process_id,
154 : DWORD thread_id,
155 E : const TraceEnterExitEventData* data) {
156 E : }
157 :
158 : void ParseEventHandlerImpl::OnBatchFunctionEntry(
159 : base::Time time,
160 : DWORD process_id,
161 : DWORD thread_id,
162 i : const TraceBatchEnterData* data) {
163 i : }
164 :
165 : void ParseEventHandlerImpl::OnProcessAttach(
166 : base::Time time,
167 : DWORD process_id,
168 : DWORD thread_id,
169 E : const TraceModuleData* data) {
170 E : }
171 :
172 : void ParseEventHandlerImpl::OnProcessDetach(
173 : base::Time time,
174 : DWORD process_id,
175 : DWORD thread_id,
176 E : const TraceModuleData* data) {
177 E : }
178 :
179 : void ParseEventHandlerImpl::OnThreadAttach(
180 : base::Time time,
181 : DWORD process_id,
182 : DWORD thread_id,
183 E : const TraceModuleData* data) {
184 E : }
185 :
186 : void ParseEventHandlerImpl::OnThreadDetach(
187 : base::Time time,
188 : DWORD process_id,
189 : DWORD thread_id,
190 E : const TraceModuleData* data) {
191 E : }
192 :
193 : void ParseEventHandlerImpl::OnInvocationBatch(
194 : base::Time time,
195 : DWORD process_id,
196 : DWORD thread_id,
197 : size_t num_invocations,
198 i : const TraceBatchInvocationInfo* data) {
199 i : }
200 :
201 : void ParseEventHandlerImpl::OnThreadName(
202 : base::Time time,
203 : DWORD process_id,
204 : DWORD thread_id,
205 i : const base::StringPiece& thread_name) {
206 i : }
207 :
208 : void ParseEventHandlerImpl::OnIndexedFrequency(
209 : base::Time time,
210 : DWORD process_id,
211 : DWORD thread_id,
212 E : const TraceIndexedFrequencyData* data) {
213 E : }
214 :
215 : void ParseEventHandlerImpl::OnDynamicSymbol(
216 : DWORD process_id,
217 : uint32_t symbol_id,
218 i : const base::StringPiece& symbol_name) {
219 i : }
220 :
221 : void ParseEventHandlerImpl::OnSampleData(
222 i : base::Time Time, DWORD process_id, const TraceSampleData* data) {
223 i : }
224 :
225 : void ParseEventHandlerImpl::OnFunctionNameTableEntry(
226 : base::Time Time,
227 : DWORD process_id,
228 i : const TraceFunctionNameTableEntry* data) {
229 i : }
230 :
231 : void ParseEventHandlerImpl::OnStackTrace(
232 : base::Time Time,
233 : DWORD process_id,
234 i : const TraceStackTrace* data) {
235 i : }
236 :
237 : void ParseEventHandlerImpl::OnDetailedFunctionCall(
238 : base::Time Time,
239 : DWORD process_id,
240 : DWORD thread_id,
241 i : const TraceDetailedFunctionCall* data) {
242 i : }
243 :
244 : void ParseEventHandlerImpl::OnComment(
245 : base::Time time,
246 : DWORD process_id,
247 i : const TraceComment* data) {
248 i : }
249 :
250 : void ParseEventHandlerImpl::OnProcessHeap(base::Time time,
251 : DWORD process_id,
252 i : const TraceProcessHeap* data) {
253 i : }
254 :
255 : } // namespace parser
256 : } // namespace trace
|