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