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 "sawbuck/common/buffer_parser.h"
21 : #include "syzygy/trace/parse/parse_engine_rpc.h"
22 :
23 : namespace trace {
24 : namespace parser {
25 :
26 E : Parser::Parser() : active_parse_engine_(NULL) {
27 E : }
28 :
29 E : Parser::~Parser() {
30 E : ignore_result(Close());
31 :
32 E : ParseEngineIter it = parse_engine_set_.begin();
33 E : for (; it != parse_engine_set_.end(); ++it) {
34 E : delete *it;
35 E : }
36 E : parse_engine_set_.clear();
37 E : }
38 :
39 E : void Parser::AddParseEngine(ParseEngine* parse_engine) {
40 E : DCHECK(parse_engine != NULL);
41 E : parse_engine_set_.push_front(parse_engine);
42 E : }
43 :
44 E : bool Parser::Init(ParseEventHandler* event_handler) {
45 E : DCHECK(event_handler != NULL);
46 E : DCHECK(active_parse_engine_ == NULL);
47 :
48 E : ParseEngine* engine = NULL;
49 :
50 : // Create the RPC call-trace parse engine.
51 E : LOG(INFO) << "Initializing RPC call-trace parse engine.";
52 E : engine = new ParseEngineRpc;
53 E : if (engine == NULL) {
54 i : LOG(ERROR) << "Failed to initialize RPC call-trace parse engine.";
55 i : return false;
56 : }
57 E : parse_engine_set_.push_back(engine);
58 :
59 : // Setup the event handler for all of the engines.
60 E : ParseEngineIter it = parse_engine_set_.begin();
61 E : for (; it != parse_engine_set_.end(); ++it) {
62 E : (*it)->set_event_handler(event_handler);
63 E : }
64 :
65 E : return true;
66 E : }
67 :
68 E : bool Parser::error_occurred() const {
69 E : DCHECK(active_parse_engine_ != NULL);
70 E : return active_parse_engine_->error_occurred();
71 E : }
72 :
73 i : void Parser::set_error_occurred(bool value) {
74 i : DCHECK(active_parse_engine_ != NULL);
75 i : active_parse_engine_->set_error_occurred(value);
76 i : }
77 :
78 E : bool Parser::OpenTraceFile(const base::FilePath& trace_file_path) {
79 E : DCHECK(!trace_file_path.empty());
80 :
81 E : if (active_parse_engine_ == NULL && !SetActiveParseEngine(trace_file_path)) {
82 E : return false;
83 : }
84 :
85 E : DCHECK(active_parse_engine_ != NULL);
86 E : return active_parse_engine_->OpenTraceFile(trace_file_path);
87 E : }
88 :
89 E : bool Parser::Consume() {
90 E : if (active_parse_engine_ == NULL) {
91 i : LOG(ERROR) << "No open trace files to consume.";
92 i : return false;
93 : }
94 E : return active_parse_engine_->ConsumeAllEvents();
95 E : }
96 :
97 : const ModuleInformation* Parser::GetModuleInformation(
98 E : uint32 process_id, AbsoluteAddress64 addr) const {
99 E : DCHECK(active_parse_engine_ != NULL);
100 E : return active_parse_engine_->GetModuleInformation(process_id, addr);
101 E : }
102 :
103 E : bool Parser::Close() {
104 E : bool result = true;
105 E : if (active_parse_engine_ != NULL) {
106 E : result = active_parse_engine_->CloseAllTraceFiles();
107 E : active_parse_engine_ = NULL;
108 : }
109 E : return result;
110 E : }
111 :
112 E : bool Parser::SetActiveParseEngine(const base::FilePath& trace_file_path) {
113 E : DCHECK(!trace_file_path.empty());
114 E : DCHECK(active_parse_engine_ == NULL);
115 :
116 E : ParseEngineIter it = parse_engine_set_.begin();
117 E : for (; it != parse_engine_set_.end(); ++it) {
118 E : ParseEngine* engine = *it;
119 E : if (engine->IsRecognizedTraceFile(trace_file_path)) {
120 E : LOG(INFO) << "Using " << engine->name() << " Call-Trace Parser.";
121 E : active_parse_engine_ = engine;
122 E : return true;
123 : }
124 E : }
125 :
126 E : LOG(ERROR) << "Failed to find a parse engine for \""
127 : << trace_file_path.value()
128 : << "\".";
129 :
130 E : return false;
131 E : }
132 :
133 : void ParseEventHandlerImpl::OnProcessStarted(base::Time time,
134 : DWORD process_id,
135 E : const TraceSystemInfo* data) {
136 E : }
137 :
138 E : void ParseEventHandlerImpl::OnProcessEnded(base::Time time, DWORD process_id) {
139 E : }
140 :
141 : void ParseEventHandlerImpl::OnFunctionEntry(
142 : base::Time time,
143 : DWORD process_id,
144 : DWORD thread_id,
145 i : const TraceEnterExitEventData* data) {
146 i : }
147 :
148 : void ParseEventHandlerImpl::OnFunctionExit(
149 : base::Time time,
150 : DWORD process_id,
151 : DWORD thread_id,
152 E : const TraceEnterExitEventData* data) {
153 E : }
154 :
155 : void ParseEventHandlerImpl::OnBatchFunctionEntry(
156 : base::Time time,
157 : DWORD process_id,
158 : DWORD thread_id,
159 i : const TraceBatchEnterData* data) {
160 i : }
161 :
162 : void ParseEventHandlerImpl::OnProcessAttach(
163 : base::Time time,
164 : DWORD process_id,
165 : DWORD thread_id,
166 E : const TraceModuleData* data) {
167 E : }
168 :
169 : void ParseEventHandlerImpl::OnProcessDetach(
170 : base::Time time,
171 : DWORD process_id,
172 : DWORD thread_id,
173 E : const TraceModuleData* data) {
174 E : }
175 :
176 : void ParseEventHandlerImpl::OnThreadAttach(
177 : base::Time time,
178 : DWORD process_id,
179 : DWORD thread_id,
180 E : const TraceModuleData* data) {
181 E : }
182 :
183 : void ParseEventHandlerImpl::OnThreadDetach(
184 : base::Time time,
185 : DWORD process_id,
186 : DWORD thread_id,
187 E : const TraceModuleData* data) {
188 E : }
189 :
190 : void ParseEventHandlerImpl::OnInvocationBatch(
191 : base::Time time,
192 : DWORD process_id,
193 : DWORD thread_id,
194 : size_t num_invocations,
195 i : const TraceBatchInvocationInfo* data) {
196 i : }
197 :
198 : void ParseEventHandlerImpl::OnThreadName(
199 : base::Time time,
200 : DWORD process_id,
201 : DWORD thread_id,
202 i : const base::StringPiece& thread_name) {
203 i : }
204 :
205 : void ParseEventHandlerImpl::OnIndexedFrequency(
206 : base::Time time,
207 : DWORD process_id,
208 : DWORD thread_id,
209 E : const TraceIndexedFrequencyData* data) {
210 E : }
211 :
212 : void ParseEventHandlerImpl::OnDynamicSymbol(
213 i : DWORD process_id, uint32 symbol_id, const base::StringPiece& symbol_name) {
214 i : }
215 :
216 : void ParseEventHandlerImpl::OnSampleData(
217 i : base::Time Time, DWORD process_id, const TraceSampleData* data) {
218 i : }
219 :
220 : } // namespace parser
221 : } // namespace trace
|