Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

trice

> DevOps
Open source

Super-fast, tiny C/C++ tracing with printf look-and-feel, even in interrupts ⚡, plus real-time PC logging

972 stars0 likes2 views
WebsiteGitHub

About

Super-fast, tiny C/C++ tracing with printf look-and-feel, even in interrupts ⚡, plus real-time PC logging

Trice - Trace IDs for Embedded C/C++

The name combines TRace IDs, C/C++, and Embedded systems.

View GitHub Pages

Hi, I am Trice.

Trice is a compact ID-based logging framework for embedded C/C++. Firmware code uses printf-like calls, but the target sends only small binary records: an ID plus optional runtime values. The PC-side trice tool reconstructs the readable text using the project-specific til.json which is intentionally cumulative: old IDs and format strings remain available so logs from older firmware can still be decoded.

Use Trice when normal printf logging is too slow, too large, too intrusive in interrupt contexts, or too inefficient for field diagnostics.

User Manual: GitHub - GitHub Pages - PDF - Project page


Log in a trice — even from ↯ interrupt handlers in a few CPU cycles in optimized configurations❗

Small demo animation

Quickstart

Choose one first path:

Situation Start here
You already have a non-blocking byte writer, DMA TX queue, USB CDC writer, socket writer, pipe, or file writer Existing non-blocking byte writer
You have a SEGGER J-Link and want the quickest lab setup SEGGER RTT direct mode
You want UART or USB-VCOM output UART / USB-VCOM deferred output
You want complete STM32 examples Example projects

For most existing projects, the non-blocking byte writer path is the least disruptive first integration.

Recommended ID workflow: trice bind

trice bind is the successor to the legacy trice insert / trice clean workflow. It keeps numeric IDs out of bind-managed Trice calls by generating sidecar headers as temporary build artefacts. Existing insert / clean projects remain fully supported and continue to work unchanged. This technique does not patch the user sources anymore during the build process. See Trice Bind in User Manual for details.

trice bind is currently experimental and is not yet included in an official release. To try it before the next release, build the trice tool from this repository and ensure the resulting executable is in your PATH:

bash
./scripts/buildTriceTool.sh

Try the minimal demo. It uses only the installed trice binary and the target sources in src from this repository.

Details and advanced topics

Basics

Minimal source example

Trice gives embedded firmware a fast logging path with a familiar source-code style:

c
trice("boot\n");
trice("adc=%d mV\n", adc_mV);

Instead of formatting strings on the target, Trice stores the human-readable text on the host and transfers compact binary records from the target. This reduces target FLASH usage, transfer bandwidth, log files and log-call execution time.

How ID-based decoding works

The recommended workflow uses trice bind as described above. The following steps describe the legacy source-modifying workflow, which remains supported:

  1. Write trice(...) calls in firmware code.
  2. Run trice insert before compilation.
  3. The compiler sees stable numeric IDs.
  4. The target emits compact binary Trice records.
  5. The PC tool decodes them with the accumulated til.json.

A typical source-level idea is:

diff
- printf("Temperature: %d °C\n", t);
+ trice("Temperature: %d °C\n", t);

Legacy source-code ID workflow (still supported)

The legacy workflow assigns IDs by processing source files with trice insert. This workflow remains supported for existing and new projects. A call such as this:

c
trice("boot\n");

becomes similar to this before compilation:

c
trice(iD(12345), "boot\n");

This is intentional: the target binary contains the ID, while the host keeps the text in til.json.

You can choose how visible those IDs are in your workflow:

  • keep inserted IDs in source,
  • run trice clean after the build,
  • use the Trice cache to avoid needless rebuilds of unchanged files.

For team projects, define this policy early and treat til.json like any other build artifact needed for field diagnostics. See Trice ID management.

Key benefits

  • Easy Migration – reuse existing printf-style code with minimal changes via the -alias option
  • Long-term field decoding – decode logs from released firmware when the matching or accumulated til.json is preserved.
  • Reduced target FLASH - format strings are kept in til.json, not in the target image.
  • Very low target overhead - down to a few CPU cycles in optimized configurations; see Trice Speed.
  • Transport friendly - UART, RTT, TCP/UDP, files, or your own non-blocking byte writer.
  • Compact transfer – a Trice record contains one 32-bit ID plus optional runtime values, reducing bandwidth and log-file size.
  • Portable tooling - the host tool is written in Go and runs on common desktop platforms.
  • Further features - like encryption, timestamps, flexible logging, transport options and tooling are described here.
  • Fully documented: Trice User Manual

Which mode should you start with?

Mode / path Use when
Deferred auxiliary 8-bit You already have a non-blocking byte writer. This is usually the most universal first integration.
Direct SEGGER RTT You have J-Link/RTT and want a fast interactive lab setup.
Deferred UART / USB-VCOM Your board exposes a serial path and you want a conventional PC input stream.
Deferred ring buffer You want a balanced default for RAM usage and runtime behavior.
Deferred double buffer You want the shortest target-side log-call path and can spend more RAM.

Direct mode writes each record immediately to the selected backend. Deferred mode writes first into a target buffer; TriceTransfer() sends later.

Integration workflow

Two parts of Trice

Trice has two cooperating parts:

  • Target-side C/C++ macros provide a familiar printf-like interface but emit IDs and values instead of full format strings.
  • The PC-side trice tool manages IDs, receives binary data, and reconstructs readable log output.

The host tool is written in Go and runs on common desktop platforms. You can also build your own receiver that reads Trice packages, maps IDs to format strings, and displays or stores the decoded output.

Files: til.json, li.json, and binary logs

File Purpose Keep?
til.json Maps IDs to format strings Yes; required for decoding
li.json Maps IDs to source locations Useful for diagnostics
Binary log file Raw target output Useful for offline or field decoding

Keep the one accumulated til.json to decode all previously released firmware versions. The repository example file is demoTIL.json. Each li.json entry stores a normalized File path relative to the location-file directory by default. Use -liRoot to select a different project root when creating location data. Log output shows only the file name by default; use -liMaxDirs to include trailing parent directories.

Legacy insert/clean ID workflows (still supported)

These three source-modifying workflows remain fully supported:

Keep IDs in source - good for small projects and maximum robustness.

bash
trice insert -src ./ -i ./til.json -li ./li.json
# build normally

Insert before build, clean after build - good when the repository should stay visually free of IDs.

bash
trice insert -src ./ -i ./til.json -li ./li.json
# build
trice clean -src ./ -i ./til.json -li ./li.json

Use the Trice cache - good when repeated insert/clean would otherwise cause unnecessary recompilation.

bash
mkdir -p ~/.trice/cache
trice insert -cache -src ./ -i ./til.json -li ./li.json
# build
trice clean -cache -src ./ -i ./til.json -li ./li.json

Pick one workflow and document it in the project build instructions. If other tools also rewrite source files, such as formatters or code generators, run them before trice insert.

Legacy insert/clean cache (still supported)

The Trice cache avoids unnecessary rebuilds when using trice insert and trice clean around the build. It keeps cached inserted and cleaned copies of unchanged files.

Typical use:

bash
mkdir -p ~/.trice/cache
trice insert -cache -src ./ -i ./til.json -li ./li.json
# build
trice clean -cache -src ./ -i ./til.json -li ./li.json

Use cache when you want to keep IDs out of your source code while avoiding repeated recompilation of unchanged files. Be careful when your build system also modifies source files; for example, run auto-formatters before trice insert.

How Cache Works:

The Trice cache saves copies of all files after processing them with trice i or trice c. This avoids inserting and removing IDs repeatedly. The copies are used to get the same results for files that have not been edited. Edited files are processed normally and the cache updates afterwards. File modification times do not change, so the build system does not reprocess unchanged files even when IDs are temporarily removed.

See Trice Cache for Compilation Speed.

Legacy insert workflow (still supported)

  1. Add the Trice target sources from src/ to your firmware project.
  2. Add a project-specific triceConfig.h.
  3. Write Trice calls in your code.
  4. Run trice insert before compiling. This assigns stable IDs and updates til.json and li.json.
  5. Build and flash the target.
  6. Run trice log on the PC to decode the binary stream.

Minimal firmware shape:

c
#include "trice.h"

int main(void) {
    BoardInit();
    TriceInit();

    trice("boot\n");
    trice("adc=%d mV\n", adc_mV);

    for (;;) {
        AppRun();
        TriceTransfer(); // needed for deferred outputs
    }
}

Create the ID files once, then insert IDs:

bash
touch til.json li.json
trice insert -src ./ -i ./til.json -li ./li.json

Start logging from a serial or USB-VCOM port:

bash
trice log -p COM15 -baud 921600 -i ./til.json -li ./li.json
# or, on Linux/macOS:
trice log -p /dev/ttyACM0 -baud 921600 -i ./til.json -li ./li.json

Legacy code integration

Existing projects do not have to migrate all logs at once. Best strategy:

Use Trice aliases so project-specific log macros are processed by trice insert without renaming every call site.

See Legacy User Code Option Trice Aliases Adaptation.

Alternatively:

  1. Keep legacy printf output and send Trice on a separate physical channel.
  2. Replace selected printf calls with Trice calls where speed, bandwidth, or FLASH matters.
  3. Use triceS macros to emit runtime generated printf strings.
  4. Shared the output channel with typeX0 User Packets.

For a first integration, prefer a small vertical slice:

  • one source file,
  • one working output path,
  • one `t

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Carmbare-metalccpp

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理