diff --git a/tests/performance-tests/include/performance-tests/reporting/JsonReportingMetrics.h b/tests/performance-tests/include/performance-tests/reporting/JsonReportingMetrics.h index 9320e3caca6..e99485a1846 100644 --- a/tests/performance-tests/include/performance-tests/reporting/JsonReportingMetrics.h +++ b/tests/performance-tests/include/performance-tests/reporting/JsonReportingMetrics.h @@ -37,6 +37,11 @@ struct PerformanceMetricRecord { Aws::Map dimensions; }; +/** + * Context will be shared between monitor invocations. + */ +struct RequestContext; + /** * An implementation of the MonitoringInterface that collects performance metrics * and reports them in a JSON format. @@ -150,6 +155,7 @@ class JsonReportingMetrics : public Aws::Monitoring::MonitoringInterface { void WriteJsonToFile(const Aws::Utils::Json::JsonValue& root) const; mutable Aws::Vector m_performanceRecords; + mutable Aws::UnorderedMap> m_requestContexts; Aws::Set m_monitoredOperations; Aws::String m_productId; Aws::String m_sdkVersion; diff --git a/tests/performance-tests/src/reporting/JsonReportingMetrics.cpp b/tests/performance-tests/src/reporting/JsonReportingMetrics.cpp index 997d4d9ec68..213f0af3f95 100644 --- a/tests/performance-tests/src/reporting/JsonReportingMetrics.cpp +++ b/tests/performance-tests/src/reporting/JsonReportingMetrics.cpp @@ -27,7 +27,8 @@ using namespace PerformanceTest::Reporting; -struct RequestContext { +struct PerformanceTest::Reporting::RequestContext { + Aws::Utils::UUID requestId{Aws::Utils::UUID::RandomUUID()}; Aws::String serviceName; Aws::String requestName; std::shared_ptr request; @@ -107,8 +108,10 @@ void JsonReportingMetrics::AddPerformanceRecord(const Aws::String& serviceName, void* JsonReportingMetrics::OnRequestStarted(const Aws::String&, const Aws::String&, const std::shared_ptr&) const { - auto context = Aws::New("RequestContext"); - return context; + auto context = Aws::MakeUnique("RequestContext"); + auto requestID = context->requestId; + m_requestContexts.emplace(requestID, std::move(context)); + return m_requestContexts[requestID].get(); } void JsonReportingMetrics::OnRequestSucceeded(const Aws::String& serviceName, const Aws::String& requestName, @@ -136,7 +139,7 @@ void JsonReportingMetrics::OnFinish(const Aws::String&, const Aws::String&, cons AddPerformanceRecord(requestContext->serviceName, requestContext->requestName, requestContext->request, requestContext->durationMs); } - Aws::Delete(requestContext); + m_requestContexts.erase(requestContext->requestId); } void JsonReportingMetrics::DumpJson() const {