2020-06-16 14:28:02 -04:00
|
|
|
using ARMeilleure.State;
|
2021-05-13 14:05:15 -04:00
|
|
|
using Ryujinx.Common;
|
2020-12-17 14:32:09 -05:00
|
|
|
using Ryujinx.Common.Logging;
|
2020-06-16 14:28:02 -04:00
|
|
|
using System;
|
2021-05-13 14:05:15 -04:00
|
|
|
using System.Buffers.Binary;
|
2020-12-17 14:32:09 -05:00
|
|
|
using System.Collections.Concurrent;
|
2020-06-16 14:28:02 -04:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO.Compression;
|
2021-05-13 14:05:15 -04:00
|
|
|
using System.Runtime.CompilerServices;
|
2021-02-21 21:23:48 -05:00
|
|
|
using System.Runtime.InteropServices;
|
2020-06-16 14:28:02 -04:00
|
|
|
using System.Threading;
|
|
|
|
|
2021-02-21 21:23:48 -05:00
|
|
|
using static ARMeilleure.Translation.PTC.PtcFormatter;
|
|
|
|
|
2020-06-16 14:28:02 -04:00
|
|
|
namespace ARMeilleure.Translation.PTC
|
|
|
|
{
|
2023-01-04 18:01:44 -05:00
|
|
|
class PtcProfiler
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
2021-05-13 14:05:15 -04:00
|
|
|
private const string OuterHeaderMagicString = "Pohd\0\0\0\0";
|
2020-12-17 14:32:09 -05:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
private const uint InternalVersion = 1866; //! Not to be incremented manually for each change to the ARMeilleure project.
|
2020-12-17 14:32:09 -05:00
|
|
|
|
2020-06-16 14:28:02 -04:00
|
|
|
private const int SaveInterval = 30; // Seconds.
|
|
|
|
|
|
|
|
private const CompressionLevel SaveCompressionLevel = CompressionLevel.Fastest;
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private readonly Ptc _ptc;
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private readonly System.Timers.Timer _timer;
|
2021-05-13 14:05:15 -04:00
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private readonly ulong _outerHeaderMagic;
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private readonly ManualResetEvent _waitEvent;
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private readonly object _lock;
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private bool _disposed;
|
2021-02-21 21:23:48 -05:00
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private Hash128 _lastHash;
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public Dictionary<ulong, FuncProfile> ProfiledFuncs { get; private set; }
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public bool Enabled { get; private set; }
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public ulong StaticCodeStart { get; set; }
|
|
|
|
public ulong StaticCodeSize { get; set; }
|
|
|
|
|
|
|
|
public PtcProfiler(Ptc ptc)
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
2023-01-04 18:01:44 -05:00
|
|
|
_ptc = ptc;
|
|
|
|
|
2020-06-16 14:28:02 -04:00
|
|
|
_timer = new System.Timers.Timer((double)SaveInterval * 1000d);
|
|
|
|
_timer.Elapsed += PreSave;
|
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
_outerHeaderMagic = BinaryPrimitives.ReadUInt64LittleEndian(EncodingCache.UTF8NoBOM.GetBytes(OuterHeaderMagicString).AsSpan());
|
|
|
|
|
2020-06-16 14:28:02 -04:00
|
|
|
_waitEvent = new ManualResetEvent(true);
|
|
|
|
|
|
|
|
_lock = new object();
|
|
|
|
|
|
|
|
_disposed = false;
|
|
|
|
|
2021-02-21 21:23:48 -05:00
|
|
|
ProfiledFuncs = new Dictionary<ulong, FuncProfile>();
|
2020-06-16 14:28:02 -04:00
|
|
|
|
|
|
|
Enabled = false;
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public void AddEntry(ulong address, ExecutionMode mode, bool highCq)
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
|
|
|
if (IsAddressInStaticCodeRange(address))
|
|
|
|
{
|
2020-12-17 14:32:09 -05:00
|
|
|
Debug.Assert(!highCq);
|
|
|
|
|
2020-06-16 14:28:02 -04:00
|
|
|
lock (_lock)
|
|
|
|
{
|
2021-02-21 21:23:48 -05:00
|
|
|
ProfiledFuncs.TryAdd(address, new FuncProfile(mode, highCq: false));
|
2020-06-16 14:28:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public void UpdateEntry(ulong address, ExecutionMode mode, bool highCq)
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
|
|
|
if (IsAddressInStaticCodeRange(address))
|
|
|
|
{
|
2020-12-17 14:32:09 -05:00
|
|
|
Debug.Assert(highCq);
|
|
|
|
|
2020-06-16 14:28:02 -04:00
|
|
|
lock (_lock)
|
|
|
|
{
|
2020-12-17 14:32:09 -05:00
|
|
|
Debug.Assert(ProfiledFuncs.ContainsKey(address));
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2021-02-21 21:23:48 -05:00
|
|
|
ProfiledFuncs[address] = new FuncProfile(mode, highCq: true);
|
2020-06-16 14:28:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public bool IsAddressInStaticCodeRange(ulong address)
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
2020-12-17 14:32:09 -05:00
|
|
|
return address >= StaticCodeStart && address < StaticCodeStart + StaticCodeSize;
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public ConcurrentQueue<(ulong address, FuncProfile funcProfile)> GetProfiledFuncsToTranslate(TranslatorCache<TranslatedFunction> funcs)
|
2020-12-17 14:32:09 -05:00
|
|
|
{
|
2021-05-13 14:05:15 -04:00
|
|
|
var profiledFuncsToTranslate = new ConcurrentQueue<(ulong address, FuncProfile funcProfile)>();
|
2020-12-17 14:32:09 -05:00
|
|
|
|
2020-12-23 21:58:36 -05:00
|
|
|
foreach (var profiledFunc in ProfiledFuncs)
|
2020-12-17 14:32:09 -05:00
|
|
|
{
|
2021-05-13 14:05:15 -04:00
|
|
|
if (!funcs.ContainsKey(profiledFunc.Key))
|
2020-12-17 14:32:09 -05:00
|
|
|
{
|
2021-05-13 14:05:15 -04:00
|
|
|
profiledFuncsToTranslate.Enqueue((profiledFunc.Key, profiledFunc.Value));
|
2020-12-17 14:32:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return profiledFuncsToTranslate;
|
2020-06-16 14:28:02 -04:00
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public void ClearEntries()
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
|
|
|
ProfiledFuncs.Clear();
|
2021-02-21 21:23:48 -05:00
|
|
|
ProfiledFuncs.TrimExcess();
|
2020-06-16 14:28:02 -04:00
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public void PreLoad()
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
2021-05-13 14:05:15 -04:00
|
|
|
_lastHash = default;
|
2021-02-21 21:23:48 -05:00
|
|
|
|
2023-01-18 17:25:16 -05:00
|
|
|
string fileNameActual = $"{_ptc.CachePathActual}.info";
|
|
|
|
string fileNameBackup = $"{_ptc.CachePathBackup}.info";
|
2020-06-16 14:28:02 -04:00
|
|
|
|
|
|
|
FileInfo fileInfoActual = new FileInfo(fileNameActual);
|
|
|
|
FileInfo fileInfoBackup = new FileInfo(fileNameBackup);
|
|
|
|
|
|
|
|
if (fileInfoActual.Exists && fileInfoActual.Length != 0L)
|
|
|
|
{
|
2020-12-17 14:32:09 -05:00
|
|
|
if (!Load(fileNameActual, false))
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
|
|
|
if (fileInfoBackup.Exists && fileInfoBackup.Length != 0L)
|
|
|
|
{
|
2020-12-17 14:32:09 -05:00
|
|
|
Load(fileNameBackup, true);
|
2020-06-16 14:28:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fileInfoBackup.Exists && fileInfoBackup.Length != 0L)
|
|
|
|
{
|
2020-12-17 14:32:09 -05:00
|
|
|
Load(fileNameBackup, true);
|
2020-06-16 14:28:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private bool Load(string fileName, bool isBackup)
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
2021-05-13 14:05:15 -04:00
|
|
|
using (FileStream compressedStream = new(fileName, FileMode.Open))
|
|
|
|
using (DeflateStream deflateStream = new(compressedStream, CompressionMode.Decompress, true))
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
2021-05-13 14:05:15 -04:00
|
|
|
OuterHeader outerHeader = DeserializeStructure<OuterHeader>(compressedStream);
|
|
|
|
|
|
|
|
if (!outerHeader.IsHeaderValid())
|
2020-11-19 20:51:59 -05:00
|
|
|
{
|
|
|
|
InvalidateCompressedStream(compressedStream);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
if (outerHeader.Magic != _outerHeaderMagic)
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
|
|
|
InvalidateCompressedStream(compressedStream);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
if (outerHeader.InfoFileVersion != InternalVersion)
|
2020-12-17 14:32:09 -05:00
|
|
|
{
|
|
|
|
InvalidateCompressedStream(compressedStream);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
if (outerHeader.Endianness != Ptc.GetEndianness())
|
2020-12-17 14:32:09 -05:00
|
|
|
{
|
|
|
|
InvalidateCompressedStream(compressedStream);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
using (MemoryStream stream = new MemoryStream())
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
2021-05-13 14:05:15 -04:00
|
|
|
Debug.Assert(stream.Seek(0L, SeekOrigin.Begin) == 0L && stream.Length == 0L);
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
deflateStream.CopyTo(stream);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
InvalidateCompressedStream(compressedStream);
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
2021-02-21 21:23:48 -05:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
Debug.Assert(stream.Position == stream.Length);
|
2020-12-17 14:32:09 -05:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
stream.Seek(0L, SeekOrigin.Begin);
|
2020-12-17 14:32:09 -05:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
Hash128 expectedHash = DeserializeStructure<Hash128>(stream);
|
2020-12-17 14:32:09 -05:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
Hash128 actualHash = XXHash128.ComputeHash(GetReadOnlySpan(stream));
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
if (actualHash != expectedHash)
|
|
|
|
{
|
|
|
|
InvalidateCompressedStream(compressedStream);
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
return false;
|
|
|
|
}
|
2020-12-17 14:32:09 -05:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
ProfiledFuncs = Deserialize(stream);
|
2020-12-17 14:32:09 -05:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
Debug.Assert(stream.Position == stream.Length);
|
2020-12-17 14:32:09 -05:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
_lastHash = actualHash;
|
|
|
|
}
|
2020-12-17 14:32:09 -05:00
|
|
|
}
|
2021-05-13 14:05:15 -04:00
|
|
|
|
|
|
|
long fileSize = new FileInfo(fileName).Length;
|
|
|
|
|
|
|
|
Logger.Info?.Print(LogClass.Ptc, $"{(isBackup ? "Loaded Backup Profiling Info" : "Loaded Profiling Info")} (size: {fileSize} bytes, profiled functions: {ProfiledFuncs.Count}).");
|
|
|
|
|
|
|
|
return true;
|
2020-12-17 14:32:09 -05:00
|
|
|
}
|
|
|
|
|
2021-02-21 21:23:48 -05:00
|
|
|
private static Dictionary<ulong, FuncProfile> Deserialize(Stream stream)
|
2020-12-17 14:32:09 -05:00
|
|
|
{
|
2021-02-21 21:23:48 -05:00
|
|
|
return DeserializeDictionary<ulong, FuncProfile>(stream, (stream) => DeserializeStructure<FuncProfile>(stream));
|
2020-12-17 14:32:09 -05:00
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private ReadOnlySpan<byte> GetReadOnlySpan(MemoryStream memoryStream)
|
2021-05-13 14:05:15 -04:00
|
|
|
{
|
|
|
|
return new(memoryStream.GetBuffer(), (int)memoryStream.Position, (int)memoryStream.Length - (int)memoryStream.Position);
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private void InvalidateCompressedStream(FileStream compressedStream)
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
|
|
|
compressedStream.SetLength(0L);
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private void PreSave(object source, System.Timers.ElapsedEventArgs e)
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
|
|
|
_waitEvent.Reset();
|
|
|
|
|
2023-01-18 17:25:16 -05:00
|
|
|
string fileNameActual = $"{_ptc.CachePathActual}.info";
|
|
|
|
string fileNameBackup = $"{_ptc.CachePathBackup}.info";
|
2020-06-16 14:28:02 -04:00
|
|
|
|
|
|
|
FileInfo fileInfoActual = new FileInfo(fileNameActual);
|
|
|
|
|
|
|
|
if (fileInfoActual.Exists && fileInfoActual.Length != 0L)
|
|
|
|
{
|
|
|
|
File.Copy(fileNameActual, fileNameBackup, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Save(fileNameActual);
|
|
|
|
|
|
|
|
_waitEvent.Set();
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private void Save(string fileName)
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
2020-12-17 14:32:09 -05:00
|
|
|
int profiledFuncsCount;
|
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
OuterHeader outerHeader = new OuterHeader();
|
|
|
|
|
|
|
|
outerHeader.Magic = _outerHeaderMagic;
|
|
|
|
|
|
|
|
outerHeader.InfoFileVersion = InternalVersion;
|
|
|
|
outerHeader.Endianness = Ptc.GetEndianness();
|
|
|
|
|
|
|
|
outerHeader.SetHeaderHash();
|
|
|
|
|
2020-06-16 14:28:02 -04:00
|
|
|
using (MemoryStream stream = new MemoryStream())
|
|
|
|
{
|
2021-05-13 14:05:15 -04:00
|
|
|
Debug.Assert(stream.Seek(0L, SeekOrigin.Begin) == 0L && stream.Length == 0L);
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
stream.Seek((long)Unsafe.SizeOf<Hash128>(), SeekOrigin.Begin);
|
2020-12-17 14:32:09 -05:00
|
|
|
|
2020-06-16 14:28:02 -04:00
|
|
|
lock (_lock)
|
|
|
|
{
|
2020-12-17 14:32:09 -05:00
|
|
|
Serialize(stream, ProfiledFuncs);
|
|
|
|
|
|
|
|
profiledFuncsCount = ProfiledFuncs.Count;
|
2020-06-16 14:28:02 -04:00
|
|
|
}
|
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
Debug.Assert(stream.Position == stream.Length);
|
|
|
|
|
|
|
|
stream.Seek((long)Unsafe.SizeOf<Hash128>(), SeekOrigin.Begin);
|
|
|
|
Hash128 hash = XXHash128.ComputeHash(GetReadOnlySpan(stream));
|
2020-06-16 14:28:02 -04:00
|
|
|
|
|
|
|
stream.Seek(0L, SeekOrigin.Begin);
|
2021-05-13 14:05:15 -04:00
|
|
|
SerializeStructure(stream, hash);
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
if (hash == _lastHash)
|
2021-02-21 21:23:48 -05:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
using (FileStream compressedStream = new(fileName, FileMode.OpenOrCreate))
|
|
|
|
using (DeflateStream deflateStream = new(compressedStream, SaveCompressionLevel, true))
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-05-13 14:05:15 -04:00
|
|
|
SerializeStructure(compressedStream, outerHeader);
|
|
|
|
|
2020-06-16 14:28:02 -04:00
|
|
|
stream.WriteTo(deflateStream);
|
2021-02-21 21:23:48 -05:00
|
|
|
|
|
|
|
_lastHash = hash;
|
2020-06-16 14:28:02 -04:00
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
compressedStream.Position = 0L;
|
2021-02-21 21:23:48 -05:00
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
_lastHash = default;
|
2020-06-16 14:28:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (compressedStream.Position < compressedStream.Length)
|
|
|
|
{
|
|
|
|
compressedStream.SetLength(compressedStream.Position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-17 14:32:09 -05:00
|
|
|
|
|
|
|
long fileSize = new FileInfo(fileName).Length;
|
|
|
|
|
2021-02-21 21:23:48 -05:00
|
|
|
if (fileSize != 0L)
|
|
|
|
{
|
|
|
|
Logger.Info?.Print(LogClass.Ptc, $"Saved Profiling Info (size: {fileSize} bytes, profiled functions: {profiledFuncsCount}).");
|
|
|
|
}
|
2020-12-17 14:32:09 -05:00
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
private void Serialize(Stream stream, Dictionary<ulong, FuncProfile> profiledFuncs)
|
2020-12-17 14:32:09 -05:00
|
|
|
{
|
2021-02-21 21:23:48 -05:00
|
|
|
SerializeDictionary(stream, profiledFuncs, (stream, structure) => SerializeStructure(stream, structure));
|
2020-12-17 14:32:09 -05:00
|
|
|
}
|
|
|
|
|
2021-05-13 14:05:15 -04:00
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1/*, Size = 29*/)]
|
|
|
|
private struct OuterHeader
|
2020-12-17 14:32:09 -05:00
|
|
|
{
|
2021-05-13 14:05:15 -04:00
|
|
|
public ulong Magic;
|
2020-12-17 14:32:09 -05:00
|
|
|
|
|
|
|
public uint InfoFileVersion;
|
2021-05-13 14:05:15 -04:00
|
|
|
|
|
|
|
public bool Endianness;
|
|
|
|
|
|
|
|
public Hash128 HeaderHash;
|
|
|
|
|
|
|
|
public void SetHeaderHash()
|
|
|
|
{
|
|
|
|
Span<OuterHeader> spanHeader = MemoryMarshal.CreateSpan(ref this, 1);
|
|
|
|
|
|
|
|
HeaderHash = XXHash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader).Slice(0, Unsafe.SizeOf<OuterHeader>() - Unsafe.SizeOf<Hash128>()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsHeaderValid()
|
|
|
|
{
|
|
|
|
Span<OuterHeader> spanHeader = MemoryMarshal.CreateSpan(ref this, 1);
|
|
|
|
|
|
|
|
return XXHash128.ComputeHash(MemoryMarshal.AsBytes(spanHeader).Slice(0, Unsafe.SizeOf<OuterHeader>() - Unsafe.SizeOf<Hash128>())) == HeaderHash;
|
|
|
|
}
|
2020-06-16 14:28:02 -04:00
|
|
|
}
|
|
|
|
|
2021-02-21 21:23:48 -05:00
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1/*, Size = 5*/)]
|
2023-01-04 18:01:44 -05:00
|
|
|
public struct FuncProfile
|
2021-02-21 21:23:48 -05:00
|
|
|
{
|
|
|
|
public ExecutionMode Mode;
|
|
|
|
public bool HighCq;
|
|
|
|
|
|
|
|
public FuncProfile(ExecutionMode mode, bool highCq)
|
|
|
|
{
|
|
|
|
Mode = mode;
|
|
|
|
HighCq = highCq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public void Start()
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
2023-01-04 18:01:44 -05:00
|
|
|
if (_ptc.State == PtcState.Enabled ||
|
|
|
|
_ptc.State == PtcState.Continuing)
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
|
|
|
Enabled = true;
|
|
|
|
|
|
|
|
_timer.Enabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public void Stop()
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
|
|
|
Enabled = false;
|
|
|
|
|
|
|
|
if (!_disposed)
|
|
|
|
{
|
|
|
|
_timer.Enabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public void Wait()
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
|
|
|
_waitEvent.WaitOne();
|
|
|
|
}
|
|
|
|
|
2023-01-04 18:01:44 -05:00
|
|
|
public void Dispose()
|
2020-06-16 14:28:02 -04:00
|
|
|
{
|
|
|
|
if (!_disposed)
|
|
|
|
{
|
|
|
|
_disposed = true;
|
|
|
|
|
|
|
|
_timer.Elapsed -= PreSave;
|
|
|
|
_timer.Dispose();
|
|
|
|
|
|
|
|
Wait();
|
|
|
|
_waitEvent.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-12 21:24:36 -04:00
|
|
|
}
|