Tracium

0.2.1 · maintenance · verified Wed Apr 22

Tracium is a JavaScript library designed for parsing Chromium performance traces. It was extracted from Google Lighthouse, making it a robust tool for analyzing web performance data generated by Chrome browsers (version 66 and newer). Currently at version 0.2.1, its release cadence is infrequent, suggesting a stable, feature-complete state rather than active, rapid development. A key differentiator is its ability to correctly parse modern Chrome traces, positioning it as an up-to-date alternative to older parsers like Big Rig. It provides structured main thread task data, including task kind, timing, and an event hierarchy, crucial for detailed performance analysis.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to load a Chromium trace (using a mock JSON for direct runnability) and parse its main thread tasks, showing task type, duration, and self-time for performance analysis.

const fs = require('fs');
const Tracium = require('tracium');

// In a real application, you'd load a trace file like this:
// const traceJSON = JSON.parse(fs.readFileSync('./mytrace.json', 'utf8'));

// For demonstration, we'll create a minimal mock trace structure.
// A real Chromium trace file would be significantly larger and more complex.
const mockTraceJSON = {
  'traceEvents': [
    { 'ph': 'M', 'pid': 1, 'tid': 1, 'name': 'process_name', 'args': { 'name': 'Browser' } },
    { 'ph': 'M', 'pid': 1, 'tid': 2, 'name': 'thread_name', 'args': { 'name': 'CrRendererMain' } },
    { 'ph': 'X', 'cat': 'devtools.timeline', 'name': 'ParseHTML', 'pid': 1, 'tid': 2, 'ts': 1000, 'dur': 500, 'args': {} },
    { 'ph': 'X', 'cat': 'devtools.timeline', 'name': 'EvaluateScript', 'pid': 1, 'tid': 2, 'ts': 1600, 'dur': 300, 'args': {} },
    { 'ph': 'X', 'cat': 'devtools.timeline', 'name': 'InvalidEvent', 'pid': 1, 'tid': 2, 'ts': 1900, 'dur': 100, 'args': {} }
  ],
  'metadata': { 'clockDomain': 'timeSinceEpoch', 'numProcs': 1 }
};

const tasks = Tracium.computeMainThreadTasks(mockTraceJSON, {
  // Set flatten to true to get all tasks, including child tasks, in a single array.
  flatten: true,
});

console.log('Computed Main Thread Tasks:');
tasks.forEach(task => {
  console.log(`- Kind: ${task.kind}, Duration: ${task.duration.toFixed(3)}ms, SelfTime: ${task.selfTime.toFixed(3)}ms`);
});
/*
Example output for the mock trace:
- Kind: parseHTML, Duration: 0.500ms, SelfTime: 0.500ms
- Kind: scriptEvaluation, Duration: 0.300ms, SelfTime: 0.300ms
- Kind: other, Duration: 0.100ms, SelfTime: 0.100ms
*/

view raw JSON →