// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Tools.DotNETCommon; namespace AutomationTool.Benchmark { /// /// Base class for running tasks /// abstract class BenchmarkTaskBase { /// /// True or false based on whether the task failed /// public bool Failed { get; protected set; } /// /// Failure message /// public string FailureString { get; protected set; } /// /// Don't report this test /// public bool SkipReport { get; protected set; } /// /// Time the task took (does not include prequisites) /// public TimeSpan TaskTime { get; protected set; } /// /// Time the task started /// public DateTime StartTime { get; protected set; } /// /// Perform any prerequisites the task requires /// virtual protected bool PerformPrequisites() { return true; } /// /// Perform the actual task that is measured /// protected abstract bool PerformTask(); /// /// Return a name for this task for reporting /// /// public abstract string GetTaskName(); /// /// Run the task. Performs any prerequisites, then the actual task itself /// public void Run() { try { if (PerformPrequisites()) { StartTime = DateTime.Now; if (PerformTask()) { TaskTime = DateTime.Now - StartTime; } else { FailureString = "Task Failed"; Failed = true; } } else { FailureString = "Prequisites Failed"; Failed = true; } } catch (Exception Ex) { FailureString = string.Format("Exception: {0}", Ex.ToString()); Failed = true; } if (Failed) { Log.TraceError("{0} failed. {1}", GetTaskName(), FailureString); } } /// /// Report how long the task took /// public void Report() { if (!Failed) { Log.TraceInformation("Task {0}:\t\t\t\t{1}", GetTaskName(), TaskTime.ToString(@"hh\:mm\:ss")); } else { Log.TraceInformation("Task {0}::\t\t\t\tFailed. {1}", GetTaskName(), FailureString); } } } }