增加日志立即输出模式
parent
6d679d38c1
commit
951bdf7a19
|
@ -9,7 +9,7 @@
|
|||
<OutputPath>../bin</OutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="..\bin\net8.0\FileUtilsCs.dll">
|
||||
<Content Include="..\bin\FileUtilsCs.dll">
|
||||
<Link>FileUtilsCs.dll</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Runtime.InteropServices;
|
|||
unsafe
|
||||
{
|
||||
Console.WriteLine(1);
|
||||
SetLogImmediately(true);
|
||||
SetLogInfo(& LogInfo);
|
||||
SetLogError(& LogError);
|
||||
TimeProvider.System.CreateTimer(Callback, null, TimeSpan.FromMilliseconds(16), TimeSpan.FromMilliseconds(16));
|
||||
|
@ -20,6 +21,8 @@ unsafe
|
|||
(char*)Unsafe.AsPointer(ref Unsafe.AsRef(in "C:\\B".GetPinnableReference())));
|
||||
Console.ReadKey();
|
||||
|
||||
[DllImport("FileUtilsCs.dll", EntryPoint = "SetLogImmediately")]
|
||||
static extern void SetLogImmediately(bool value);
|
||||
[DllImport("FileUtilsCs.dll", EntryPoint = "TestLog")]
|
||||
static extern void TestLog();
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
@ -8,6 +9,7 @@ public class EntryPoints
|
|||
{
|
||||
internal static Action<string>? logInfoAction;
|
||||
internal static Action<string>? logErrorAction;
|
||||
internal static bool logImmediately = false;
|
||||
|
||||
static ConcurrentQueue<string> _logQueue = new ConcurrentQueue<string>();
|
||||
static ConcurrentQueue<string> _logErrorQueue = new ConcurrentQueue<string>();
|
||||
|
@ -15,27 +17,48 @@ public class EntryPoints
|
|||
[UnmanagedCallersOnly(EntryPoint = "Tick")]
|
||||
static void Tick()
|
||||
{
|
||||
if (logImmediately)
|
||||
return;
|
||||
if (_logErrorQueue.TryDequeue(out var error))
|
||||
{
|
||||
logErrorAction?.Invoke(error);
|
||||
}
|
||||
|
||||
_logErrorQueue.Clear();
|
||||
if (_logQueue.TryDequeue(out var message))
|
||||
{
|
||||
logInfoAction?.Invoke(message);
|
||||
}
|
||||
|
||||
_logQueue.Clear();
|
||||
}
|
||||
|
||||
public static void LogError(string message)
|
||||
{
|
||||
_logErrorQueue.Enqueue(message);
|
||||
if (logImmediately)
|
||||
logErrorAction?.Invoke(message);
|
||||
else
|
||||
_logErrorQueue.Enqueue(message);
|
||||
}
|
||||
|
||||
public static void Log(string message)
|
||||
{
|
||||
_logQueue.Enqueue(message);
|
||||
if (logImmediately)
|
||||
logInfoAction?.Invoke(message);
|
||||
else
|
||||
_logQueue.Enqueue(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 立即输出日志
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
[UnmanagedCallersOnly(EntryPoint = "SetLogImmediately")]
|
||||
public static void SetLogImmediately(bool value)
|
||||
{
|
||||
logImmediately = value;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "SetLogInfo")]
|
||||
public static unsafe void SetLogInfo(delegate* managed<nint, void> logAction)
|
||||
{
|
||||
|
@ -51,7 +74,7 @@ public class EntryPoints
|
|||
{
|
||||
logErrorAction = (o) =>
|
||||
{
|
||||
var pp = (nint)Unsafe.AsPointer(ref Unsafe.AsRef(in o.GetPinnableReference()));
|
||||
var pp = (nint)Unsafe.AsPointer(ref Unsafe.AsRef(in o.GetPinnableReference()));
|
||||
logAction(pp);
|
||||
};
|
||||
}
|
||||
|
@ -74,7 +97,7 @@ public class EntryPoints
|
|||
public static unsafe void MoveFolder(char* source, char* destination)
|
||||
{
|
||||
var srcRootPath = new string(source);
|
||||
var destRootPath = new string(destination);
|
||||
var destRootPath = new string(destination);
|
||||
MoveFolder(srcRootPath, destRootPath, true);
|
||||
}
|
||||
|
||||
|
@ -137,4 +160,20 @@ public class EntryPoints
|
|||
LogError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "TestSqrt1M")]
|
||||
static void TestSqrt1M()
|
||||
{
|
||||
float a = 356f;
|
||||
float[] arr = new float[100];
|
||||
arr = Enumerable.Range(0, 100).Select(x => (float)x).ToArray();
|
||||
for (var i = 0; i < 100_0000; i++)
|
||||
{
|
||||
MathF.Sqrt(a);
|
||||
var f = arr[i % 100];
|
||||
Vector4 v = new Vector4(f, f, f, f);
|
||||
var length = v.Length();
|
||||
arr[i % 100] = MathF.Cos(length * MathF.PI / 180);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
dotnet publish -r win-x64 -c Debug -o ../bin
|
||||
dotnet publish -r win-x64 -c Release -o ../bin
|
Loading…
Reference in New Issue