• Stars
    star
    3,542
  • Rank 12,529 (Top 0.3 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a debugger for async rust!

tokio-console

API Documentation(main) MIT licensed Build Status Discord chat

Chat | API Documentation (main branch)

what's all this, then?

this repository contains an implementation of TurboWish/tokio-console, a diagnostics and debugging tool for asynchronous Rust programs. the diagnostic toolkit consists of multiple components:

  • a wire protocol for streaming diagnostic data from instrumented applications to diagnostic tools. the wire format is defined using gRPC and protocol buffers, for efficient transport on the wire and interoperability between different implementations of data producers and consumers.

    the console-api crate contains generated code for this wire format for projects using the tonic gRPC implementation. additionally, projects using other gRPC code generators (including those in other languages!) can depend on the protobuf definitions themselves.

  • instrumentation for collecting diagnostic data from a process and exposing it over the wire format. the console-subscriber crate in this repository contains an implementation of the instrumentation-side API as a tracing-subscriber Layer, for projects using Tokio and tracing.

  • tools for displaying and exploring diagnostic data, implemented as gRPC clients using the console wire protocol. the tokio-console crate implements an an interactive command-line tool that consumes this data, but other implementations, such as graphical or web-based tools, are also possible.

extremely cool and amazing screenshots

wow! whoa! it's like top(1) for tasks!

task list view

viewing details for a single task:

task details view

on the shoulders of giants

the console is part of a much larger effort to improve debugging tooling for async Rust. a 2019 Google Summer of Code project by Matthias Prechtl (@matprec) implemented an initial prototype, with a focus on interactive log viewing. more recently, both the Tokio team and the async foundations working group have made diagnostics and debugging tools a priority for async Rust in 2021 and beyond. in particular, a series of blog posts by @pnkfelix lay out much of the vision that this project seeks to eventually implement.

furthermore, we're indebted to our antecedents in other programming languages and environments for inspiration. this includes tools and systems such as pprof, Unix top(1) and htop(1), XCode's Instruments, and many others.

using it

instrumenting your program

to instrument an application using Tokio, add a dependency on the console-subscriber crate, and add this one-liner to the top of your main function:

console_subscriber::init();

notes:

  • in order to collect task data from Tokio, the tokio_unstable cfg must be enabled. for example, you could build your project with

    RUSTFLAGS="--cfg tokio_unstable" cargo build

    or add the following to your .cargo/config.toml file:

    [build]
    rustflags = ["--cfg", "tokio_unstable"]

    For more information on the appropriate location of your .cargo/config.toml file, especially when using workspaces, see the console-subscriber readme.

  • the tokio and runtime tracing targets must be enabled at the TRACE level.

running the console

to run the console command-line tool, install tokio-console from crates.io

cargo install --locked tokio-console

and run locally

tokio-console

alternative method: run the tool from a local checkout of this repository

$ cargo run

by default, this will attempt to connect to an instrumented application running on localhost on port 6669. if the application is running somewhere else, or is serving the console endpoint on a different port, a target address can be passed as an argument to the console (either as an <IP>:<PORT> or <DNS_NAME>:<PORT>). for example:

cargo run -- http://my.great.console.app.local:5555

The console command-line tool supports a number of additional flags to configure its behavior. The help command will print a list of supported command-line flags and arguments:

USAGE:
    tokio-console [OPTIONS] [TARGET_ADDR] [SUBCOMMAND]

ARGS:
    <TARGET_ADDR>
            The address of a console-enabled process to connect to.

            This may be an IP address and port, or a DNS name.

            On Unix platforms, this may also be a URI with the `file` scheme that specifies the path
            to a Unix domain socket, as in `file://localhost/path/to/socket`.

            [default: http://127.0.0.1:6669]

OPTIONS:
        --ascii-only <ASCII_ONLY>
            Explicitly use only ASCII characters

        --colorterm <truecolor>
            Overrides the value of the `COLORTERM` environment variable.

            If this is set to `24bit` or `truecolor`, 24-bit RGB color support will be enabled.

            [env: COLORTERM=truecolor]
            [possible values: 24bit, truecolor]

    -h, --help
            Print help information

        --lang <LANG>
            Overrides the terminal's default language

            [env: LANG=]

        --log <ENV_FILTER>
            Log level filter for the console's internal diagnostics.

            Logs are written to a new file at the path given by the `--log-dir` argument (or its
            default value), or to the system journal if `systemd-journald` support is enabled.

            If this is set to 'off' or is not set, no logs will be written.

            [default: off]

            [env: RUST_LOG=]

        --log-dir <LOG_DIRECTORY>
            Path to a directory to write the console's internal logs to.

            [default: /tmp/tokio-console/logs]

        --no-colors
            Disable ANSI colors entirely

        --no-duration-colors <COLOR_DURATIONS>
            Disable color-coding for duration units

        --no-terminated-colors <COLOR_TERMINATED>
            Disable color-coding for terminated tasks

        --palette <PALETTE>
            Explicitly set which color palette to use

            [possible values: 8, 16, 256, all, off]

        --retain-for <RETAIN_FOR>
            How long to continue displaying completed tasks and dropped resources after they have
            been closed.

            This accepts either a duration, parsed as a combination of time spans (such as `5days
            2min 2s`), or `none` to disable removing completed tasks and dropped resources.

            Each time span is an integer number followed by a suffix. Supported suffixes are:

            * `nsec`, `ns` -- nanoseconds

            * `usec`, `us` -- microseconds

            * `msec`, `ms` -- milliseconds

            * `seconds`, `second`, `sec`, `s`

            * `minutes`, `minute`, `min`, `m`

            * `hours`, `hour`, `hr`, `h`

            * `days`, `day`, `d`

            * `weeks`, `week`, `w`

            * `months`, `month`, `M` -- defined as 30.44 days

            * `years`, `year`, `y` -- defined as 365.25 days

            [default: 6s]

    -V, --version
            Print version information

SUBCOMMANDS:
    gen-completion
            Generate shell completions
    gen-config
            Generate a `console.toml` config file with the default configuration values, overridden
            by any provided command-line arguments
    help
            Print this message or the help of the given subcommand(s)

for development

the console-subscriber/examples directory contains some potentially useful tools:

  • app.rs: a very simple example program that spawns a bunch of tasks in a loop forever
  • dump.rs: a simple CLI program that dumps the data stream from a Tasks server

Examples can be executed with:

cargo run --example $name

More Repositories

1

tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
Rust
23,031
star
2

axum

Ergonomic and modular web framework built with Tokio, Tower, and Hyper
Rust
17,992
star
3

mio

Metal I/O library for Rust.
Rust
6,301
star
4

tracing

Application level tracing for Rust.
Rust
5,365
star
5

mini-redis

Incomplete Redis client and server implementation using Tokio - for learning purposes only
Rust
3,927
star
6

prost

PROST! a Protocol Buffers implementation for the Rust Language
Rust
3,766
star
7

loom

Concurrency permutation testing tool for Rust.
Rust
1,847
star
8

bytes

Utilities for working with bytes
Rust
1,739
star
9

io-uring

The `io_uring` library for Rust
Rust
1,037
star
10

tokio-uring

An io_uring backed runtime for Rust
Rust
946
star
11

turmoil

Add hardship to your tests
Rust
772
star
12

tokio-proto

A network application framework for Rust
Rust
694
star
13

slab

Slab allocator for Rust
Rust
641
star
14

tokio-core

I/O primitives and event loop for async I/O in Rust
Rust
628
star
15

async-stream

Asynchronous streams for Rust using async & await notation
Rust
568
star
16

rdbc

Rust DataBase Connectivity (RDBC) :: Common Rust API for database drivers
Rust
558
star
17

tokio-minihttp

Protocol implementation experimentations
Rust
425
star
18

tokio-metrics

Utilities for collecting metrics from a Tokio application
Rust
254
star
19

tls

A collection of Tokio based TLS libraries.
Rust
243
star
20

tracing-opentelemetry

Rust
233
star
21

website

Website for the Tokio project
TypeScript
211
star
22

valuable

Rust
185
star
23

async-backtrace

Rust
162
star
24

tokio-io

Core I/O primitives for asynchronous I/O in Rust.
Rust
124
star
25

tokio-socks5

An example SOCKSv5 server implementation with tokio
Rust
100
star
26

tokio-tls

An implementation of TLS/SSL streams for Tokio
Rust
95
star
27

simulation

Framework for simulating distributed applications
Rust
92
star
28

tokio-timer

Timer facilities for Tokio
Rust
83
star
29

tokio-service

The core `Service` trait in Tokio and support
Rust
81
star
30

tokio-line

Line protocol for Tokio
Rust
64
star
31

tokio-redis

Redis client for Tokio
Rust
58
star
32

tokio-uds

Unix Domain Sockets for tokio
Rust
52
star
33

doc-push

Tokio doc blitz effort - A concerted effort to improve Tokio's documentation.
50
star
34

tokio-compat

Streamline updating a Tokio 0.1 application to Tokio 0.2.
Rust
48
star
35

book

45
star
36

tokio-openssl

OpenSSL bindings for Tokio
Rust
37
star
37

tokio-middleware

A collection of Tokio middleware
Rust
28
star
38

tokio-rfcs

22
star
39

async

Utilities building on top of Rust's async primitives.
Rust
22
star
40

console-gsoc

Google Summer of Code tokio-console prototype
Rust
12
star
41

service-fn

A service implemented by a closure
Rust
11
star
42

gsoc

Organize the Google Summer of Code projects.
6
star
43

cargo-tokio

A cargo subcommand to help building the Tokio project.
Rust
4
star
44

website-next

Next iteration of the Tokio website.
TypeScript
1
star