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 a block-graph transform to be used by the indexed frequency
16 : // tracking instrumentation to add a static IndexedFrequencyData object to the
17 : // block graph.
18 :
19 : #ifndef SYZYGY_INSTRUMENT_TRANSFORMS_ADD_INDEXED_FREQUENCY_DATA_TRANSFORM_H_
20 : #define SYZYGY_INSTRUMENT_TRANSFORMS_ADD_INDEXED_FREQUENCY_DATA_TRANSFORM_H_
21 :
22 : #include "base/string_piece.h"
23 : #include "syzygy/block_graph/transforms/named_transform.h"
24 : #include "syzygy/common/indexed_frequency_data.h"
25 : #include "syzygy/core/address_space.h"
26 :
27 : namespace instrument {
28 : namespace transforms {
29 :
30 : class AddIndexedFrequencyDataTransform
31 : : public block_graph::transforms::NamedBlockGraphTransformImpl<
32 : AddIndexedFrequencyDataTransform> {
33 : public:
34 : typedef block_graph::BlockGraph BlockGraph;
35 : typedef common::IndexedFrequencyData IndexedFrequencyData;
36 :
37 : // Construct a transform which adds a static frequency data instance.
38 : // @param agent_id The agent that'll use those data.
39 : // @param freq_name The name of the frequency data block.
40 : // @param version The version of the data structure used to store the data.
41 : AddIndexedFrequencyDataTransform(uint32 agent_id,
42 : const base::StringPiece& freq_name,
43 : uint32 version,
44 : IndexedFrequencyData::DataType data_type);
45 :
46 : // Return the block which holds the frequency data. This will only be non-NULL
47 : // after a successful application of this transform.
48 E : BlockGraph::Block* frequency_data_block() { return frequency_data_block_; }
49 :
50 : // Returns the block which holds the frequency data buffer. This will only
51 : // be non-NULL after a successful application of this transform.
52 E : BlockGraph::Block* frequency_data_buffer_block() {
53 E : return frequency_data_buffer_block_;
54 E : }
55 :
56 : // BlockGraphTransformInterface Implementation.
57 : virtual bool TransformBlockGraph(BlockGraph* block_graph,
58 : BlockGraph::Block* header_block) OVERRIDE;
59 :
60 : // After applying the transform, this method can be used to allocate the
61 : // correct number of bytes for the default frequency data static buffer.
62 : // @param num_entries The number of frequency counters to allocate.
63 : // @param frequency_size The size (in bytes) of each frequency counter. This
64 : // must be 1, 2 or 4.
65 : bool ConfigureFrequencyDataBuffer(uint32 num_entries,
66 : uint8 frequency_size);
67 :
68 : // The transform name.
69 : static const char kTransformName[];
70 :
71 : protected:
72 : // The agent id to embed into the IndexFrequencyData instance.
73 : uint32 agent_id_;
74 :
75 : // The statically allocated frequency data block that is added by the
76 : // transform. This becomes non-NULL after a successful application of the
77 : // transform.
78 : BlockGraph::Block* frequency_data_block_;
79 : // The statically allocated frequency data buffer block that is added by the
80 : // transform. This becomes non-NULL after a successful application of the
81 : // transform. This is allocated as a separate block because it is
82 : // uninitialized and may be written to the image for free.
83 : BlockGraph::Block* frequency_data_buffer_block_;
84 :
85 : // Name of the frequency data block.
86 : std::string freq_name_;
87 :
88 : // Version of the data structure.
89 : uint32 version_;
90 :
91 : // The type of the data in the IndexFrequencyData instance.
92 : IndexedFrequencyData::DataType data_type_;
93 : };
94 :
95 : } // namespace transforms
96 : } // namespace instrument
97 :
98 : #endif // SYZYGY_INSTRUMENT_TRANSFORMS_ADD_INDEXED_FREQUENCY_DATA_TRANSFORM_H_
|