Fix graph output formatting

This commit is contained in:
Alwin Berger 2024-02-09 20:01:19 +01:00
parent beee8d8cb7
commit 3817892ff1
2 changed files with 10 additions and 6 deletions

View File

@ -45,6 +45,7 @@ use crate::{
use std::time::{SystemTime, UNIX_EPOCH};
use clap::{Parser, Subcommand};
use csv::Reader;
use petgraph::dot::{Dot, Config};
// Constants ================================================================================
@ -194,8 +195,10 @@ macro_rules! do_dump_graph {
let dump_path = $cli.dump_name.clone().unwrap().with_extension(if $c=="" {"graph"} else {$c});
println!("Dumping graph to {:?}", &dump_path);
if let Some(md) = $state.named_metadata_map_mut().get_mut::<SysGraphFeedbackState>("SysMap") {
let out = md.graph.map(|i,x| x.pretty_print(), |_,_| ());
fs::write(dump_path,ron::to_string(&out).expect("Failed to serialize graph")).expect("Failed to write graph");
let out = md.graph.map(|i,x| x.pretty_print(), |_,_| "");
let outs = Dot::with_config(&out, &[Config::EdgeNoLabel]).to_string();
let outs = outs.replace(';',"\\n");
fs::write(dump_path,outs).expect("Failed to write graph");
}
}
};

View File

@ -115,14 +115,15 @@ impl SysGraphNode {
pub fn pretty_print(&self) -> String {
let mut ret = String::new();
ret.push_str(&format!("{}#{}",&self.base.current_task.0.task_name,&self.base.current_task.1));
ret.push_str("\nRl:");
ret.push_str(";Rl:");
for i in &self.base.ready_list_after {
ret.push_str(&format!("\n{}#{}",i.0.task_name,i.1));
ret.push_str(&format!(";{}#{}",i.0.task_name,i.1));
}
ret.push_str("\nDl:");
ret.push_str(";Dl:");
for i in &self.base.delay_list_after {
ret.push_str(&format!("\n{}#{}",i.0.task_name,i.1));
ret.push_str(&format!(";{}#{}",i.0.task_name,i.1));
}
// println!("{}",ret);
ret
}
}