perf(wpf): scopeLog 记录函数进出时间

This commit is contained in:
status102
2026-03-03 14:43:52 +08:00
parent 5ac35f33d7
commit 7bca8a592b
3 changed files with 42 additions and 2 deletions

View File

@@ -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;

View 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);
}
}

View File

@@ -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();