#timing #call #graph #json #spans #called

time-graph

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

6 releases

0.3.2 Sep 25, 2024
0.3.1 Aug 28, 2023
0.3.0 Feb 28, 2023
0.2.0 May 17, 2022
0.1.1 Mar 5, 2021

#36 in Profiling

Download history 280/week @ 2024-08-17 234/week @ 2024-08-24 597/week @ 2024-08-31 333/week @ 2024-09-07 861/week @ 2024-09-14 996/week @ 2024-09-21 532/week @ 2024-09-28 538/week @ 2024-10-05 435/week @ 2024-10-12 391/week @ 2024-10-19 1041/week @ 2024-10-26 827/week @ 2024-11-02 911/week @ 2024-11-09 1459/week @ 2024-11-16 1850/week @ 2024-11-23 1182/week @ 2024-11-30

5,533 downloads per month
Used in integrate

Apache-2.0/MIT

74KB
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

~2.8–5.5MB
~93K SLoC