You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/AutomatedTesting/Levels/AWS/Metrics/Script/Metrics.lua

80 lines
2.8 KiB
Lua

----------------------------------------------------------------------------------------------------
--
-- All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
-- its licensors.
--
-- For complete copyright and license terms please see the LICENSE at the root of this
-- distribution (the "License"). All use of this software is governed by the License,
-- or, if provided, by the license below or the license accompanying this file. Do not
-- remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--
--
----------------------------------------------------------------------------------------------------
local metrics = {
}
function metrics:OnActivate()
self.tickTime = 0
self.numSubmittedMetricsEvents = 0
self.tickBusHandler = TickBus.Connect(self,self.entityId)
self.metricsNotificationHandler = AWSMetricsNotificationBus.Connect(self, self.entityId)
LyShineLua.ShowMouseCursor(true)
end
function metrics:OnSendMetricsSuccess(requestId)
Debug.Log("Metrics is sent successfully.")
end
function metrics:OnSendMetricsFailure(requestId, errorMessage)
Debug.Log("Failed to send metrics.")
end
function metrics:OnDeactivate()
AWSMetricsRequestBus.Broadcast.FlushMetrics()
Debug.Log("Stop generating new test events and flushed the buffered metrics.")
self.tickBusHandler:Disconnect()
self.metricsNotificationHandler:Disconnect()
end
function metrics:OnTick(deltaTime, timePoint)
self.tickTime = self.tickTime + deltaTime
if self.tickTime > 2.0 then
defaultAttribute = AWSMetrics_MetricsAttribute()
defaultAttribute:SetName("event_name")
defaultAttribute:SetStrValue("login")
customAttribute = AWSMetrics_MetricsAttribute()
customAttribute:SetName("custom_attribute")
customAttribute:SetStrValue("value")
attributeList = AWSMetrics_AttributesSubmissionList()
attributeList.attributes:push_back(defaultAttribute)
attributeList.attributes:push_back(customAttribute)
if self.numSubmittedMetricsEvents % 2 == 0 then
if AWSMetricsRequestBus.Broadcast.SubmitMetrics(attributeList.attributes, 0, "lua", false) then
Debug.Log("Submitted metrics without buffer.")
else
Debug.Log("Failed to Submit metrics without buffer.")
end
else
if AWSMetricsRequestBus.Broadcast.SubmitMetrics(attributeList.attributes, 0, "lua", true) then
Debug.Log("Submitted metrics with buffer.")
else
Debug.Log("Failed to Submit metrics with buffer.")
end
end
self.numSubmittedMetricsEvents = self.numSubmittedMetricsEvents + 1
self.tickTime = 0
end
end
return metrics