Use timings `duration` to set size of rendered node

finchie
Apr 22, 2024, 7:09 AM
OPTMCUTBEZQT3HETRWVBU4HYSB7NNBA4TY7QOOKCN3YLSMDKNM2QC

Dependencies

  • [2] UXJFRBBL Move graph functionality into `graph` module
  • [3] T34OV3YQ Store timings output in `timings::Output` struct
  • [4] JVYWRCPT Add basic chart visualisation
  • [5] ZPFD3275 Switch from `cargo_metadata`+`petgraph` to `guppy`
  • [6] Q3Z6XMP5 Migrate dependency tree to `petgraph::Graph`
  • [*] LOR3KOXG Parse JSON output from `cargo build --timings`
  • [*] 7CVIL7UJ Create simple metadata parser

Change contents

  • edit in src/timings.rs at line 140
    [3.2251]
    [8.2689]
    }
    pub fn pkg_time(&self, pkg: &PackageId) -> Option<f64> {
    self.repr
    .get(pkg)
    .map(|timings| timings.iter().map(|msg| msg.duration).sum())
  • replacement in src/main.rs at line 18
    [4.1460][2.64:112]()
    .data(graph::data(&package_graph)),
    [4.1460]
    [4.1499]
    .data(graph::data(&package_graph, &timings)),
  • edit in src/graph.rs at line 1
    [2.146]
    [2.147]
    use crate::timings;
  • replacement in src/graph.rs at line 46
    [2.1551][2.1551:1618]()
    pub fn data(graph: &PackageGraph) -> charming::series::GraphData {
    [2.1551]
    [2.1618]
    pub fn data(graph: &PackageGraph, timings: &timings::Output) -> charming::series::GraphData {
  • replacement in src/graph.rs at line 54
    [2.1831][2.1831:2158]()
    .map(|(id, node)| charming::series::GraphNode {
    id: id.repr().to_string(),
    name: graph.metadata(id).unwrap().name().to_string(),
    x: node.pos.x(),
    y: node.pos.y(),
    value: 1_f64,
    category: 0,
    symbol_size: 1_f64,
    label: None,
    [2.1831]
    [2.2158]
    .map(|(id, node)| {
    let unit_time = if let Some(duration) = timings.pkg_time(id) {
    duration
    } else {
    // TODO: once using the resolved crate graph, `None` should never appear
    println!("Queried node outside cargo's unit graph: {id}");
    0_f64
    };
    // TODO: figure out the difference between `value` and `symbol_size`
    charming::series::GraphNode {
    id: id.repr().to_string(),
    name: graph.metadata(id).unwrap().name().to_string(),
    x: node.pos.x(),
    y: node.pos.y(),
    value: unit_time,
    category: 0,
    symbol_size: unit_time,
    label: None,
    }