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 : // This defines the virtual simulator class, which analyzes trace files from
16 : // the execution of an instrumented dll, and calls the respective events
17 : // from a subclass of SimulatorEventHandler.
18 :
19 : #ifndef SYZYGY_SIMULATE_SIMULATOR_H_
20 : #define SYZYGY_SIMULATE_SIMULATOR_H_
21 :
22 : #include "syzygy/playback/playback.h"
23 : #include "syzygy/simulate/simulation_event_handler.h"
24 : #include "syzygy/trace/parse/parser.h"
25 :
26 m : namespace simulate {
27 :
28 : // This class consumes a set of call-trace logs and reports the number of
29 : // pagefaults on them.
30 m : class Simulator : public trace::parser::ParseEventHandlerImpl {
31 m : public:
32 m : typedef playback::Playback Playback;
33 m : typedef Playback::TraceFileList TraceFileList;
34 :
35 : // Construct a new Simulator instance.
36 : // @param module_path The path of the module dll.
37 : // @param instrumented_path The path of the instrumented dll.
38 : // @param trace_files A list of trace files to analyze.
39 : // @param simulation The simulation where the events will be fed.
40 m : Simulator(const base::FilePath& module_path,
41 m : const base::FilePath& instrumented_path,
42 m : const TraceFileList& trace_files,
43 m : SimulationEventHandler* simulation);
44 :
45 : // Decomposes the image, parses the trace files and captures
46 : // the pagefaults on them.
47 : // @returns true on success, false on failure.
48 m : bool ParseTraceFiles();
49 :
50 m : protected:
51 m : typedef block_graph::BlockGraph BlockGraph;
52 m : typedef pe::PEFile PEFile;
53 m : typedef pe::ImageLayout ImageLayout;
54 m : typedef trace::parser::Parser Parser;
55 :
56 : // @name ParseEventHandler overrides.
57 : // @{
58 m : virtual void OnProcessStarted(base::Time time,
59 m : DWORD process_id,
60 m : const TraceSystemInfo* data) override;
61 m : virtual void OnFunctionEntry(base::Time time,
62 m : DWORD process_id,
63 m : DWORD thread_id,
64 m : const TraceEnterExitEventData* data) override;
65 m : virtual void OnBatchFunctionEntry(base::Time time,
66 m : DWORD process_id,
67 m : DWORD thread_id,
68 m : const TraceBatchEnterData* data) override;
69 : // @}
70 :
71 : // The input files.
72 m : base::FilePath module_path_;
73 m : base::FilePath instrumented_path_;
74 m : TraceFileList trace_files_;
75 :
76 : // The PE file and Image layout to be passed to playback_.
77 m : BlockGraph block_graph_;
78 m : PEFile pe_file_;
79 m : ImageLayout image_layout_;
80 :
81 : // A Playback, which would decompose the given image and call the On...
82 : // functions on this Simulator.
83 m : scoped_ptr<Playback> playback_;
84 :
85 : // The call-trace log file parser. This can be preset to a custom parser
86 : // prior to calling Simulator.
87 m : scoped_ptr<Parser> parser_;
88 :
89 : // A pointer to a simulation, that is to be used.
90 m : SimulationEventHandler* simulation_;
91 m : };
92 :
93 m : } // namespace simulate
94 :
95 : #endif // SYZYGY_SIMULATE_SIMULATOR_H_
|