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/strings/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 block_graph::TransformPolicyInterface TransformPolicyInterface;
36 : typedef common::IndexedFrequencyData IndexedFrequencyData;
37 :
38 : // Construct a transform which adds a static frequency data instance.
39 : // @param agent_id The agent that'll use those data.
40 : // @param freq_name The name of the frequency data block.
41 : // @param version The version of the data structure used to store the data.
42 : // @param indexed_frequency_data_size The size of the indexed_frequency_data
43 : // structure or extended version. Instrumenters may add fields after the
44 : // common part of the indexed_frequency_data structure.
45 : AddIndexedFrequencyDataTransform(uint32 agent_id,
46 : const base::StringPiece& freq_name,
47 : uint32 version,
48 : IndexedFrequencyData::DataType data_type,
49 : size_t indexed_frequency_data_size);
50 :
51 : // Return the block which holds the frequency data. This will only be non-NULL
52 : // after a successful application of this transform.
53 E : BlockGraph::Block* frequency_data_block() { return frequency_data_block_; }
54 :
55 : // Returns the block which holds the frequency data buffer. This will only
56 : // be non-NULL after a successful application of this transform.
57 E : BlockGraph::Block* frequency_data_buffer_block() {
58 E : return frequency_data_buffer_block_;
59 E : }
60 :
61 : // BlockGraphTransformInterface Implementation.
62 : virtual bool TransformBlockGraph(const TransformPolicyInterface* policy,
63 : BlockGraph* block_graph,
64 : BlockGraph::Block* header_block) override;
65 :
66 : // After applying the transform, this method can be used to allocate the
67 : // correct number of bytes for the default frequency data static buffer.
68 : // @param num_entries The number of frequency counters to allocate.
69 : // @param frequency_size The size (in bytes) of each frequency counter. This
70 : // must be 1, 2 or 4.
71 : bool ConfigureFrequencyDataBuffer(uint32 num_entries,
72 : uint32 num_columns,
73 : uint8 frequency_size);
74 :
75 : // The transform name.
76 : static const char kTransformName[];
77 :
78 : protected:
79 : // The agent id to embed into the IndexFrequencyData instance.
80 : uint32 agent_id_;
81 :
82 : // The statically allocated frequency data block that is added by the
83 : // transform. This becomes non-NULL after a successful application of the
84 : // transform.
85 : BlockGraph::Block* frequency_data_block_;
86 :
87 : // The size of the statically allocated block.
88 : size_t frequency_data_block_size_;
89 :
90 : // The statically allocated frequency data buffer block that is added by the
91 : // transform. This becomes non-NULL after a successful application of the
92 : // transform. This is allocated as a separate block because it is
93 : // uninitialized and may be written to the image for free.
94 : BlockGraph::Block* frequency_data_buffer_block_;
95 :
96 : // Name of the frequency data block.
97 : std::string freq_name_;
98 :
99 : // Version of the data structure.
100 : uint32 version_;
101 :
102 : // The type of the data in the IndexFrequencyData instance.
103 : IndexedFrequencyData::DataType data_type_;
104 : };
105 :
106 : } // namespace transforms
107 : } // namespace instrument
108 :
109 : #endif // SYZYGY_INSTRUMENT_TRANSFORMS_ADD_INDEXED_FREQUENCY_DATA_TRANSFORM_H_
|