KEMBAR78
API for profiling non-Java apps · Issue #751 · async-profiler/async-profiler · GitHub
Skip to content

API for profiling non-Java apps #751

@apangin

Description

@apangin

Background

async-profiler was designed for profiling JVM processes. Unlike traditional Java profilers, it monitors non-Java threads (e.g., GC threads) and also shows native frames in Java stack traces. async-profiler parses symbols from shared libraries and uses DWARF info for stack walking. Basically, async-profiler can already do much of what can be expected from a non-Java profiler.

Proposal

Given that async-profiler already deals with non-Java threads, it should be possible to make it work for C, C++ or Rust applications. Currently there are many dependencies on the JVM runtime in the code. The idea of this proposal is to factor out all JVM dependencies so that async-profiler will work with processes that have no libjvm.so loaded.

Since dynamic attach does not work for native applications, the scope of this proposal is limited to the case when profiler is controlled programmatically from the process being profiled. Similarly to the existing Java API, there will be C API for using inside native applications.

API

typedef const char* asprof_error_t;
typedef void (*asprof_writer_t)(const char* buf, size_t size);

// Should be called once prior to any other API functions
void asprof_init();

// Returns an error message for the given error code or NULL if there is no error
const char* asprof_error_str(asprof_error_t err);

// Executes async-profiler command using output_callback as an optional sink
// for the profiler output. Returning an error code or NULL on success.
asprof_error_t asprof_execute(const char* command, asprof_writer_t output_callback);

Notes

All basic functionality remains the same. Profiler can run in cpu, wall and other perf_events modes. Flame Graph and JFR output formats are supported, although JFR files will obviously lack Java-specific events.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions