Convert Figma logo to code with AI

google logoperfetto

Performance instrumentation and tracing for Android, Linux and Chrome (read-only mirror of https://android.googlesource.com/platform/external/perfetto/)

2,740
342
2,740
47

Top Related Projects

Performance analysis tools based on Linux perf_events (aka perf) and ftrace

Deprecated Catapult GitHub. Please instead use http://crbug.com "Speed>Benchmarks" component for bugs and https://chromium.googlesource.com/catapult for downloading and editing source code..

PerfView is a CPU and memory performance-analysis tool

3,577

Vector is an on-host performance monitoring framework which exposes hand picked high resolution metrics to every engineer’s browser.

4,160

C/C++ Performance Profiler

Quick Overview

Perfetto is an open-source system profiling, app tracing, and trace analysis platform developed by Google. It provides a comprehensive set of tools for performance analysis across various platforms, including Android, Linux, and Chrome OS. Perfetto aims to offer a unified solution for capturing, storing, and analyzing performance data.

Pros

  • Cross-platform support (Android, Linux, Chrome OS)
  • Highly efficient and low-overhead tracing
  • Extensible architecture with custom data sources
  • Powerful web-based trace viewer for analysis

Cons

  • Steep learning curve for advanced usage
  • Limited documentation for some features
  • Primarily focused on Google-related platforms
  • May require root access for certain tracing features

Code Examples

  1. Initializing a Perfetto tracing session:
#include "perfetto/tracing.h"

void InitializeTracing() {
  perfetto::TracingInitArgs args;
  args.backends = perfetto::kSystemBackend;
  perfetto::Tracing::Initialize(args);
}
  1. Adding a track event to the trace:
TRACE_EVENT_BEGIN("category", "EventName");
// ... code to be measured ...
TRACE_EVENT_END("category");
  1. Creating a custom data source:
class MyDataSource : public perfetto::DataSource<MyDataSource> {
 public:
  void OnSetup(const SetupArgs&) override {}
  void OnStart(const StartArgs&) override {}
  void OnStop(const StopArgs&) override {}
};

PERFETTO_DECLARE_DATA_SOURCE_STATIC_MEMBERS(MyDataSource);
PERFETTO_REGISTER_DATA_SOURCE(MyDataSource);

Getting Started

To start using Perfetto in your project:

  1. Include Perfetto in your build system (e.g., via CMake or Bazel).
  2. Initialize tracing in your application:
#include "perfetto/tracing.h"

int main() {
  perfetto::TracingInitArgs args;
  args.backends = perfetto::kInProcessBackend;
  perfetto::Tracing::Initialize(args);

  perfetto::TrackEvent::Register();

  // Your application code here
  TRACE_EVENT_BEGIN("app", "MainLoop");
  // ...
  TRACE_EVENT_END("app");

  return 0;
}
  1. Build and run your application with Perfetto tracing enabled.
  2. Use the Perfetto trace viewer (https://ui.perfetto.dev/) to analyze the captured traces.

Competitor Comparisons

Performance analysis tools based on Linux perf_events (aka perf) and ftrace

Pros of perf-tools

  • Lightweight and easy to use, with minimal setup required
  • Focuses on Linux performance analysis tools, making it ideal for Linux-specific debugging
  • Provides a collection of individual scripts, allowing users to pick and choose tools as needed

Cons of perf-tools

  • Limited cross-platform support compared to Perfetto's broader compatibility
  • Less comprehensive data visualization and analysis capabilities
  • Lacks the advanced tracing and profiling features offered by Perfetto

Code Comparison

perf-tools (execsnoop):

#!/bin/bash
# Trace new processes with arguments
stdbuf -oL perf script -F comm,pid,ppid,args | \
    awk '$1 != "-" && $1 != "perf" {print}'

Perfetto (trace config):

TraceConfig config;
config.add_buffers()->set_size_kb(1024);
auto* ds = config.add_data_sources()->mutable_config();
ds->set_name("linux.ftrace");
ds->set_target_buffer(0);

Both repositories provide valuable performance analysis tools, but they cater to different use cases. perf-tools offers a collection of lightweight, Linux-specific scripts for quick debugging, while Perfetto provides a more comprehensive, cross-platform tracing and profiling solution with advanced visualization capabilities.

Deprecated Catapult GitHub. Please instead use http://crbug.com "Speed>Benchmarks" component for bugs and https://chromium.googlesource.com/catapult for downloading and editing source code..

Pros of Catapult

  • More comprehensive suite of web performance tools, including Telemetry and Trace-Viewer
  • Longer history and established ecosystem within the Chromium project
  • Supports a wider range of performance analysis scenarios beyond tracing

Cons of Catapult

  • Larger and more complex codebase, potentially harder to maintain
  • Less focus on efficient, low-overhead tracing compared to Perfetto
  • May have slower adoption of new features due to its broader scope

Code Comparison

Catapult (Python-based):

from telemetry import story
from telemetry.page import page as page_module

class MyStorySet(story.StorySet):
    def __init__(self):
        super(MyStorySet, self).__init__()
        self.AddStory(page_module.Page('http://www.google.com', self, name='Google'))

Perfetto (C++-based):

#include "perfetto/tracing.h"

PERFETTO_DEFINE_CATEGORIES(perfetto::Category("rendering").SetDescription("Rendering events"));

void MyTracingFunction() {
    TRACE_EVENT("rendering", "Frame");
}

The code snippets showcase the different approaches: Catapult focuses on web performance testing with Python, while Perfetto provides low-level C++ tracing APIs for efficient system-wide profiling.

PerfView is a CPU and memory performance-analysis tool

Pros of PerfView

  • Specifically designed for .NET and Windows performance analysis
  • Includes a rich GUI for data visualization and analysis
  • Offers extensive documentation and tutorials for users

Cons of PerfView

  • Limited cross-platform support compared to Perfetto
  • Less flexible for custom data sources and trace formats
  • Primarily focused on Windows ecosystem, limiting its use in other environments

Code Comparison

PerfView (C#):

TraceEventSession session = new TraceEventSession("MySession");
session.EnableProvider("Microsoft-Windows-DotNETRuntime");
session.Source.Dynamic.All += (TraceEvent data) => {
    Console.WriteLine($"Got Event {data.EventName}");
};

Perfetto (C++):

perfetto::TracingInitArgs args;
perfetto::Tracing::Initialize(args);
auto* tracing_session = perfetto::Tracing::NewTrace();
tracing_session->Setup(config);
tracing_session->Start();

Both tools provide APIs for setting up tracing sessions, but PerfView is more focused on .NET-specific providers, while Perfetto offers a more generic approach suitable for various platforms and data sources.

3,577

Vector is an on-host performance monitoring framework which exposes hand picked high resolution metrics to every engineer’s browser.

Pros of Vector

  • Designed specifically for high-performance service-to-service networking
  • Focuses on observability and telemetry for cloud-native environments
  • Supports a wide range of data sources and sinks

Cons of Vector

  • Less comprehensive tracing capabilities compared to Perfetto
  • May have a steeper learning curve for users not familiar with cloud-native observability concepts
  • Limited support for low-level system tracing

Code Comparison

Vector configuration example:

[sources.http_server]
type = "http_server"
address = "0.0.0.0:80"

[sinks.console]
type = "console"
inputs = ["http_server"]
encoding.codec = "json"

Perfetto configuration example:

buffers {
  size_kb: 63488
  fill_policy: DISCARD
}
data_sources {
  config {
    name: "linux.process_stats"
    target_buffer: 0
    process_stats_config {
      proc_stats_poll_ms: 1000
    }
  }
}

Vector is more focused on configuring data pipelines for observability, while Perfetto's configuration is geared towards detailed system tracing and performance analysis. Both projects serve different primary use cases, with Vector excelling in cloud-native environments and Perfetto providing deeper insights into system-level performance.

4,160

C/C++ Performance Profiler

Pros of Orbit

  • More focused on game and graphics profiling, with features tailored for GPU profiling and frame analysis
  • Offers a user-friendly GUI for easier data visualization and interaction
  • Supports live profiling and real-time data collection

Cons of Orbit

  • Limited to Windows and Linux platforms, lacking macOS support
  • Narrower scope compared to Perfetto's system-wide tracing capabilities
  • Less extensive documentation and community resources

Code Comparison

Orbit (C++):

void OrbitApp::SelectCallstackEvents(
    const std::vector<CallstackEvent>& selected_callstack_events) {
  selected_callstack_events_ = selected_callstack_events;
  UpdateSelectionReport();
}

Perfetto (C++):

void TraceProcessor::EnableMetatrace() {
  metatrace::Enable();
  metatrace_id_ = metatrace::InternString("TraceProcessor::EnableMetatrace");
}

Both projects use C++ and demonstrate object-oriented programming. Orbit's code focuses on UI-related functionality, while Perfetto's example shows low-level tracing operations. Perfetto's codebase is generally more extensive and covers a broader range of tracing scenarios.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Perfetto - System profiling, app tracing and trace analysis

Perfetto is a production-grade open-source stack for performance instrumentation and trace analysis. It offers services and libraries and for recording system-level and app-level traces, native + java heap profiling, a library for analyzing traces using SQL and a web-based UI to visualize and explore multi-GB traces.

See https://perfetto.dev/docs or the /docs/ directory for documentation.