#timing #called #graph #spans #call #elapsed

time-graph

Always-on profilling recording function timing and the corresponding call graph

5 releases

0.3.1 Aug 28, 2023
0.3.0 Feb 28, 2023
0.2.0 May 17, 2022
0.1.3 Sep 1, 2021
0.1.1 Mar 5, 2021

#47 in Profiling

Download history 893/week @ 2024-03-13 557/week @ 2024-03-20 477/week @ 2024-03-27 643/week @ 2024-04-03 776/week @ 2024-04-10 427/week @ 2024-04-17 347/week @ 2024-04-24 530/week @ 2024-05-01 712/week @ 2024-05-08 1401/week @ 2024-05-15 1093/week @ 2024-05-22 1126/week @ 2024-05-29 1050/week @ 2024-06-05 1371/week @ 2024-06-12 441/week @ 2024-06-19 509/week @ 2024-06-26

3,659 downloads per month

Apache-2.0/MIT

73KB
917 lines

Time-graph

This crate provides a simple way of extracting the number of time a given function (or spans inside functions) have been called, how much time have been spent in each function/span, and record the full "call-graph" between functions/spans. The indented use case is to extract simple profiling data from actual runs of a software. Importantly, this crate does not consider different invocation of the same function/span separately, but instead group all invocation of functions/span together.

This crate can output timing information in multiple formats, including graphviz' dot, JSON data and a nice UTF8 table. Here is the output from running the example with cargo run --release --example calculation --all-features (see the corresponding code):

Graphviz' dot: graphviz' dot output

Terminal table:

╔════╦══════════════════════════════════════════════╦════════════╦═══════════╦══════════╦═════════╗
║ id ║ span name                                    ║ call count ║ called by ║ total    ║ mean    ║
╠════╬══════════════════════════════════════════════╬════════════╬═══════════╬══════════╬═════════╣
║  0calculation::run_other_5ms                   ║          1 ║         — ║   6.29ms ║  6.29ms ║
╠════╬══════════════════════════════════════════════╬════════════╬═══════════╬══════════╬═════════╣
║  2calculation::run_computation                 ║          1 ║         — ║   1.65ms ║  1.65ms ║
╠════╬══════════════════════════════════════════════╬════════════╬═══════════╬══════════╬═════════╣
║  1calculation::compute                         ║         102440.19µs ║ 44.02µs ║
╠════╬══════════════════════════════════════════════╬════════════╬═══════════╬══════════╬═════════╣
║  4calculation::{another span}1211.07µs ║ 11.07µs ║
╠════╬══════════════════════════════════════════════╬════════════╬═══════════╬══════════╬═════════╣
║  3calculation::details::bottom_5us             ║        1462, 4, 11.62ms ║ 11.10µs ║
╚════╩══════════════════════════════════════════════╩════════════╩═══════════╩══════════╩═════════╝

JSON:

{
  "timings": {
    "calculation::run_other_5ms": {
      "id": 0,
      "elapsed": "6.289708ms",
      "called": 1
    },
    "calculation::compute": {
      "id": 1,
      "elapsed": "440.188µs",
      "called": 10
    },
    "calculation::run_computation": {
      "id": 2,
      "elapsed": "1.647644ms",
      "called": 1
    },
    "calculation::details::bottom_5us": {
      "id": 3,
      "elapsed": "1.621202ms",
      "called": 146
    },
    "calculation::{another span}": {
      "id": 4,
      "elapsed": "11.074µs",
      "called": 1
    }
  },
  "calls": [
    { "caller": 1, "callee": 1, "count": 10 },
    { "caller": 3, "callee": 3, "count": 45 },
    { "caller": 3, "callee": 3, "count": 1 },
    { "caller": 4, "callee": 4, "count": 1 },
    { "caller": 3, "callee": 3, "count": 100 }
  ]
}

License and contributions

This crate is distributed under both the MIT license and Apache 2.0 license. By contributing to this crate, you agree to distribute your contributions under the same license.

Dependencies

~4–6MB
~105K SLoC