GithubHelp home page GithubHelp logo

ljpwuguo / hwcpipe Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arm-software/libgpucounters

0.0 0.0 0.0 329 KB

Hardware counters interface

License: MIT License

Shell 0.13% C++ 96.32% C 1.08% CMake 1.33% Dockerfile 1.14%

hwcpipe's Introduction

HWCPipe

Introduction

HWCPipe is a simple and extensible interface for reading CPU and GPU hardware counters.

License

The software is provided under an MIT license.

This project has a third-party dependency, which may have independent licensing:

Contributions

All contributions are accepted under the same LICENSE.

Building

To use HWCPipe, build it as a shared library in your project.

If your project uses CMake, you can add the following to your CMakeLists.txt:

add_subdirectory(hwcpipe)

Usage

Using HWCPipe

Basic usage for HWCPipe is simple:

// HWCPipe performs automated platform detection for CPU/GPU counters
hwcpipe::HWCPipe h;

// Start HWCPipe once at the beginning of the profiling session
h.run();

while (main_loop) {
    // Call sample() to sample counters with the frequency you need
    auto measurements = h.sample();

    [...]
}

// At the end of the profiling session, stop HWCPipe
h.stop();

The sample function returns a Measurements struct, which can be accessed like this:

// Check if CPU measurements are available
if (measurements.cpu)
{
    // Look for a counter in the map
    const auto &counter = measurements.cpu->find(CpuCounter::Cycles);
    if (counter != measurements.cpu->end())
    {
        // Get the data stored in the counter, casted to the type you need
        auto value = counter->second.get<float>();
    }
}

Enabling counters

The available counters are specified in the CpuCounter and GpuCounter enums (cpu_profiler.h and gpu_profiler.h respectively).

Platforms will support a subset of these counters, which can be queried via:

auto cpu_counters = h.cpu_profiler()->supported_counters();
auto gpu_counters = h.gpu_profiler()->supported_counters()

You can specify the counters to be enabled in the following ways:

// Enable a default set of counters
auto h = hwcpipe::HWCPipe();

// Pass sets of CPU and GPU counters to be enabled
auto h = hwcpipe::HWCPipe({CpuCounter::Cycles, CpuCounter::Instructions}, {GpuCounter::GpuCycles});

// Pass a JSON string
auto h = hwcpipe::HWCPipe(json);

The JSON string should be formatted like this:

{
    "cpu": ["Cycles", "Instructions"],
    "gpu": ["GpuCycles"]
}

Available counter names can be found in cpu_counter_names (cpu_profiler.h) and gpu_counter_names (gpu_profiler.h).

For more information regarding Mali counters, see Mali Performance Counters.

Enabling profiling on Android

In order for performance data to be displayed, profiling needs to be enabled on the device. Some devices may disable it by default.

Profiling can be enabled via adb:

adb shell setprop security.perf_harden 0

Adding support for a new platform

If the counters provided in CpuCounter and GpuCounter are enough for the new platform, the process is simple:

  • Add an implementation of either CpuProfiler of GpuProfiler (you can use PmuProfiler and MaliProfiler as references).
  • Add your platform to the automated platform detection in hwcpipe.cpp. For consistency in platform detection, the constructor for your platform should throw if the platform is not available.
  • Add your platform to the build system.

Adding new counters

If you need to add new counters to the existing ones, you should update the following variables:

  • Add the counter to the CpuCounter/GpuCounter enum.
  • Add the counter name to the cpu_counter_names/gpu_counter_names map (necessary for JSON initialization).
  • Add a description and the unit for your counter to the cpu_counter_info/gpu_counter_info map.

The CpuCounter and GpuCounter enums are meant to be expanded. Platforms must not break if new counters are added.

hwcpipe's People

Contributors

attilioprovenzano-arm avatar joseemilio-arm avatar wasimabbas-arm avatar ryanoshea-arm avatar solidpixel avatar zandrofargnoli avatar per-mathisen-arm avatar antonio-caggiano-arm avatar bengaineyarm avatar ilelann avatar ming4883 avatar sm-powell avatar steffenlarsen avatar akastix avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.