10
10
#include < aws/core/monitoring/CoreMetrics.h>
11
11
#include < aws/core/monitoring/MonitoringFactory.h>
12
12
#include < aws/core/monitoring/MonitoringInterface.h>
13
+ #include < aws/core/utils/DateTime.h>
14
+ #include < aws/core/utils/json/JsonSerializer.h>
13
15
#include < aws/core/utils/memory/AWSMemory.h>
16
+ #include < aws/core/utils/memory/stl/AWSMap.h>
14
17
#include < aws/core/utils/memory/stl/AWSSet.h>
15
18
#include < aws/core/utils/memory/stl/AWSString.h>
16
19
#include < aws/core/utils/memory/stl/AWSVector.h>
17
20
18
21
#include < cstdint>
19
22
#include < memory>
20
- #include < utility >
23
+ #include < variant >
21
24
22
25
namespace PerformanceTest {
23
26
namespace Reporting {
27
+
24
28
/* *
25
29
* Container for a single performance metric record that stores measurement data and associated metadata.
26
30
*/
27
31
struct PerformanceMetricRecord {
28
32
Aws::String name;
29
33
Aws::String description;
30
34
Aws::String unit;
31
- int64_t date;
32
- Aws::Vector<int64_t > measurements;
33
- Aws::Vector<std::pair< Aws::String, Aws::String> > dimensions;
35
+ Aws::Utils::DateTime date;
36
+ Aws::Vector<std::variant< int64_t , double > > measurements;
37
+ Aws::Map< Aws::String, Aws::String> dimensions;
34
38
};
35
39
36
40
/* *
@@ -39,6 +43,18 @@ struct PerformanceMetricRecord {
39
43
*/
40
44
class JsonReportingMetrics : public Aws ::Monitoring::MonitoringInterface {
41
45
public:
46
+ /* *
47
+ * Constructor that initializes the metrics collector with configuration parameters.
48
+ * @param monitoredOperations Set of operations to monitor (empty means monitor all)
49
+ * @param productId Product identifier (e.g., "cpp1")
50
+ * @param sdkVersion SDK version string
51
+ * @param commitId Git commit identifier
52
+ * @param outputFilename Path to output file (e.g., "s3-perf-results.json")
53
+ */
54
+ JsonReportingMetrics (const Aws::Set<Aws::String>& monitoredOperations = Aws::Set<Aws::String>(), const Aws::String& productId = " unknown" ,
55
+ const Aws::String& sdkVersion = " unknown" , const Aws::String& commitId = " unknown" ,
56
+ const Aws::String& outputFilename = " performance-test-results.json" );
57
+
42
58
~JsonReportingMetrics () override ;
43
59
44
60
/* *
@@ -58,7 +74,7 @@ class JsonReportingMetrics : public Aws::Monitoring::MonitoringInterface {
58
74
* @param request HTTP request object
59
75
* @param outcome HTTP response outcome
60
76
* @param metrics Core metrics collection containing latency data
61
- * @param context Request context (unused)
77
+ * @param context Request context
62
78
*/
63
79
void OnRequestSucceeded (const Aws::String& serviceName, const Aws::String& requestName,
64
80
const std::shared_ptr<const Aws::Http::HttpRequest>& request, const Aws::Client::HttpResponseOutcome& outcome,
@@ -71,7 +87,7 @@ class JsonReportingMetrics : public Aws::Monitoring::MonitoringInterface {
71
87
* @param request HTTP request object
72
88
* @param outcome HTTP response outcome
73
89
* @param metrics Core metrics collection containing latency data
74
- * @param context Request context (unused)
90
+ * @param context Request context
75
91
*/
76
92
void OnRequestFailed (const Aws::String& serviceName, const Aws::String& requestName,
77
93
const std::shared_ptr<const Aws::Http::HttpRequest>& request, const Aws::Client::HttpResponseOutcome& outcome,
@@ -82,7 +98,7 @@ class JsonReportingMetrics : public Aws::Monitoring::MonitoringInterface {
82
98
* @param serviceName Name of the AWS service
83
99
* @param requestName Name of the operation
84
100
* @param request HTTP request object
85
- * @param context Request context (unused)
101
+ * @param context Request context
86
102
*/
87
103
void OnRequestRetry (const Aws::String& serviceName, const Aws::String& requestName,
88
104
const std::shared_ptr<const Aws::Http::HttpRequest>& request, void * context) const override ;
@@ -92,60 +108,53 @@ class JsonReportingMetrics : public Aws::Monitoring::MonitoringInterface {
92
108
* @param serviceName Name of the AWS service
93
109
* @param requestName Name of the operation
94
110
* @param request HTTP request object
95
- * @param context Request context (unused)
111
+ * @param context Request context
96
112
*/
97
113
void OnFinish (const Aws::String& serviceName, const Aws::String& requestName,
98
114
const std::shared_ptr<const Aws::Http::HttpRequest>& request, void * context) const override ;
99
115
116
+ private:
100
117
/* *
101
- * Sets test dimensions that will be included with all performance records.
102
- * @param dimensions Vector of key-value pairs representing test dimensions (e.g., size, bucket type)
103
- */
104
- static void SetTestContext (const Aws::Vector<std::pair<Aws::String, Aws::String>>& dimensions);
105
-
106
- /* *
107
- * Registers specific operations to monitor. If empty, all operations are monitored.
108
- * @param operations Vector of operation names to track (e.g., "PutObject", "GetItem")
109
- */
110
- static void RegisterOperationsToMonitor (const Aws::Vector<Aws::String>& operations);
111
-
112
- /* *
113
- * Sets product information to include in the JSON output.
114
- * @param productId Product identifier (e.g., "cpp1")
115
- * @param sdkVersion SDK version string
116
- * @param commitId Git commit identifier
117
- */
118
- static void SetProductInfo (const Aws::String& productId, const Aws::String& sdkVersion, const Aws::String& commitId);
119
-
120
- /* *
121
- * Sets the output filename for the JSON performance report.
122
- * @param filename Path to output file (e.g., "s3-perf-results.json")
118
+ * Helper method to process request metrics and store in context.
119
+ * @param serviceName Name of the AWS service
120
+ * @param requestName Name of the operation
121
+ * @param request HTTP request object
122
+ * @param metricsFromCore Core metrics collection containing latency data
123
+ * @param context Request context
123
124
*/
124
- static void SetOutputFilename (const Aws::String& filename);
125
+ void StoreLatencyInContext (const Aws::String& serviceName, const Aws::String& requestName,
126
+ const std::shared_ptr<const Aws::Http::HttpRequest>& request,
127
+ const Aws::Monitoring::CoreMetricsCollection& metricsFromCore, void * context) const ;
125
128
126
- private:
127
129
/* *
128
- * Adds a performance record for a completed AWS service operation.
129
- * @param serviceName Name of the AWS service (e.g., "S3", "DynamoDB")
130
- * @param requestName Name of the operation (e.g., "PutObject", "GetItem")
131
- * @param metricsFromCore Core metrics collection containing latency data
130
+ * Adds a performance record with a specified duration.
131
+ * @param serviceName Name of the AWS service
132
+ * @param requestName Name of the operation
133
+ * @param request HTTP request object
134
+ * @param durationMs Duration of the request in milliseconds
132
135
*/
133
136
void AddPerformanceRecord (const Aws::String& serviceName, const Aws::String& requestName,
134
- const Aws::Monitoring::CoreMetricsCollection& metricsFromCore ) const ;
137
+ const std::shared_ptr< const Aws::Http::HttpRequest>& request, const std::variant< int64_t , double >& durationMs ) const ;
135
138
136
139
/* *
137
140
* Outputs aggregated performance metrics to JSON file.
138
141
* Groups records by name and dimensions, then writes to configured output file.
139
142
*/
140
143
void DumpJson () const ;
141
144
145
+ /* *
146
+ * Writes JSON to the output file.
147
+ * @param root The JSON root object to write
148
+ */
149
+ void WriteJsonToFile (const Aws::Utils::Json::JsonValue& root) const ;
150
+
142
151
mutable Aws::Vector<PerformanceMetricRecord> m_performanceRecords;
143
- static Aws::Vector<std::pair< Aws::String, Aws::String>> TestDimensions ;
144
- static Aws::Set<Aws:: String> MonitoredOperations ;
145
- static Aws::String ProductId ;
146
- static Aws::String SdkVersion ;
147
- static Aws::String CommitId ;
148
- static Aws::String OutputFilename ;
152
+ Aws::Set< Aws::String> m_monitoredOperations ;
153
+ Aws::String m_productId ;
154
+ Aws::String m_sdkVersion ;
155
+ Aws::String m_commitId ;
156
+ Aws::String m_outputFilename ;
157
+ mutable bool m_hasInvalidLatency ;
149
158
};
150
159
151
160
/* *
@@ -154,12 +163,32 @@ class JsonReportingMetrics : public Aws::Monitoring::MonitoringInterface {
154
163
*/
155
164
class JsonReportingMetricsFactory : public Aws ::Monitoring::MonitoringFactory {
156
165
public:
166
+ /* *
167
+ * Constructor that initializes the factory with configuration parameters.
168
+ * @param monitoredOperations Set of operations to monitor (empty means monitor all)
169
+ * @param productId Product identifier (e.g., "cpp1")
170
+ * @param sdkVersion SDK version string
171
+ * @param commitId Git commit identifier
172
+ * @param outputFilename Path to output file (e.g., "s3-perf-results.json")
173
+ */
174
+ JsonReportingMetricsFactory (const Aws::Set<Aws::String>& monitoredOperations = Aws::Set<Aws::String>(),
175
+ const Aws::String& productId = " unknown" , const Aws::String& sdkVersion = " unknown" ,
176
+ const Aws::String& commitId = " unknown" , const Aws::String& outputFilename = " performance-test-results.json" );
177
+
157
178
~JsonReportingMetricsFactory () override = default ;
179
+
158
180
/* *
159
181
* Creates a new JsonReportingMetrics instance for performance monitoring.
160
182
* @return Unique pointer to monitoring interface implementation
161
183
*/
162
184
Aws::UniquePtr<Aws::Monitoring::MonitoringInterface> CreateMonitoringInstance () const override ;
185
+
186
+ private:
187
+ Aws::Set<Aws::String> m_monitoredOperations;
188
+ Aws::String m_productId;
189
+ Aws::String m_sdkVersion;
190
+ Aws::String m_commitId;
191
+ Aws::String m_outputFilename;
163
192
};
164
193
} // namespace Reporting
165
194
} // namespace PerformanceTest
0 commit comments