| | | 1 | | #if UNITY_EDITOR |
| | | 2 | | using System; |
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | |
| | | 6 | | namespace Hertzole.ScriptableValues.Debugging |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Represents a stack trace entry with a time stamp. |
| | | 10 | | /// </summary> |
| | | 11 | | public readonly struct StackTraceEntry : IEquatable<StackTraceEntry> |
| | | 12 | | { |
| | | 13 | | // Use bytes to use as little memory as possible. |
| | | 14 | | // It's way more efficient than using DateTime. |
| | | 15 | | // We need to be efficient because these stack traces can easily stack up to 1000s of entries. |
| | | 16 | | public readonly byte hour; |
| | | 17 | | public readonly byte minute; |
| | | 18 | | public readonly byte second; |
| | | 19 | | |
| | | 20 | | public readonly StackTrace trace; |
| | | 21 | | |
| | | 22 | | public StackTraceEntry(StackTrace trace) |
| | 2940 | 23 | | { |
| | 2940 | 24 | | this.trace = trace; |
| | 2940 | 25 | | DateTimeOffset time = DateTimeOffset.Now; |
| | 2940 | 26 | | hour = (byte) time.Hour; |
| | 2940 | 27 | | minute = (byte) time.Minute; |
| | 2940 | 28 | | second = (byte) time.Second; |
| | 2940 | 29 | | } |
| | | 30 | | |
| | | 31 | | public bool Equals(StackTraceEntry other) |
| | 48 | 32 | | { |
| | 48 | 33 | | return hour == other.hour && minute == other.minute && second == other.second && EqualityComparer<StackTrace |
| | 48 | 34 | | } |
| | | 35 | | |
| | | 36 | | public override bool Equals(object obj) |
| | 12 | 37 | | { |
| | 12 | 38 | | return obj is StackTraceEntry other && Equals(other); |
| | 12 | 39 | | } |
| | | 40 | | |
| | | 41 | | public override int GetHashCode() |
| | 24 | 42 | | { |
| | | 43 | | unchecked |
| | 24 | 44 | | { |
| | 24 | 45 | | int hashCode = hour.GetHashCode(); |
| | 24 | 46 | | hashCode = (hashCode * 397) ^ minute.GetHashCode(); |
| | 24 | 47 | | hashCode = (hashCode * 397) ^ second.GetHashCode(); |
| | 24 | 48 | | hashCode = (hashCode * 397) ^ (trace != null ? trace.GetHashCode() : 0); |
| | 24 | 49 | | return hashCode; |
| | | 50 | | } |
| | 24 | 51 | | } |
| | | 52 | | |
| | | 53 | | public static bool operator ==(StackTraceEntry left, StackTraceEntry right) |
| | 12 | 54 | | { |
| | 12 | 55 | | return left.Equals(right); |
| | 12 | 56 | | } |
| | | 57 | | |
| | | 58 | | public static bool operator !=(StackTraceEntry left, StackTraceEntry right) |
| | 12 | 59 | | { |
| | 12 | 60 | | return !left.Equals(right); |
| | 12 | 61 | | } |
| | | 62 | | } |
| | | 63 | | } |
| | | 64 | | #endif |