diff --git a/src/MaaCore/Controller/AdbController.cpp b/src/MaaCore/Controller/AdbController.cpp index 716710536d..8f72405ae6 100644 --- a/src/MaaCore/Controller/AdbController.cpp +++ b/src/MaaCore/Controller/AdbController.cpp @@ -4,6 +4,7 @@ #include "Common/AsstConf.h" #include "Utils/NoWarningCV.h" #include +#include #ifdef _MSC_VER #pragma warning(push) @@ -133,8 +134,8 @@ std::optional asst::AdbController::call_command(const std::string& callcmd_lock.unlock(); - auto duration = duration_cast(steady_clock::now() - start_time).count(); - Log.info("Call `", cmd, "` ret", exit_ret, ", cost", duration, "ms , stdout size:", pipe_data.size(), + m_last_command_duration = duration_cast(steady_clock::now() - start_time).count(); + Log.info("Call `", cmd, "` ret", exit_ret, ", cost", m_last_command_duration, "ms , stdout size:", pipe_data.size(), ", socket size:", sock_data.size()); if (!pipe_data.empty() && pipe_data.size() < 4096) { Log.trace("stdout output:", Logger::separator::newline, pipe_data); @@ -462,9 +463,31 @@ bool asst::AdbController::screencap(const std::string& cmd, const DecodeFunc& de if ((!m_support_socket || !m_server_started) && by_socket) [[unlikely]] { return false; } - auto ret = call_command(cmd, timeout, allow_reconnect, by_socket); + { // 记录截图耗时,每10次截图回传一次最值+平均值 + m_screencap_duration.emplace_back(m_last_command_duration); // 记录截图耗时 + ++m_screencap_time; + if (m_screencap_duration.size() > 30) { + m_screencap_duration.pop_front(); + } + if (m_screencap_time > 9) { // 每 10 次截图计算一次平均耗时 + m_screencap_time = 0; + auto [screencap_cost_min, screencap_cost_max] = ranges::minmax(m_screencap_duration); + json::value info = json::object { + { "uuid", m_uuid }, + { "what", "ScreencapCost" }, + { "details", + json::object { + { "min", screencap_cost_min }, + { "max", screencap_cost_max }, + { "avg", std::accumulate(m_screencap_duration.begin(), m_screencap_duration.end(), 0ll) / + m_screencap_duration.size() }, + } }, + }; + callback(AsstMsg::ConnectionInfo, info); + } + } if (!ret || ret.value().empty()) [[unlikely]] { Log.warn("data is empty!"); return false; diff --git a/src/MaaCore/Controller/AdbController.h b/src/MaaCore/Controller/AdbController.h index a8bc579c50..c1c2fb774d 100644 --- a/src/MaaCore/Controller/AdbController.h +++ b/src/MaaCore/Controller/AdbController.h @@ -3,6 +3,7 @@ #include "ControllerAPI.h" #include +#include #include "Platform/PlatformFactory.h" @@ -128,5 +129,8 @@ namespace asst bool m_server_started = false; bool m_inited = false; bool m_kill_adb_on_exit = false; + long long m_last_command_duration = 0; // 上次命令执行用时 + std::deque m_screencap_duration; // 截图用时 + int m_screencap_time = 0; // 截图次数 }; } // namespace asst diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index 702db74a98..9eb5045fea 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -482,6 +482,9 @@ namespace MaaWpfGui.Main Instances.TaskQueueViewModel.AddLog(fastestScreencapStringBuilder.ToString(), color); Instances.CopilotViewModel.AddLog(fastestScreencapStringBuilder.ToString()); break; + case "ScreencapCost": + Instances.SettingsViewModel.ScreencapCost = string.Format(LocalizationHelper.GetString("ScreencapCost"), details["details"]?["min"]?.ToString() ?? "???", details["details"]?["avg"]?.ToString() ?? "???", details["details"]?["max"]?.ToString() ?? "???", DateTimeOffset.Now.ToString("HH:mm:ss")); + break; } } diff --git a/src/MaaWpfGui/Res/Localizations/en-us.xaml b/src/MaaWpfGui/Res/Localizations/en-us.xaml index 212ae3357d..3043153421 100644 --- a/src/MaaWpfGui/Res/Localizations/en-us.xaml +++ b/src/MaaWpfGui/Res/Localizations/en-us.xaml @@ -238,6 +238,7 @@ Ends with Script Prevent hibernation when running tasks Keep screen on when preventing hibernation + Screencap Cost min/avg/max(ms): {0:#,#} / {1:#,#} / {2:#,#} ({3}) I.S. Theme Phantom Mizuki diff --git a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml index 2ffcca9097..345c73417f 100644 --- a/src/MaaWpfGui/Res/Localizations/ja-jp.xaml +++ b/src/MaaWpfGui/Res/Localizations/ja-jp.xaml @@ -238,6 +238,7 @@ 終了時にスクリプトを使用します タスク実行時の休止状態の防止 休止状態を防ぐときは画面をオンのままにします + スクリーンショットの撮影には時間がかかります min/avg/max(ms): {0:#,#} / {1:#,#} / {2:#,#} ({3}) 主題 ファントム ミヅキ diff --git a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml index 977da6bfae..574e32703b 100644 --- a/src/MaaWpfGui/Res/Localizations/ko-kr.xaml +++ b/src/MaaWpfGui/Res/Localizations/ko-kr.xaml @@ -238,6 +238,7 @@ 종료 시 추가 스크립트 작업 실행 시 절전 모드 차단 절전 모드 방지 시 항상 밝게 표시 + 스크린샷을 찍는 데는 시간이 걸립니다 min/avg/max(ms): {0:#,#} / {1:#,#} / {2:#,#} ({3}) 통합전략 테마 팬텀 미즈키 diff --git a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml index 237a808287..5e5953c1ed 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-cn.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-cn.xaml @@ -238,6 +238,7 @@ 结束后脚本 运行任务时阻止休眠 阻止休眠时保持屏幕常亮 + 截图耗时 min/avg/max(ms): {0:#,#} / {1:#,#} / {2:#,#} ({3}) 肉鸽主题 傀影 水月 diff --git a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml index 7010c5ecbc..350b5611f7 100644 --- a/src/MaaWpfGui/Res/Localizations/zh-tw.xaml +++ b/src/MaaWpfGui/Res/Localizations/zh-tw.xaml @@ -238,6 +238,7 @@ 結束後腳本 運行任務時阻止休眠 阻止休眠時保持螢幕常亮 + 截圖耗時 min/avg/max(ms): {0:#,#} / {1:#,#} / {2:#,#} ({3}) 肉鴿主題 傀影 水月 diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index 0b682ecd44..cc9929fcbb 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -853,6 +853,14 @@ namespace MaaWpfGui.ViewModels.UI } } + private string _screencapCost = string.Format(LocalizationHelper.GetString("ScreencapCost"), "---", "---", "---", "---"); + + public string ScreencapCost + { + get => _screencapCost; + set => SetAndNotify(ref _screencapCost, value); + } + public void RunScript(string str) { bool enable = str switch diff --git a/src/MaaWpfGui/Views/UserControl/ConnectSettingsUserControl.xaml b/src/MaaWpfGui/Views/UserControl/ConnectSettingsUserControl.xaml index 4aa1d4d99f..47d7245bf6 100644 --- a/src/MaaWpfGui/Views/UserControl/ConnectSettingsUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/ConnectSettingsUserControl.xaml @@ -34,6 +34,7 @@ + + Visibility="{c:Binding BlockSleep}" /> +