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