feat: wpf设置-连接设置新增近期截图耗时

This commit is contained in:
status102
2023-12-04 15:42:48 +08:00
parent 8a549466cd
commit 813763865b
10 changed files with 54 additions and 4 deletions

View File

@@ -4,6 +4,7 @@
#include "Common/AsstConf.h"
#include "Utils/NoWarningCV.h"
#include <cstdint>
#include <numeric>
#ifdef _MSC_VER
#pragma warning(push)
@@ -133,8 +134,8 @@ std::optional<std::string> asst::AdbController::call_command(const std::string&
callcmd_lock.unlock();
auto duration = duration_cast<milliseconds>(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<milliseconds>(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;

View File

@@ -3,6 +3,7 @@
#include "ControllerAPI.h"
#include <random>
#include <deque>
#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<long long> m_screencap_duration; // 截图用时
int m_screencap_time = 0; // 截图次数
};
} // namespace asst

View File

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

View File

@@ -238,6 +238,7 @@
<system:String x:Key="EndsWithScript">Ends with Script</system:String>
<system:String x:Key="BlockSleep">Prevent hibernation when running tasks</system:String>
<system:String x:Key="BlockSleepWithScreenOn">Keep screen on when preventing hibernation</system:String>
<system:String x:Key="ScreencapCost">Screencap Cost min/avg/max(ms): {0:#,#} / {1:#,#} / {2:#,#} ({3})</system:String>
<system:String x:Key="RoguelikeTheme">I.S. Theme</system:String>
<system:String x:Key="RoguelikeThemePhantom">Phantom</system:String>
<system:String x:Key="RoguelikeThemeMizuki">Mizuki</system:String>

View File

@@ -238,6 +238,7 @@
<system:String x:Key="EndsWithScript">終了時にスクリプトを使用します</system:String>
<system:String x:Key="BlockSleep">タスク実行時の休止状態の防止</system:String>
<system:String x:Key="BlockSleepWithScreenOn">休止状態を防ぐときは画面をオンのままにします</system:String>
<system:String x:Key="ScreencapCost">スクリーンショットの撮影には時間がかかります min/avg/max(ms): {0:#,#} / {1:#,#} / {2:#,#} ({3})</system:String>
<system:String x:Key="RoguelikeTheme">主題</system:String>
<system:String x:Key="RoguelikeThemePhantom">ファントム</system:String>
<system:String x:Key="RoguelikeThemeMizuki">ミヅキ</system:String>

View File

@@ -238,6 +238,7 @@
<system:String x:Key="EndsWithScript">종료 시 추가 스크립트</system:String>
<system:String x:Key="BlockSleep">작업 실행 시 절전 모드 차단</system:String>
<system:String x:Key="BlockSleepWithScreenOn">절전 모드 방지 시 항상 밝게 표시</system:String>
<system:String x:Key="ScreencapCost">스크린샷을 찍는 데는 시간이 걸립니다 min/avg/max(ms): {0:#,#} / {1:#,#} / {2:#,#} ({3})</system:String>
<system:String x:Key="RoguelikeTheme">통합전략 테마</system:String>
<system:String x:Key="RoguelikeThemePhantom">팬텀</system:String>
<system:String x:Key="RoguelikeThemeMizuki">미즈키</system:String>

View File

@@ -238,6 +238,7 @@
<system:String x:Key="EndsWithScript">结束后脚本</system:String>
<system:String x:Key="BlockSleep">运行任务时阻止休眠</system:String>
<system:String x:Key="BlockSleepWithScreenOn">阻止休眠时保持屏幕常亮</system:String>
<system:String x:Key="ScreencapCost">截图耗时 min/avg/max(ms): {0:#,#} / {1:#,#} / {2:#,#} ({3})</system:String>
<system:String x:Key="RoguelikeTheme">肉鸽主题</system:String>
<system:String x:Key="RoguelikeThemePhantom">傀影</system:String>
<system:String x:Key="RoguelikeThemeMizuki">水月</system:String>

View File

@@ -238,6 +238,7 @@
<system:String x:Key="EndsWithScript">結束後腳本</system:String>
<system:String x:Key="BlockSleep">運行任務時阻止休眠</system:String>
<system:String x:Key="BlockSleepWithScreenOn">阻止休眠時保持螢幕常亮</system:String>
<system:String x:Key="ScreencapCost">截圖耗時 min/avg/max(ms): {0:#,#} / {1:#,#} / {2:#,#} ({3})</system:String>
<system:String x:Key="RoguelikeTheme">肉鴿主題</system:String>
<system:String x:Key="RoguelikeThemePhantom">傀影</system:String>
<system:String x:Key="RoguelikeThemeMizuki">水月</system:String>

View File

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

View File

@@ -34,6 +34,7 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel
Grid.Row="0"
@@ -271,7 +272,13 @@
VerticalAlignment="Center"
Content="{DynamicResource BlockSleepWithScreenOn}"
IsChecked="{Binding BlockSleepWithScreenOn}"
Visibility="{c:Binding BlockSleep}"/>
Visibility="{c:Binding BlockSleep}" />
</StackPanel>
<controls:TextBlock
Grid.Row="11"
Grid.Column="0"
Grid.ColumnSpan="3"
HorizontalAlignment="Center"
Text="{c:Binding ScreencapCost}" />
</Grid>
</UserControl>