Dump this cfg to a Graphviz format file and translate it to PNG.
(&self, deopt: &Deopt)
| 119 | |
| 120 | /// Dump this cfg to a Graphviz format file and translate it to PNG. |
| 121 | pub fn dump_to_file(&self, deopt: &Deopt) -> eyre::Result<()> { |
| 122 | let config = vec![petgraph::dot::Config::EdgeNoLabel]; |
| 123 | let raw_str = format!( |
| 124 | "{:?}", |
| 125 | petgraph::dot::Dot::with_config(&self.graph, &config) |
| 126 | ); |
| 127 | let file: PathBuf = [deopt.get_library_misc_dir()?, "callgraph".into()] |
| 128 | .iter() |
| 129 | .collect(); |
| 130 | |
| 131 | let mut dot_path = file.clone(); |
| 132 | dot_path.set_extension("dot"); |
| 133 | std::fs::write(&dot_path, raw_str)?; |
| 134 | let mut cfg_path = file.clone(); |
| 135 | cfg_path.set_extension("pdf"); |
| 136 | let output = std::process::Command::new("dot") |
| 137 | .arg("-Tpdf") |
| 138 | .arg(&dot_path) |
| 139 | .arg("-o") |
| 140 | .arg(cfg_path) |
| 141 | .output()?; |
| 142 | if !output.status.success() { |
| 143 | let err_msg = String::from_utf8_lossy(&output.stderr).to_string(); |
| 144 | eyre::bail!("{err_msg}"); |
| 145 | } |
| 146 | std::fs::remove_file(dot_path)?; |
| 147 | Ok(()) |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | pub fn get_lib_call_graph() -> &'static CallGraph { |