// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using EpicGames.Core; using UnrealBuildBase; using UnrealBuildTool; namespace AutomationTool.Benchmark { [Flags] public enum UBTBuildOptions { None = 0, PreClean = 1 << 0, // don't preclean before the job (useful for testing) PostClean = 1 << 1, // clean after the job (default for building multiple clients) CleanOnly = 1 << 2, } [Flags] public enum DDCTaskOptions { None = 0, WarmDDC = 1 << 0, ColdDDCNoShared = 1 << 1, ColdDDC = 1 << 2, NoShaderDDC = 1 << 3, HotDDC = 1 << 4, KeepMemoryDDC = 1 << 6, } [Flags] public enum XGETaskOptions { None = 0, NoXGE = 1 << 1, WithXGE = 1 << 2, NoEditorXGE = 1 << 3, // don't use XGE for shader compilation WithEditorXGE = 1 << 4, // don't use XGE for shader compilation } /// /// Simple class that describes a target in a project /// class ProjectTargetInfo { public FileReference ProjectFile { get; private set; } public UnrealTargetPlatform TargetPlatform { get; private set; } public bool BuildTargetAsClient { get; private set; } public ProjectTargetInfo(FileReference InFileReference, UnrealTargetPlatform InTargetPlatform, bool InBuildTargetAsClient) { ProjectFile = InFileReference; TargetPlatform = InTargetPlatform; BuildTargetAsClient = InBuildTargetAsClient; } } /// /// 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; 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 post-task cleanup /// virtual protected void PerformCleanup() { } /// /// Perform the actual task that is measured /// protected abstract bool PerformTask(); /// /// Return a name for this task for reporting /// /// public string TaskName { get; set; } /// /// A list of modifiers that can be considered when /// protected List TaskModifiers { get { return InternalModifiers; } } private readonly List InternalModifiers = new List(); /// /// Run the task. Performs any prerequisites, then the actual task itself /// public void Run() { try { if (PerformPrequisites()) { StartTime = DateTime.Now; if (!PerformTask()) { FailureString = "Task Failed"; Failed = true; } } else { FailureString = "Prequisites Failed"; Failed = true; } } catch (Exception Ex) { FailureString = string.Format("Exception: {0}", Ex.ToString()); Failed = true; } if (StartTime != DateTime.MinValue) { TaskTime = DateTime.Now - StartTime; } if (Failed) { Log.TraceError("{0} failed. {1}", GetFullTaskName(), FailureString); } try { PerformCleanup(); } catch (Exception Ex) { Log.TraceError("Cleanup of {0} failed. {1}", GetFullTaskName(), Ex); } } /// /// Report how long the task took /// public void Report() { if (!Failed) { Log.TraceInformation("Task {0}:\t\t\t\t{1}", GetFullTaskName(), TaskTime.ToString(@"hh\:mm\:ss")); } else { Log.TraceInformation("Task {0}::\t\t\t\t{1} Failed. {2}", GetFullTaskName(), TaskTime.ToString(@"hh\:mm\:ss"), FailureString); } } /// /// Returns a full name to use in reporting and logging /// /// public string GetFullTaskName() { string Name = TaskName; if (TaskModifiers.Count > 0) { Name = string.Format("{0} ({1})", Name, string.Join(" ", TaskModifiers)); } return Name; } public override string ToString() { return GetFullTaskName(); } } }