|
43 | 43 | /* See header for documentation. */ |
44 | 44 | void LayerConfig::parseSamplingOptions(const json& config) |
45 | 45 | { |
46 | | - // Decode top level options |
47 | | - std::string rawMode = config.at("sample_mode"); |
| 46 | + // Decode frame selection mode |
| 47 | + std::string rawFrameMode = config.at("frame_mode"); |
48 | 48 |
|
49 | | - if (rawMode == "disabled") |
| 49 | + if (rawFrameMode == "disabled") |
50 | 50 | { |
51 | | - mode = MODE_DISABLED; |
| 51 | + frameMode = FRAME_SELECTION_DISABLED; |
52 | 52 | } |
53 | | - else if (rawMode == "periodic_frame") |
| 53 | + else if (rawFrameMode == "periodic") |
54 | 54 | { |
55 | | - mode = MODE_PERIODIC_FRAME; |
| 55 | + frameMode = FRAME_SELECTION_PERIODIC; |
56 | 56 | periodicFrame = config.at("periodic_frame"); |
57 | 57 | periodicMinFrame = config.at("periodic_min_frame"); |
58 | 58 | } |
59 | | - else if (rawMode == "frame_list") |
| 59 | + else if (rawFrameMode == "list") |
60 | 60 | { |
61 | | - mode = MODE_FRAME_LIST; |
| 61 | + frameMode = FRAME_SELECTION_LIST; |
62 | 62 | specificFrames = config.at("frame_list").get<std::vector<uint64_t>>(); |
63 | 63 | } |
64 | 64 | else |
65 | 65 | { |
66 | | - LAYER_ERR("Unknown counter sample_mode: %s", rawMode.c_str()); |
67 | | - rawMode = "disabled"; |
| 66 | + LAYER_ERR("Unknown frame_mode: %s", rawFrameMode.c_str()); |
| 67 | + frameMode = FRAME_SELECTION_DISABLED; |
| 68 | + rawFrameMode = "disabled"; |
68 | 69 | } |
69 | 70 |
|
| 71 | + // Decode counter sampling mode |
| 72 | + std::string rawSampleMode = config.at("sample_mode"); |
| 73 | + |
| 74 | + if (rawSampleMode == "disabled") |
| 75 | + { |
| 76 | + samplingMode = COUNTER_SAMPLING_DISABLED; |
| 77 | + } |
| 78 | + else if (rawSampleMode == "frame") |
| 79 | + { |
| 80 | + samplingMode = COUNTER_SAMPLING_FRAMES; |
| 81 | + } |
| 82 | + else if (rawSampleMode == "workload") |
| 83 | + { |
| 84 | + samplingMode = COUNTER_SAMPLING_WORKLOADS; |
| 85 | + } |
| 86 | + else |
| 87 | + { |
| 88 | + LAYER_ERR("Unknown sample_mode: %s", rawSampleMode.c_str()); |
| 89 | + samplingMode = COUNTER_SAMPLING_DISABLED; |
| 90 | + rawSampleMode = "disabled"; |
| 91 | + } |
| 92 | + |
| 93 | + // Decode frame serialization mode |
| 94 | + frameSerialization = config.at("frame_serialization"); |
| 95 | + |
70 | 96 | LAYER_LOG("Layer sampling configuration"); |
71 | 97 | LAYER_LOG("============================"); |
72 | | - LAYER_LOG(" - Sample mode: %s", rawMode.c_str()); |
| 98 | + LAYER_LOG(" - Frame selection mode: %s", rawFrameMode.c_str()); |
73 | 99 |
|
74 | | - if (mode == MODE_PERIODIC_FRAME) |
| 100 | + if (frameMode == FRAME_SELECTION_PERIODIC) |
75 | 101 | { |
76 | 102 | LAYER_LOG(" - Frame period: %" PRIu64, periodicFrame); |
77 | 103 | LAYER_LOG(" - Minimum frame: %" PRIu64, periodicMinFrame); |
78 | 104 | } |
79 | | - else if (mode == MODE_FRAME_LIST) |
| 105 | + else if (frameMode == FRAME_SELECTION_LIST) |
80 | 106 | { |
81 | 107 | std::stringstream result; |
82 | 108 | std::copy(specificFrames.begin(), specificFrames.end(), std::ostream_iterator<uint64_t>(result, " ")); |
83 | 109 | LAYER_LOG(" - Frames: %s", result.str().c_str()); |
84 | 110 | } |
| 111 | + |
| 112 | + LAYER_LOG(" - Counter sampling mode: %s", rawSampleMode.c_str()); |
| 113 | + |
| 114 | + if (samplingMode == COUNTER_SAMPLING_FRAMES) |
| 115 | + { |
| 116 | + LAYER_LOG(" - Frame serialization: %u", frameSerialization); |
| 117 | + } |
85 | 118 | } |
86 | 119 |
|
87 | 120 | /* See header for documentation. */ |
@@ -131,18 +164,45 @@ LayerConfig::LayerConfig() |
131 | 164 | bool LayerConfig::isFrameOfInterest( |
132 | 165 | uint64_t frameID |
133 | 166 | ) const { |
134 | | - switch(mode) |
| 167 | + switch(frameMode) |
135 | 168 | { |
136 | | - case MODE_DISABLED: |
| 169 | + case FRAME_SELECTION_DISABLED: |
137 | 170 | return false; |
138 | | - case MODE_PERIODIC_FRAME: |
| 171 | + case FRAME_SELECTION_PERIODIC: |
139 | 172 | return (frameID >= periodicMinFrame) && |
140 | 173 | ((frameID % periodicFrame) == 0); |
141 | | - case MODE_FRAME_LIST: |
| 174 | + case FRAME_SELECTION_LIST: |
142 | 175 | return isIn(frameID, specificFrames); |
143 | 176 | } |
144 | 177 |
|
145 | 178 | // Should never reach here |
146 | 179 | return false; |
147 | 180 | } |
148 | 181 |
|
| 182 | +/* See header for documentation. */ |
| 183 | +bool LayerConfig::isSamplingWorkloads() const |
| 184 | +{ |
| 185 | + return frameMode != FRAME_SELECTION_DISABLED && |
| 186 | + samplingMode == COUNTER_SAMPLING_WORKLOADS; |
| 187 | +} |
| 188 | + |
| 189 | +/* See header for documentation. */ |
| 190 | +bool LayerConfig::isSamplingFrames() const |
| 191 | +{ |
| 192 | + return frameMode != FRAME_SELECTION_DISABLED && |
| 193 | + samplingMode == COUNTER_SAMPLING_FRAMES; |
| 194 | +} |
| 195 | + |
| 196 | +/* See header for documentation. */ |
| 197 | +bool LayerConfig::isSamplingAny() const |
| 198 | +{ |
| 199 | + return frameMode != FRAME_SELECTION_DISABLED && |
| 200 | + samplingMode != COUNTER_SAMPLING_DISABLED; |
| 201 | +} |
| 202 | + |
| 203 | +/* See header for documentation. */ |
| 204 | +bool LayerConfig::isSerializingFrames() const |
| 205 | +{ |
| 206 | + return isSamplingWorkloads() || |
| 207 | + (isSamplingFrames() && frameSerialization); |
| 208 | +}; |
0 commit comments