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 : // Declares the grinder interface. A grinder is broadly a ParseEventHandler
16 : // that can parse a command-line, do a unit of work, and produce some summary
17 : // output.
18 : #ifndef SYZYGY_GRINDER_GRINDER_H_
19 : #define SYZYGY_GRINDER_GRINDER_H_
20 :
21 : #include "base/command_line.h"
22 : #include "syzygy/trace/parse/parser.h"
23 :
24 : namespace grinder {
25 :
26 : // The simple interface all grinders implement.
27 : class GrinderInterface : public trace::parser::ParseEventHandlerImpl {
28 : public:
29 : typedef trace::parser::Parser Parser;
30 :
31 E : virtual ~GrinderInterface() { }
32 :
33 : // Parses any required and/or optional arguments from the command-line.
34 : // @param command_line the command-line to be parsed.
35 : // @returns true on success, false otherwise.
36 : // @note The implementation should log on failure.
37 : virtual bool ParseCommandLine(const CommandLine* command_line) = 0;
38 :
39 : // Provides a pointer to the parse engine that will be used to push events
40 : // to the grinder. This will be called after a successful call to
41 : // ParseCommandLine and prior to any parse event handling.
42 : // @param parser the parser that will be feeding events to this event
43 : // handler.
44 : virtual void SetParser(Parser* parser) = 0;
45 :
46 : // Performs any computation/aggregation/summarization that needs to be done
47 : // after having parsed trace files. This will only be called after a
48 : // successful call to ParseCommandLine and after all parse events have been
49 : // successfully handled by this object.
50 : // @returns true on success, false otherwise.
51 : // @note The implementation should log on failure.
52 : virtual bool Grind() = 0;
53 :
54 : // Produces the final output to the provided file handle. This will only be
55 : // called after a successful call to Grind.
56 : // @returns true on success, false otherwise.
57 : // @note The implementation should log on failure.
58 : virtual bool OutputData(FILE* file) = 0;
59 : };
60 :
61 : } // namespace grinder
62 :
63 : #endif // SYZYGY_GRINDER_GRINDER_H_
|