百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
X

Xpedite

> 数据库
开源

一款专门用于测量和优化 C++ 低延迟/实时系统性能的非抽样分析器

197 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一款专门用于测量和优化 C++ 低延迟/实时系统性能的非抽样分析器

Xpedite

A non-sampling profiler, purpose built to measure and optimise, performance of ultra-low-latency / real time systems.

The main features include

  1. Targeted Profiling - Quantify how efficiently a section of code, runs in any Intel CPU and how much head room is left for further optimizations.
  2. PMU counters - Capture hundreds of processor specific performance counters like cache/TLB misses, CPU Stalls, NUMA remote access, context switches, etc.
  3. Cycles accounting - Find percent of retiring vs stalled cpu cycles with Topdown micro architecture analysis.
  4. Optimization heuristics - Narrow down cpu bottlenecks, with potential for maximum application speed up.
  5. Analytics & visualization - Provides a Jupiter shell for interactive drill down and visualization of performance metrics and bottlenecks.
  6. Regression detection - Benchmark multiple releases/builds side-by-side, to detect and prevent regression across releases.

Why yet another profiler ?

Xpedite grew in the world of automated low latency trading systems, where latency directly translates to profitability. Such trading systems typically never relinquish cpu, but rather spin in a tight loop always looking for external events. Eventually when an event is detected, the engine would need to react in a few microseconds.

In cases where events occur less frequently, the amount of time spent waiting, far exceeds the time spent by the critical path reacting. Profiling such low-latency systems becomes a real challenge, with off the shelf sampling profilers like linux perf or Intel vtune.

Sampling profilers, as the name implies, will sample timestamps and performance counters from the cpu, based on some counter firing frequency. For trading systems, such a sample set will be dominated by samples from the wait loop, rather than from the critical path, which reacts to events.

Due to this, sampling profilers typically end up profiling the least interesting part of the code, while ignoring the critical path. What we really need is an intrusive profiler, which can target and collect samples only during execution of desired critical path(s). Xpedite is primarily built to optimize real time systems of the nature described above.

Quick Start

section description
Building Build and install xpedite
Instrumentation Instrument C++ programs to identify profiling targets
Profiler Initialisation Enable profiling by initialising profiling framework
Profiling Attach to a live process and collect performance statistics
Xpedite Shell A shell to explore performance statistics
Benchmarking View profiles of multiple builds side by side
Hardware performance counters Collect and visualise cpu hardware performance counters
Cycle Accounting Cycle accounting using topdown micro architecture analysis methodology
Collaboration Collaborate in troubleshooting performance bottlenecks
Quality of life features Lazy to write your own profile info ? why not auto generate it ?
Support Need help ?
Acknowledgements Thanks to our contributors

Building

To build xpedite, you will need a linux machine (kernel 2.5 or later) running on intel hardware with the following packages.

  1. cmake (3.4 or later)
  2. GNU gcc (5.2 or later)
  3. python 3
  4. pybind11
  5. python 3 venv

With the above installed, to use xpedite, clone this repository and run the following from xpedite source dir:

$ ./build.sh      # builds xpedite c++ library

$ ./install.sh    # creates a virtual environment and installs xpedite python dependencies

$ alias xpedite="PATH=`pwd`/install/runtime/bin `pwd`/scripts/bin/xpedite" # Adds an alias for xpedite to shell

The build process will produce a static library, libxpedite.a, which can be linked into a C++ executable (if you want to use xpedite in a position independent executable, the build produces a different static library to use, libxpedite-pie.a).

In addition, the build process will produce a demo program, xpediteDemo. This program is a hello world example of - How to profile a c++ program with xpedite.

The demo source also serves as working example of xpedite instrumentation and profiling. To see it in action, run demo/demo.sh

Instrumentation

Xpedite is an intrusive probe based profiler. Profiling starts with careful instrumentation of application code with probes. Let's consider how to instrument a simple C++ program.

cpp
  #include 
  #include 

  void eat()   { std::cout 
    #include 

    int main() {
      if(!xpedite::framework::initialize("/tmp/xpedite-appinfo.txt")) {
        throw std::runtime_error {"failed to init xpedite"}; 
      }
      life(100);
    }

In the above program, the AppInfo is placed at filesystem path "/tmp/xpedite-appinfo.txt". The second argument is an optional boolean parameter, to make the application wait, till a profiler attaches to the process.

Finally, To build this simple program, add the two snippets above to a file called Life.C and run

$ g++ -pthread -std=c++11 -I  Life.C -o life -L  -lxpedite -ldl -lrt

The explicit path statements may not be necessary, depending on where/how xpedite have been installed on your system.

Profiling

Xpedite probes start as 5 byte NOP instructions and have near zero overhead during normal execution. The profiler when attached to a process, can activate all or a subset of probes, for collection of timing and hardware counters. All profile parameters, including path to AppInfo, list of probes etc ... are specified in a python module called "profileInfo.py".

Let's see an example of a minimalistic profileInfo, that can be used to profile the above program.

…

With the above code stored in the file profileInfo.py, let's build a profile by running the application, followed by attaching xpedite to it.

If you followed all the steps, listed in the previous sections, by now you would have built a program called "life". Starting the program from a command line will, print messages similar to ones shown below.

  1 info Tue Mar  6 14:27:13 2018 Listener xpedite [fd - 4 | ip - 0.0.0.0 | port - 0 | mode - NON-Blocking binding to port 0
  2 info Tue Mar  6 14:27:13 2018 Listener xpedite [fd - 4 | ip - 0.0.0.0 | port - 57474 | mode - NON-Blocking listening for incoming connections 33504
  3 info Tue Mar  6 14:27:18 2018 xpedite - accepted incoming connection from ip - 127.0.0.1 | port - 64538 | fd - 3 | mode - NON-Blocking
  ...

To attach the profiler to the running process, invoke xpedite record -p profileInfo.py -H 1 from console. If everything works, the profiler after collecting profile data from the target process, will start an instance of jupyter.

Open the url in console, with a web browser, to see the results.

extracting counters for thread 61843 from file /dev/shm/xpedite-life-1520365531-61843.data ->  completed in 0.03 sec.
...
generating notebook life-2018-03-06-14:45:31.ipynb ->
 completed 5.4 KiB in 0.08 sec.
 [I 14:45:34.331 NotebookApp] Writing notebook server cookie secret to /tmp/xpediteShell0Uu2xn/.local/share/jupyter/runtime/notebook_cookie_secret
 ...
 [I 14:45:34.533 NotebookApp] The IPython Notebook is running at: http://10.198.37.19:8889/
 [I 14:45:34.533 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

Xpedite Shell

Browsing the url, opens a page with a list of xpedite reports (files with .ipynb extension). Your page may contain, just one report as shown below.

Clicking on the ipynb link, opens a interactive shell, with a summary of the profile.

Below the summary, the report will include a histogram for latency distribution, plotting time in x-axis and transaction count in y-axis.

This visualisation is a good starting point for getting an overview of application's latency profile.

The shell also supports commands to filter, query and dynamically generate other visualisations to analyze profile data.

To run a new command

  1. First add an empty cell by clicking + button next to save file icon or pressing hot key b
  2. Enter a xpedite shell commands or any valid python snippet
  3. To finally run the command, click the play icon or press hot key shift + enter.

For instance, running xpedite command txns() will print a table with 100 transactions (as shown below).

Before you go any further, Let's take a moment to get familiar with a core xpedite concept.

Transaction

Transaction is any functionality in the program, that is a meaningful target for profiling and optimisations.

A transaction stores data (timestamps and h/w counters) from a collection of probes, that got hit, during program execution to achieve the functionality.

The transactions can be used to generate statistics and visualisations for total end to end latency, and latency between each pair of probes.

Let's look at, how profile info and instrumentation work together to build transactions, in the above program.

The method life() is instrumented at three places.

  1. XPEDITE_TXN_SCOPE(Life)
  2. XPEDITE_PROBE(SleepBegin)
  3. XPEDITE_PROBE(CodeBegin)

Each instantiation of XPEDITE_PROBE inserts one named probe (first argument) in the control flow.

Probe scope macros like XPEDITE_TXN_SCOPE however, inserts a pair of named probe. The first probe is inserted at the point of instrumentation, while the second one at the end of block scope(RAII).

With the above instrumentation in place, each iteration of the loop in life(), will hit the following 4 probes in order.

  1. LifeBegin
  2. SleepBegin
  3. CodeBegin
  4. LifeEnd

Since we are interested in measuring loop iteration latency, the route LifeBegin -> SleepBegin -> CodeBegin -> LifeEnd is used to build transactions. We expect to see 100 transactions, one per iteration of the loop.

The txns() command obliges by returning the table below with 100 rows (one row per transaction). The columns in the table, matches the expected route, with control flowing from left to right. Each cell in a row, shows the latency for execution of, code between the probe for the current column and the next one.

From the table, Let's see, how one can infer latency stats for a transaction. Looking at the first row, we can see the below stats for the first transaction

  1. Total time - 618.572 us
  2. Time spent in eat() - 615.559 us
  3. Time spent in sleep() - 1.670 us
  4. Time spent in code() - 1.343 us

Now let's do something interesting. Instead of listing all transactions, let's just list outliers (transactions, that took longer than expected)

The command ```filter(lambda txn: txn.duration >

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Pythonbenchmarkingcpu-profilerinteljupyter

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库