-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from Janekdererste/profile_runtime
Profile runtime
- Loading branch information
Showing
14 changed files
with
393 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::Parser; | ||
use tracing::info; | ||
|
||
use rust_q_sim::simulation::config::PartitionMethod; | ||
use rust_q_sim::simulation::id; | ||
use rust_q_sim::simulation::logging::init_std_out_logging; | ||
use rust_q_sim::simulation::network::global_network::Network; | ||
|
||
fn main() { | ||
init_std_out_logging(); | ||
let args = InputArgs::parse(); | ||
info!("Starting network conversion with args: {args:?}"); | ||
|
||
let net_path = PathBuf::from(&args.network); | ||
let id_path = PathBuf::from(&args.id_store); | ||
|
||
if is_binary_format(&net_path) { | ||
info!("Converting from binary to xml format. Load id store first."); | ||
id::load_from_file(&id_path); | ||
} | ||
|
||
let net = Network::from_file_path(&net_path, 1, PartitionMethod::None); | ||
let out_path = replace_extension(&net_path); | ||
net.to_file(&out_path); | ||
|
||
if is_binary_format(&out_path) { | ||
info!("Converting from xml to binary format. Writing ids to store file."); | ||
id::store_to_file(&id_path); | ||
} | ||
} | ||
|
||
fn is_binary_format(path: &PathBuf) -> bool { | ||
path.extension() | ||
.expect("Network files must either end with xml, xml.gz, or binpb") | ||
.eq("binpb") | ||
} | ||
|
||
fn replace_extension(path: &PathBuf) -> PathBuf { | ||
let new_ext = if is_binary_format(path) { | ||
"xml.gz" | ||
} else { | ||
"binpb" | ||
}; | ||
let mut result = PathBuf::from(path); | ||
result.set_extension(new_ext); | ||
result | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
struct InputArgs { | ||
#[arg(short, long)] | ||
pub network: String, | ||
#[arg(short, long)] | ||
pub id_store: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.