using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Unity.PerformanceTesting.Exceptions;
using UnityEngine.Profiling;
namespace Unity.PerformanceTesting
{
///
/// Represents a performance test sample group.
///
[Serializable]
public class SampleGroup : IDeserializationCallback
{
///
/// Name of the sample group.
///
public string Name;
///
/// Measurement unit.
///
public SampleUnit Unit;
///
/// Whether the measurement is inverted and increase is positive.
///
public bool IncreaseIsBetter;
///
/// List of samples.
///
public List Samples = new List();
///
/// Minimum value of samples.
///
public double Min;
///
/// Maximum value of samples.
///
public double Max;
///
/// Medina value of samples.
///
public double Median;
///
/// Average value of samples.
///
public double Average;
///
/// Standard deviation of samples.
///
public double StandardDeviation;
///
/// Sum of samples.
///
public double Sum;
///
/// Creates a new sample group with given parameters.
///
/// Name of the sample group.
/// Unit of measurement.
/// Whether the measurement is inverted and increase is positive.
/// Exception can be thrown if empty or null name is provided.
public SampleGroup(string name, SampleUnit unit = SampleUnit.Millisecond, bool increaseIsBetter = false)
{
Name = name;
Unit = unit;
IncreaseIsBetter = increaseIsBetter;
if (string.IsNullOrEmpty(name))
{
throw new PerformanceTestException("Sample group name is empty. Please assign a valid name.");
}
}
internal Recorder Recorder;
///
/// Gets the profiler recorder object.
///
/// Profiler recorder.
public Recorder GetRecorder()
{
return Recorder ?? (Recorder = Recorder.Get(Name));
}
///
/// Validates the deserialized object.
///
/// The object that initiated the deserialization process.
public void OnDeserialization(object sender)
{
if (string.IsNullOrEmpty(Name))
{
throw new PerformanceTestException("Sample group name is empty. Please assign a valid name.");
}
}
}
}