From 6001da2866a62da4d1a9454c3df3e8c8c25ae744 Mon Sep 17 00:00:00 2001 From: doterop Date: Fri, 26 Mar 2021 08:51:04 +0100 Subject: [PATCH] Added scoped timer --- .../Plugins/Carla/Source/Carla/Util/Timer.h | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/Timer.h diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/Timer.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/Timer.h new file mode 100644 index 000000000..19e254391 --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Util/Timer.h @@ -0,0 +1,36 @@ +// Copyright (c) 2021 Computer Vision Center (CVC) at the Universitat Autonoma +// de Barcelona (UAB). +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "Misc/DateTime.h" + +struct ScopedTimer +{ + + ScopedTimer(FString msg) + { + Msg = msg; + StartTime = FDateTime::UtcNow(); + StartTimestamp = StartTime.ToUnixTimestamp() * 1000 + StartTime.GetMillisecond(); + start = FPlatformTime::Seconds(); + } + + ~ScopedTimer() + { + FDateTime StopTime = FDateTime::UtcNow(); + int64 StopTimestamp = StopTime.ToUnixTimestamp() * 1000 + StopTime.GetMillisecond(); + double end = FPlatformTime::Seconds(); + UE_LOG(LogCarla, Error, TEXT("%s - Timer = %d ms Platform = %f ms"), + *Msg, StopTimestamp-StartTimestamp, (end - start) * 1000.0f); + } + + FString Msg; + FDateTime StartTime; + int64 StartTimestamp; + double start; + +}; \ No newline at end of file