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 coverage grinder, which processes trace files containing
16 : // coverage data and produces LCOV output.
17 : #ifndef SYZYGY_GRINDER_COVERAGE_GRINDER_H_
18 : #define SYZYGY_GRINDER_COVERAGE_GRINDER_H_
19 :
20 : #include "syzygy/grinder/basic_block_util.h"
21 : #include "syzygy/grinder/coverage_data.h"
22 : #include "syzygy/grinder/grinder.h"
23 :
24 : namespace grinder {
25 :
26 : // This class processes trace files containing basic-block frequency data and
27 : // produces LCOV output.
28 : class CoverageGrinder : public GrinderInterface {
29 : public:
30 : CoverageGrinder();
31 : ~CoverageGrinder();
32 :
33 : // @name GrinderInterface implementation.
34 : // @{
35 : virtual bool ParseCommandLine(const CommandLine* command_line) OVERRIDE;
36 : virtual void SetParser(Parser* parser) OVERRIDE;
37 : virtual bool Grind() OVERRIDE;
38 : virtual bool OutputData(FILE* file) OVERRIDE;
39 : // @}
40 :
41 : // @name IndexedFrequencyGrinder implementation.
42 : // @{
43 : // Override of the OnIndexedFrequency callback.
44 : // NOTE: This only process TraceIndexedFrequencyData records of the
45 : // appropriate type (basic-block entry counts).
46 : virtual void OnIndexedFrequency(
47 : base::Time time,
48 : DWORD process_id,
49 : DWORD thread_id,
50 : const TraceIndexedFrequencyData* data) OVERRIDE;
51 : // @}
52 :
53 : enum OutputFormat {
54 : kLcovFormat,
55 : kCacheGrindFormat,
56 : };
57 :
58 E : OutputFormat output_format() const { return output_format_; }
59 :
60 E : const CoverageData& coverage_data() { return coverage_data_; }
61 :
62 : protected:
63 : // Stores per-module coverage data, populated during calls to
64 : // OnIndexedFrequency.
65 : basic_block_util::PdbInfoMap pdb_info_cache_;
66 :
67 : // Stores the final coverage data, populated by Grind. Contains an aggregate
68 : // of all LineInfo objects stored in the pdb_info_map_, in a reverse map
69 : // (where efficient lookup is by file name and line number).
70 : CoverageData coverage_data_;
71 :
72 : // Points to the parser that is feeding us events. Used to get module
73 : // information.
74 : Parser* parser_;
75 :
76 : // Set to true if any call to OnIndexedFrequency fails. Processing will
77 : // continue with a warning that results may be partial.
78 : bool event_handler_errored_;
79 :
80 : // The output format to use.
81 : OutputFormat output_format_;
82 : };
83 :
84 : } // namespace grinder
85 :
86 : #endif // SYZYGY_GRINDER_COVERAGE_GRINDER_H_
|