也是大刀阔斧的重构的一天呢
This commit is contained in:
parent
a958e594a0
commit
42c9c3415b
@ -4,10 +4,11 @@ use crate::{
|
||||
Command,
|
||||
};
|
||||
|
||||
use std::{io::Write, path::PathBuf};
|
||||
use std::{io::Write, ops::Range, path::PathBuf, time::Instant};
|
||||
|
||||
use base16384::Base16384Utf8;
|
||||
use colored::Colorize;
|
||||
use crossbeam::channel::{bounded, Receiver, Sender};
|
||||
use tracing::{info, warn};
|
||||
|
||||
/// 根据 u64 生成对应的 name
|
||||
@ -23,14 +24,12 @@ pub fn gen_name(id: u64) -> String {
|
||||
}
|
||||
|
||||
pub struct CacluateConfig {
|
||||
/// 计算 range
|
||||
pub range: std::ops::Range<u64>,
|
||||
/// 线程数
|
||||
pub thread_id: u32,
|
||||
/// 八围预期值
|
||||
pub prop_expect: u32,
|
||||
/// qp 预期值
|
||||
pub qp_expect: u32,
|
||||
pub xp_expect: u32,
|
||||
/// 队伍名称
|
||||
pub team: String,
|
||||
/// 预期状态输出时间间隔 (秒)
|
||||
@ -75,63 +74,14 @@ pub fn schdule_threads(cli_arg: Command, out_path: PathBuf) {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn cacl(config: CacluateConfig, id: u64) {
|
||||
// 初始猜测的时间间隔
|
||||
let mut report_interval = 100000; // 第一次猜测测 10w 次, 获取初始数据
|
||||
let mut run_speed = 0.0;
|
||||
let mut start_time = std::time::Instant::now();
|
||||
let mut k: u64 = 0;
|
||||
let mut get_count: u32 = 0;
|
||||
// 设置线程亲和性
|
||||
if let Some(core_affinity) = config.core_affinity {
|
||||
crate::set_thread2core(1 << core_affinity)
|
||||
}
|
||||
|
||||
// 提前准备好 team_namer
|
||||
let team_namer = TeamNamer::new(&config.team).unwrap();
|
||||
|
||||
let mut main_namer = Namer::new_from_team_namer_unchecked(&team_namer, "dummy");
|
||||
|
||||
for i in (config.start + id..config.end).step_by(config.thread_id as usize) {
|
||||
k += 1;
|
||||
if k >= report_interval {
|
||||
let now = std::time::Instant::now();
|
||||
let d_t: std::time::Duration = now.duration_since(start_time);
|
||||
let new_run_speed = k as f64 / d_t.as_secs_f64();
|
||||
// 预估剩余时间
|
||||
let wait_time = (config.range.end - i) / new_run_speed as u64;
|
||||
let wait_time = chrono::Duration::seconds(wait_time as i64);
|
||||
// 转换成 时:分:秒
|
||||
// 根据实际运行速率来调整 report_interval
|
||||
report_interval = config.report_interval * new_run_speed as u64;
|
||||
info!(
|
||||
"|{:>2}|Id:{:>15}|{:6.2}/s {:>3.3}E/d {:>5.2}{}|{:<3}|预计:{}:{}:{}|",
|
||||
id,
|
||||
i,
|
||||
new_run_speed,
|
||||
new_run_speed * 8.64 / 1_0000.0,
|
||||
d_t.as_secs_f64(),
|
||||
// 根据对比上一段运行速度 输出 emoji
|
||||
// ⬆️ ➡️ ⬇️
|
||||
// 两个值 相差 0.1 之内都是 ➡️
|
||||
if new_run_speed > run_speed + 0.1 {
|
||||
"⬆️".green()
|
||||
} else if new_run_speed < run_speed - 0.1 {
|
||||
// 橙色
|
||||
"⬇️".red()
|
||||
} else {
|
||||
"➡️".blue()
|
||||
},
|
||||
get_count,
|
||||
wait_time.num_hours(),
|
||||
wait_time.num_minutes() % 60,
|
||||
wait_time.num_seconds() % 60
|
||||
);
|
||||
run_speed = new_run_speed;
|
||||
start_time = std::time::Instant::now();
|
||||
k = 0;
|
||||
}
|
||||
pub fn batch_cacl(
|
||||
config: &CacluateConfig,
|
||||
range: Range<u64>,
|
||||
main_namer: &mut Namer,
|
||||
team_namer: &TeamNamer,
|
||||
get_count: &mut u64,
|
||||
) {
|
||||
for i in range {
|
||||
// 这堆操作放在这边了, 保证统计没问题
|
||||
let name = gen_name(i);
|
||||
// 新加的提前检测
|
||||
@ -149,11 +99,11 @@ pub fn cacl(config: CacluateConfig, id: u64) {
|
||||
let xu = crate::evaluate::xuping::XuPing2_0_1015::evaluate(&main_namer);
|
||||
let xu_qd = crate::evaluate::xuping::XuPing2_0_1015_QD::evaluate(&main_namer);
|
||||
|
||||
if xu < config.qp_expect as f64 || xu_qd < config.qp_expect as f64 {
|
||||
if xu < config.xp_expect as f64 || xu_qd < config.xp_expect as f64 {
|
||||
continue;
|
||||
}
|
||||
|
||||
get_count += 1;
|
||||
*get_count += 1;
|
||||
info!("Id:{:>15}|{}|{:.4}|{:.4}|{}", i, full_name, xu, xu_qd, main_namer.get_info());
|
||||
// 写入文件
|
||||
let write_in = format!(
|
||||
@ -181,3 +131,61 @@ pub fn cacl(config: CacluateConfig, id: u64) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn cacl(config: CacluateConfig, receiver: Receiver<Option<Range<u64>>>) {
|
||||
// 初始猜测的时间间隔
|
||||
// 设置线程亲和性
|
||||
if let Some(core_affinity) = config.core_affinity {
|
||||
crate::set_thread2core(1 << core_affinity)
|
||||
}
|
||||
|
||||
// 提前准备好 team_namer
|
||||
let team_namer = TeamNamer::new(&config.team).unwrap();
|
||||
|
||||
let mut main_namer = Namer::new_from_team_namer_unchecked(&team_namer, "dummy");
|
||||
|
||||
let mut start_time = std::time::Instant::now();
|
||||
|
||||
let mut report_interval = 100000; // 第一次猜测测 10w 次, 获取初始数据
|
||||
let mut run_speed = 0.0;
|
||||
let mut k: u64 = 0;
|
||||
k += 1;
|
||||
if k >= report_interval {
|
||||
let now = std::time::Instant::now();
|
||||
let d_t: std::time::Duration = now.duration_since(range_time);
|
||||
let new_run_speed = k as f64 / d_t.as_secs_f64();
|
||||
// 预估剩余时间
|
||||
let wait_time = (range.end - i) / new_run_speed as u64;
|
||||
let wait_time = chrono::Duration::seconds(wait_time as i64);
|
||||
// 转换成 时:分:秒
|
||||
// 根据实际运行速率来调整 report_interval
|
||||
report_interval = config.report_interval * new_run_speed as u64;
|
||||
info!(
|
||||
"|{:>2}|Id:{:>15}|{:6.2}/s {:>3.3}E/d {:>5.2}{}|{:<3}|预计:{}:{}:{}|",
|
||||
config.thread_id,
|
||||
i,
|
||||
new_run_speed,
|
||||
new_run_speed * 8.64 / 1_0000.0,
|
||||
d_t.as_secs_f64(),
|
||||
// 根据对比上一段运行速度 输出 emoji
|
||||
// ⬆️ ➡️ ⬇️
|
||||
// 两个值 相差 0.1 之内都是 ➡️
|
||||
if new_run_speed > run_speed + 0.1 {
|
||||
"⬆️".green()
|
||||
} else if new_run_speed < run_speed - 0.1 {
|
||||
// 橙色
|
||||
"⬇️".red()
|
||||
} else {
|
||||
"➡️".blue()
|
||||
},
|
||||
get_count,
|
||||
wait_time.num_hours(),
|
||||
wait_time.num_minutes() % 60,
|
||||
wait_time.num_seconds() % 60
|
||||
);
|
||||
run_speed = new_run_speed;
|
||||
range_time = std::time::Instant::now();
|
||||
k = 0;
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,9 @@ pub struct Command {
|
||||
/// 八围预期值
|
||||
#[arg(long = "prop-expected", short = 'p', default_value_t = 640)]
|
||||
pub prop_expect: u32,
|
||||
/// qp 预期值
|
||||
#[arg(long = "qp-expected", short = 'q', default_value_t = 0)]
|
||||
pub qp_expect: u32,
|
||||
/// xp 预期值
|
||||
#[arg(long = "xp-expected", short = 'x', default_value_t = 0)]
|
||||
pub xp_expect: u32,
|
||||
/// 队伍名称
|
||||
#[arg(long)]
|
||||
pub team: String,
|
||||
@ -47,10 +47,9 @@ pub struct Command {
|
||||
impl Command {
|
||||
pub fn as_cacl_config(&self, path: &PathBuf) -> CacluateConfig {
|
||||
CacluateConfig {
|
||||
range: self.start..self.end,
|
||||
thread_id: 0,
|
||||
prop_expect: self.prop_expect,
|
||||
qp_expect: self.qp_expect,
|
||||
xp_expect: self.xp_expect,
|
||||
team: self.team.clone(),
|
||||
report_interval: self.report_interval,
|
||||
core_affinity: self.pick_core.map(|x| 1 << x),
|
||||
@ -59,6 +58,24 @@ impl Command {
|
||||
}
|
||||
|
||||
pub fn is_single_thread(&self) -> bool { self.thread_count == 1 }
|
||||
|
||||
pub fn display_info(&self) -> String {
|
||||
format!(
|
||||
"开始: {} 结尾: {}\n线程数: {}\n八围预期: {}\n强评/强单最低值: {}\n队伍名: {}\n预期状态输出时间间隔: {} 秒\n{}",
|
||||
self.start,
|
||||
self.end,
|
||||
self.thread_count,
|
||||
self.prop_expect,
|
||||
self.xp_expect,
|
||||
self.team,
|
||||
self.report_interval,
|
||||
if self.is_single_thread() {
|
||||
"".to_string()
|
||||
} else {
|
||||
format!("batch 大小: {}", self.batch_size)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_thread2core(core: usize) {
|
||||
@ -116,12 +133,7 @@ fn main() {
|
||||
return;
|
||||
}
|
||||
|
||||
// info!("开始: {} 结尾: {}", cli_arg.start, cli_arg.end);
|
||||
// info!("线程数: {}", cli_arg.thread_count);
|
||||
// info!("八围预期: {}", cli_arg.prop_expect);
|
||||
// info!("队伍名: {}", cli_arg.team);
|
||||
// info!("输出文件名: {:?}", out_path);
|
||||
// info!("预期状态输出时间间隔: {} 秒", cli_arg.report_interval);
|
||||
info!("{}", cli_arg.display_info());
|
||||
|
||||
cacluate::start_main(cli_arg, out_path);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user