A non-sampling profiler purpose built to measure and optimize performance of C++ low latency/real time systems
A non-sampling profiler purpose built to measure and optimize performance of C++ low latency/real time systems
A non-sampling profiler, purpose built to measure and optimise, performance of ultra-low-latency / real time systems.
The main features include
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.
| 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 |
To build xpedite, you will need a linux machine (kernel 2.5 or later) running on intel hardware with the following packages.
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
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.
#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 -lrtThe explicit path statements may not be necessary, depending on where/how xpedite have been installed on your system.
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).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
+ button next to save file icon or pressing hot key bshift + 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 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.
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.
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
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 >
No open issues yet, or sync has not completed.