mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
perf(wpf): scopeLog 记录函数进出时间
This commit is contained in:
@@ -44,6 +44,7 @@ using MaaWpfGui.Services;
|
||||
using MaaWpfGui.Services.Notification;
|
||||
using MaaWpfGui.Services.Web;
|
||||
using MaaWpfGui.States;
|
||||
using MaaWpfGui.Utilities;
|
||||
using MaaWpfGui.ViewModels.UI;
|
||||
using MaaWpfGui.ViewModels.UserControl.TaskQueue;
|
||||
using Newtonsoft.Json;
|
||||
@@ -463,7 +464,7 @@ public class AsstProxy
|
||||
/// <returns>是否成功。</returns>
|
||||
public bool LoadResource()
|
||||
{
|
||||
_logger.Information("Load Resource");
|
||||
using var log = new LogScope(_logger);
|
||||
|
||||
string clientType = SettingsViewModel.GameSettings.ClientType;
|
||||
|
||||
|
||||
39
src/MaaWpfGui/Utilities/LogScope.cs
Normal file
39
src/MaaWpfGui/Utilities/LogScope.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
// <copyright file="LogScope.cs" company="MaaAssistantArknights">
|
||||
// Part of the MaaWpfGui project, maintained by the MaaAssistantArknights team (Maa Team)
|
||||
// Copyright (C) 2021-2025 MaaAssistantArknights Contributors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License v3.0 only as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
// </copyright>
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Serilog;
|
||||
|
||||
namespace MaaWpfGui.Utilities;
|
||||
|
||||
public class LogScope : IDisposable
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly string _methodName;
|
||||
private readonly System.Diagnostics.Stopwatch _stopwatch;
|
||||
|
||||
public LogScope(ILogger logger, [CallerMemberName] string methodName = "")
|
||||
{
|
||||
_logger = logger;
|
||||
_methodName = methodName;
|
||||
_stopwatch = System.Diagnostics.Stopwatch.StartNew();
|
||||
_logger.Information("{MethodName} Enter", _methodName);
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
_stopwatch.Stop();
|
||||
_logger.Information("{MethodName} Exit, {Elapsed:#,0} ms", _methodName, _stopwatch.ElapsedMilliseconds);
|
||||
}
|
||||
}
|
||||
@@ -715,7 +715,7 @@ public class FightSettingsUserControlModel : TaskSettingsViewModel, FightSetting
|
||||
public void UpdateStageList()
|
||||
{
|
||||
Execute.PostToUIThreadAsync(() => {
|
||||
_logger.Information("Updating stage list...");
|
||||
using var log = new LogScope(_logger);
|
||||
using var scope = _lock.EnterScope();
|
||||
var stageList = Instances.StageManager.GetStageList();
|
||||
RefreshStageList();
|
||||
|
||||
Reference in New Issue
Block a user