future proofing against glob order of file
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{bail, Context, Result};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
use pimcore::json_to_instruction::json_to_executor;
|
use pimcore::json_to_instruction::json_to_executor;
|
||||||
@@ -55,7 +55,6 @@ fn main() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn populate_crossbar(args: &Args, executor: &mut pimcore::Executable) {
|
fn populate_crossbar(args: &Args, executor: &mut pimcore::Executable) {
|
||||||
let num_cores = executor.cpu_mut().num_core();
|
let num_cores = executor.cpu_mut().num_core();
|
||||||
|
|
||||||
@@ -94,12 +93,10 @@ fn populate_crossbar(args: &Args, executor: &mut pimcore::Executable) {
|
|||||||
.execute_store(&bytes)
|
.execute_store(&bytes)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn dump_memory(mut executor: pimcore::Executable, args: &Args) -> Result<()> {
|
fn dump_memory(mut executor: pimcore::Executable, args: &Args) -> Result<()> {
|
||||||
let dumps: Vec<(i32, i32)> = args
|
let dumps: Vec<(i32, i32)> = args
|
||||||
.dump
|
.dump
|
||||||
@@ -171,12 +168,18 @@ fn retrive_cores(args: &Args) -> Result<Vec<Value>, anyhow::Error> {
|
|||||||
} else if let Some(folder) = args.folder.as_ref() {
|
} else if let Some(folder) = args.folder.as_ref() {
|
||||||
let pattern = folder.join("core*.json");
|
let pattern = folder.join("core*.json");
|
||||||
let pattern_str = pattern.to_str().context("Invalid path encoding")?;
|
let pattern_str = pattern.to_str().context("Invalid path encoding")?;
|
||||||
let paths: Vec<_> = glob(pattern_str)?.collect();
|
let mut paths: Vec<_> = glob(pattern_str)?.map(|x| x.unwrap()).collect();
|
||||||
|
paths.sort_by_cached_key(|x| {
|
||||||
|
let mut x = x.file_stem().expect("Extracting the stem").to_str().expect("File not utf-8");
|
||||||
|
x = &x[5..];
|
||||||
|
x.parse::<i32>().unwrap()
|
||||||
|
});
|
||||||
|
|
||||||
if paths.is_empty() {
|
if paths.is_empty() {
|
||||||
bail!("No core*.json files found in {:?}", folder);
|
bail!("No core*.json files found in {:?}", folder);
|
||||||
}
|
}
|
||||||
for entry in paths {
|
for entry in paths {
|
||||||
let path = entry?;
|
let path = entry;
|
||||||
let content = fs::read_to_string(&path)
|
let content = fs::read_to_string(&path)
|
||||||
.with_context(|| format!("Failed to read core file: {:?}", path))?;
|
.with_context(|| format!("Failed to read core file: {:?}", path))?;
|
||||||
let json: Value = serde_json::from_str(&content)
|
let json: Value = serde_json::from_str(&content)
|
||||||
|
|||||||
Reference in New Issue
Block a user