[feat] fps benchmark one-key testing
This commit is contained in:
@@ -6,6 +6,8 @@ use crate::wrap_err;
|
||||
use anyhow::Result;
|
||||
use std::fs::File;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use tauri::path::BaseDirectory;
|
||||
use tauri::Manager;
|
||||
|
||||
@@ -188,3 +190,68 @@ pub async fn analyze_replay(app: tauri::AppHandle, path: &str) -> Result<String,
|
||||
// 返回结果
|
||||
Ok(output_str.to_string())
|
||||
}
|
||||
|
||||
// 帧数测试相关
|
||||
#[tauri::command]
|
||||
pub fn get_console_log_path(cs_path: &str) -> Result<String, String> {
|
||||
// cs_path 是类似 "game\bin\win64" 的路径,需要向上找到 game\csgo\console.log
|
||||
let path = Path::new(cs_path);
|
||||
// 向上找到 game 目录
|
||||
if let Some(game_dir) = path.ancestors().find(|p| {
|
||||
p.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.map(|n| n == "game")
|
||||
.unwrap_or(false)
|
||||
}) {
|
||||
let console_log_path = game_dir.join("csgo").join("console.log");
|
||||
Ok(console_log_path.to_string_lossy().to_string())
|
||||
} else {
|
||||
Err("无法找到 game 目录".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn read_vprof_report(console_log_path: &str) -> Result<String, String> {
|
||||
let path = Path::new(console_log_path);
|
||||
|
||||
if !path.exists() {
|
||||
return Err("console.log 文件不存在".to_string());
|
||||
}
|
||||
|
||||
let file = File::open(path).map_err(|e| format!("无法打开文件: {}", e))?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut vprof_lines = Vec::new();
|
||||
let mut in_vprof_section = false;
|
||||
let mut empty_line_count = 0;
|
||||
|
||||
for line_result in reader.lines() {
|
||||
let line = line_result.map_err(|e| format!("读取行错误: {}", e))?;
|
||||
|
||||
// 检测 [VProf] 标记
|
||||
if line.contains("[VProf]") {
|
||||
in_vprof_section = true;
|
||||
empty_line_count = 0;
|
||||
vprof_lines.push(line.clone());
|
||||
} else if in_vprof_section {
|
||||
// 如果在 VProf 部分中
|
||||
if line.trim().is_empty() {
|
||||
empty_line_count += 1;
|
||||
// 如果遇到两个连续的空行,结束 VProf 部分
|
||||
if empty_line_count >= 2 {
|
||||
break;
|
||||
}
|
||||
vprof_lines.push(line.clone());
|
||||
} else {
|
||||
empty_line_count = 0;
|
||||
vprof_lines.push(line.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if vprof_lines.is_empty() {
|
||||
return Err("未找到 [VProf] 报告".to_string());
|
||||
}
|
||||
|
||||
Ok(vprof_lines.join("\n"))
|
||||
}
|
||||
|
||||
@@ -132,6 +132,8 @@ fn main() {
|
||||
cmds::set_cs2_video_config,
|
||||
cmds::check_path,
|
||||
cmds::analyze_replay,
|
||||
cmds::get_console_log_path,
|
||||
cmds::read_vprof_report,
|
||||
on_button_clicked
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
|
||||
Reference in New Issue
Block a user