Added scoped timer

This commit is contained in:
doterop 2021-03-26 08:51:04 +01:00 committed by bernat
parent 86efe6f581
commit 6001da2866
1 changed files with 36 additions and 0 deletions

View File

@ -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 <https://opensource.org/licenses/MIT>.
#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;
};