Add chrono crate and modify file output path
This commit is contained in:
parent
5bc4644a58
commit
60cd2a777e
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/target
|
||||
/namerena
|
||||
|
164
Cargo.lock
generated
164
Cargo.lock
generated
@ -2,6 +2,21 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "android-tzdata"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.13"
|
||||
@ -50,18 +65,50 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "base16384"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c81fb0b757d33aa2a07ee0f07800e5e529aac2a78a474f1816174516e23a1d62"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.15.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.88"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02f341c093d19155a6e41631ce5971aac4e9a868262212153124c15fa22d1cdc"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b"
|
||||
dependencies = [
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"wasm-bindgen",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.1"
|
||||
@ -108,6 +155,12 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.3.11"
|
||||
@ -123,18 +176,56 @@ version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.60"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.153"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.20"
|
||||
@ -146,6 +237,7 @@ name = "namerena-rs"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base16384",
|
||||
"chrono",
|
||||
"clap",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
@ -167,6 +259,15 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.19.0"
|
||||
@ -378,6 +479,60 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
@ -400,6 +555,15 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
|
@ -11,6 +11,7 @@ base16384 = "0.1.0"
|
||||
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = { version = "0.3.18", features = ["time"] }
|
||||
chrono = "0.4.34"
|
||||
|
||||
[features]
|
||||
default = ["simd"]
|
||||
|
54
src/main.rs
54
src/main.rs
@ -2,9 +2,11 @@
|
||||
|
||||
mod name;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use base16384::Base16384Utf8;
|
||||
use clap::Parser;
|
||||
use tracing::info;
|
||||
use tracing::{info, warn};
|
||||
|
||||
/// 根据 u64 生成对应的 name
|
||||
/// 转换成 base 16384
|
||||
@ -42,7 +44,7 @@ const allow_d: u32 = 10;
|
||||
#[allow(non_upper_case_globals)]
|
||||
const report_interval: u64 = 1_00_0000;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
pub struct Command {
|
||||
#[arg(long, default_value_t = 0)]
|
||||
pub start: u64,
|
||||
@ -57,7 +59,7 @@ pub struct Command {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn cacl(start: u64, max: u64, step: usize, top: u32, id: u64, team: &String) {
|
||||
fn cacl(start: u64, max: u64, step: usize, top: u32, id: u64, team: &String, outfile: &PathBuf) {
|
||||
let mut start_time = std::time::Instant::now();
|
||||
let mut k: u64 = 0;
|
||||
let mut top = top;
|
||||
@ -74,6 +76,10 @@ fn cacl(start: u64, max: u64, step: usize, top: u32, id: u64, team: &String) {
|
||||
let name = gen_name(i as u64);
|
||||
let full_name = format!("{}@{}", name, team);
|
||||
info!("{:>15}|{}|{}", i, full_name, show_name(&namer));
|
||||
// 写入
|
||||
if let Err(e) = std::fs::write(outfile, full_name) {
|
||||
warn!("写入文件<{:?}>失败: {}", outfile, e);
|
||||
}
|
||||
}
|
||||
k += 1;
|
||||
if k >= report_interval as u64 {
|
||||
@ -103,35 +109,47 @@ fn main() {
|
||||
|
||||
let mut n = 0;
|
||||
let mut threads = Vec::with_capacity(cli_arg.thread_count as usize);
|
||||
let now = std::time::Instant::now();
|
||||
// namerena-<team>-<start>-<end>-<time>.txt
|
||||
let now = chrono::Local::now().format("%Y-%m-%d_%H-%M-%S").to_string();
|
||||
// namerena-<team>-<time>.txt
|
||||
// <time>: %Y-%m-%d-%H-%M-%S
|
||||
let output_filename = format!(
|
||||
"namerena-{}-{}-{}-{:?}.txt",
|
||||
cli_arg.team,
|
||||
cli_arg.start,
|
||||
cli_arg.end,
|
||||
now
|
||||
"namerena-{}-{}.txt",
|
||||
cli_arg.team, now
|
||||
);
|
||||
info!("输出文件: {}", output_filename);
|
||||
|
||||
let out_path = PathBuf::from(format!("./namerena/{}", output_filename));
|
||||
info!("输出文件: {:?}", out_path);
|
||||
// 先创建文件夹
|
||||
if let Err(e) = std::fs::create_dir_all(&out_path.parent().unwrap()) {
|
||||
warn!("创建文件夹失败: {}", e);
|
||||
}
|
||||
// 再创建文件
|
||||
if let Err(e) = std::fs::File::create(&out_path) {
|
||||
warn!("创建文件失败: {}", e);
|
||||
}
|
||||
|
||||
info!("start: {} end: {}", cli_arg.start, cli_arg.end);
|
||||
info!("thread_count: {}", cli_arg.thread_count);
|
||||
info!("top: {}", cli_arg.top);
|
||||
info!("team: {}", cli_arg.team);
|
||||
info!("output: {:?}", out_path);
|
||||
|
||||
for i in 0..cli_arg.thread_count {
|
||||
let top = cli_arg.top;
|
||||
let max = cli_arg.end;
|
||||
let start = cli_arg.start;
|
||||
n += 1;
|
||||
let cli = cli_arg.clone();
|
||||
let out_path = out_path.clone();
|
||||
let thread_name = format!("thread_{}", i);
|
||||
let thread_count = cli_arg.thread_count;
|
||||
let team = cli_arg.team.clone();
|
||||
threads.push(std::thread::spawn(move || {
|
||||
info!("线程 {} 开始计算", thread_name);
|
||||
cacl(
|
||||
start,
|
||||
max as u64,
|
||||
cli.start,
|
||||
cli.end as u64,
|
||||
thread_count as usize,
|
||||
top as u32,
|
||||
cli.top as u32,
|
||||
n as u64,
|
||||
&team,
|
||||
&out_path,
|
||||
);
|
||||
info!("线程 {} 结束计算", thread_name);
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user