### Install POCO C++ Library Prerequisites Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-POCO Installs necessary development packages for OpenSSL and iODBC on Debian-based systems. These are common dependencies for network and database operations within the POCO library. ```bash $ sudo apt-get install openssl libssl-dev $ sudo apt-get install libiodbc2 libiodbc2-dev ``` -------------------------------- ### Ubuntu TBB Installation Commands Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-parallel-sort-algorithm These shell commands install the Intel Thread Building Blocks (TBB) library on Ubuntu systems. It adds the necessary repository and then installs the development package. This is a prerequisite for compiling the parallel sorting example. ```shell echo "deb http://cz.archive.ubuntu.com/ubuntu focal main universe" | sudo tee -a /etc/apt/sources.list sudo apt update sudo apt install libtbb-dev ``` -------------------------------- ### Download and Checkout POCO Library Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-POCO Clones the POCO C++ library repository from GitHub and checks out a specific release version (poco-1.7.5-release). This ensures a stable and reproducible build. ```bash $ git clone https://github.com/pocoproject/poco.git $ cd poco $ git checkout poco-1.7.5-release ``` -------------------------------- ### Install Build Dependencies Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-chromium Installs all required system dependencies for building Chromium. This includes compiler toolchains, development libraries, and build tools. Requires sudo privileges. Input: Chromium source root directory. Output: system packages installed for Chromium build. ```shell sudo ./build/install-build-deps.sh ``` -------------------------------- ### uftrace Installation Steps Source: https://github.com/namhyung/uftrace/wiki/Home These commands outline the process for installing uftrace from its source repository. It involves cloning the repository, navigating into the directory, optionally installing dependencies, configuring the build, and finally compiling and installing the tool. ```shell git clone https://github.com/namhyung/uftrace.git cd uftrace sudo misc/install-deps.sh # optional for advanced features ./configure # --prefix can be used to change install dir make sudo make install ``` -------------------------------- ### uftrace Record and Replay with Manual Argument Specification Source: https://github.com/namhyung/uftrace/blob/master/doc/uftrace-record.md Demonstrates how to record function calls with specific argument matching and replay them. The `-A` option specifies the argument pattern, and `-F` replays the trace. The example uses '.' to match any character in arguments. ```shell $ uftrace record -A . -R main ./hello Hello world $ uftrace replay -F main # DURATION TID FUNCTION [ 18948] | main(1, 0x7ffeeb7590b8) { 7.183 us [ 18948] | puts("Hello world"); 9.832 us [ 18948] | } = 0; /* main */ ``` -------------------------------- ### uftrace Dynamic Tracing with Patching and Unpatching Source: https://github.com/namhyung/uftrace/blob/master/doc/uftrace-record.md Illustrates how to combine patch (`-P`) and unpatch (`-U`) options for fine-grained control over dynamic tracing. This example traces all functions except 'a' by first patching all functions ('.') and then unpatching 'a'. The order of options is crucial. ```shell $ uftrace record --no-libcall -P . -U a abc $ uftrace replay # DURATION TID FUNCTION [19390] | main() { [19390] | b() { 0.983 us [19390] | c(); 2.012 us [19390] | } /* b */ 3.373 us [19390] | } /* main */ $ uftrace record --no-libcall -U a -P . abc $ uftrace replay # DURATION TID FUNCTION [19390] | main() { [19390] | a() { [19390] | b() { 0.983 us [19390] | c(); 2.012 us [19390] | } /* b */ 2.451 us [19390] | } /* a */ 3.373 us [19390] | } /* main */ ``` -------------------------------- ### Record and replay tracing using uftrace (Shell) Source: https://github.com/namhyung/uftrace/blob/master/doc/uftrace-record.md Shell commands to compile the example program, record its execution with uftrace, and replay the collected trace. Demonstrates the typical workflow for using uftrace on a Linux system. Requires a GCC-compatible compiler. ```Shell $ cat abc.c $ gcc -pg -o abc abc.c $ uftrace record ./abc $ uftrace replay ``` -------------------------------- ### Clone and Install uftrace (Bash) Source: https://github.com/namhyung/uftrace/blob/master/doc/uftrace.html This Bash script performs a basic installation by cloning the uftrace repository, running configure to detect system features, building the project, and installing it system-wide. It requires git, gcc, and potentially sudo access for installation. The configure step outputs detected features like libelf and perf_event support; installation places binaries in /usr/local. ```bash $ git clone https://github.com/namhyung/uftrace && cd uftrace $ ./configure uftrace detected system features: ... prefix: /usr/local ... libelf: [ on ] - more flexible ELF data handling ... libdw: [ OFF ] - DWARF debug info support ... libpython: [ OFF ] - python tracing & scripting support ... libluajit: [ OFF ] - luajit scripting support ... libncursesw: [ OFF ] - TUI support ... cxa_demangle: [ on ] - full demangler support with libstdc++ ... perf_event: [ on ] - perf (PMU) event support ... schedule: [ on ] - scheduler event support ... capstone: [ OFF ] - full dynamic tracing support $ make $ sudo make install ``` -------------------------------- ### Configure and Build POCO with Profiling Flags Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-POCO Configures the POCO build using CMake, specifying installation prefix and enabling C/C++ compiler flags for debugging (`-g`) and profiling (`-pg`). The `-fno-omit-frame-pointer` flag is crucial for accurate profiling. Finally, it builds and installs the library. ```bash $ mkdir cmake_build $ cd cmake_build $ cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/usr \ -DCMAKE_C_FLAGS="-g -pg -fno-omit-frame-pointer" \ -DCMAKE_CXX_FLAGS="-g -pg -fno-omit-frame-pointer" $ make $ make install ``` -------------------------------- ### Compile POCO Test Program with Profiling Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-POCO Compiles the `poco-test.cpp` program using g++. It includes necessary header (`-I`) and library (`-L`, `-l`) paths for the POCO library and enables debugging (`-g`) and profiling (`-pg`) flags. The output executable is named `a.out`. ```bash $ g++ -pg -g -I$HOME/usr/include poco-test.cpp -L$HOME/usr/lib -lPocoFoundation $ ./a.out onEvent: 42 ``` -------------------------------- ### Environment Setup - depot_tools Configuration Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-chromium Sets up the PATH environment variable to include depot_tools directory. This is required for managing Chromium source code and dependencies. Input: current working directory containing depot_tools folder. Output: updated PATH variable. ```shell export PATH=`pwd`/depot_tools:$PATH ``` -------------------------------- ### GCC FENTRY Instrumentation with uftrace Source: https://github.com/namhyung/uftrace/blob/master/doc/uftrace-record.md Demonstrates using uftrace with binaries compiled using GCC's FENTRY instrumentation (`-mfentry`, `-mnop-mcount`). This method adds minimal overhead. The example shows recording and replaying all functions (`-P .`) from a program compiled with these GCC flags. ```shell $ gcc -pg -mfentry -mnop-mcount -o abc-fentry tests/s-abc.c $ uftrace record -P . --no-libcall abc-fentry $ uftrace replay # DURATION TID FUNCTION [ 18973] | main() { [ 18973] | a() { [ 18973] | b() { 0.852 us [ 18973] | c(); 2.378 us [ 18973] | } /* b */ 2.909 us [ 18973] | } /* a */ 3.756 us [ 18973] | } /* main */ ``` -------------------------------- ### Install GStreamer Prerequisites (Shell) Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-GStreamer Installs the necessary GStreamer libraries and plugins using apt-get. This is a prerequisite for running GStreamer applications. ```shell $ apt-get install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio ``` -------------------------------- ### Launch uftrace TUI Session Browser Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-chromium Launches uftrace Text User Interface for viewing recorded traces. Displays session list when multiple Chrome processes are recorded. Supports keyboard navigation for switching between sessions, viewing call graphs, generating reports, and accessing help. Input: uftrace data file. Output: interactive TUI interface for trace analysis. ```shell uftrace tui -t 30ms ``` -------------------------------- ### Install bpftrace Dependencies on Ubuntu Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-bpftrace Installs necessary development libraries for bpftrace on Ubuntu systems. It includes direct installation for newer Ubuntu versions and instructions for compiling bcc if needed for older versions. Essential build tools and LLVM components are also installed. ```bash # On ubuntu 19.04 & newer sudo apt-get install libbpfcc-dev # if not, compile bcc first # https://github.com/iovisor/bcc/blob/master/INSTALL.md#install-and-compile-bcc # For other distros, or detailed info can be found at: # https://github.com/iovisor/bpftrace/blob/master/INSTALL.md#building-bpftrace # install dependency sudo apt-get update sudo apt-get install -y bison cmake flex g++ git libelf-dev zlib1g-dev libfl-dev systemtap-sdt-dev sudo apt-get install -y llvm-7-dev llvm-7-runtime libclang-7-dev clang-7 ``` -------------------------------- ### Kernel Function Tracing Setup Source: https://context7.com/namhyung/uftrace/llms.txt Describes kernel function tracing capabilities that use the ftrace framework to correlate user-space and kernel-space execution within a unified timeline view. Requires root privileges and shows example output with kernel functions like __monstartup and __cxa_atexit alongside user-space functions. The kernel tracing provides detailed duration information for both user and kernel space operations. ```bash # Enable kernel tracing (requires root) sudo uftrace record -k ./program # Example output showing kernel functions: # DURATION TID FUNCTION # 1.365 us [21901] | __monstartup(); # 0.951 us [21901] | __cxa_atexit(); # [21901] | main() { # [21901] | fprintf() { ``` -------------------------------- ### Chromium Dependencies Sync Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-chromium Synchronizes Chromium third-party dependencies using gclient with shallow mode. This downloads all required dependencies for building Chromium. Requires gclient to be available in PATH. Input: current directory (Chromium source root). Output: all third-party dependencies downloaded. ```shell gclient sync --shallow ``` -------------------------------- ### POCO C++ Event and Delegate Test Program Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-POCO A C++ program demonstrating the POCO library's event and delegate mechanism. It defines a `Source` class that fires an event and a `Target` class that handles it. The `main` function sets up the event connection, fires the event, and then disconnects the handler. ```cpp #include "Poco/BasicEvent.h" #include "Poco/Delegate.h" #include using Poco::BasicEvent; using Poco::Delegate; class Source { public: BasicEvent theEvent; void fireEvent(int n) { theEvent(this, n); } }; class Target { public: void onEvent(const void* pSender, int& arg) { std::cout << "onEvent: " << arg << std::endl; } }; int main(int argc, char** argv) { Source source; Target target; source.theEvent += Delegate( &target, &Target::onEvent); source.fireEvent(42); source.theEvent -= Delegate( &target, &Target::onEvent); return 0; } ``` -------------------------------- ### Record Chrome Execution with uftrace Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-chromium Records function call trace of Chrome browser execution in headless mode. Uses 5ms time threshold and disables libcall recording for better performance. The browser is launched with no-sandbox and headless flags, visiting Google.com. Input: Chrome binary path. Output: uftrace data file with function call trace. ```shell uftrace record -t 5ms --no-libcall ./chrome --no-sandbox --headless https://www.google.com ``` -------------------------------- ### uftrace replay output example Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-LevelDB-RocksDB-with-YCSB Example output from uftrace replay showing function call tracing of db_bench execution. ```text $ uftrace replay # DURATION TID FUNCTION [ 14076] | _GLOBAL__sub_I_fLS::FLAGS_benchmarks::cxx11() { [ 14076] | __static_initialization_and_destruction_0() { 0.185 us [ 14076] | std::ios_base::Init::Init(); 0.088 us [ 14076] | __cxa_atexit(); 0.036 us [ 14076] | __cxa_atexit(); [ 14076] | std::__cxx11::basic_string::basic_string() { 2.617 us [ 14076] | strlen(); [ 14076] | std::__cxx11::basic_string::_M_construct() { 2.048 us [ 14076] | std::__cxx11::basic_string::_M_create(); 0.154 us [ 14076] | memcpy(); 2.558 us [ 14076] | } /* std::__cxx11::basic_string::_M_construct */ 8.249 us [ 14076] | } /* std::__cxx11::basic_string::basic_string */ [ 14076] | std::__cxx11::basic_string::_M_construct() { 0.072 us [ 14076] | std::__cxx11::basic_string::_M_create(); 0.057 us [ 14076] | memcpy(); 0.337 us [ 14076] | } /* std::__cxx11::basic_string::_M_construct */ 0.725 us [ 14076] | google::FlagRegisterer::FlagRegisterer(); 0.042 us [ 14076] | __cxa_atexit(); 2.743 us [ 14076] | google::FlagRegisterer::FlagRegisterer(); 0.292 us [ 14076] | google::FlagRegisterer::FlagRegisterer(); ``` -------------------------------- ### C Program for Threading Example Source: https://github.com/namhyung/uftrace/wiki/Tutorial A simple C program that demonstrates thread creation and function calls using pthreads. This code is used as an example for recording and replaying traces with uftrace. ```c #include void *bar(void) { return NULL; } void *foo(void *unused) { return bar(); } int main(int argc, char *argv[]) { pthread_t th; foo(argv); pthread_create(&th, NULL, foo, NULL); pthread_join(th, NULL); return 0; } ``` -------------------------------- ### Run uftrace Record and Replay on POCO Program Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-POCO Executes the compiled POCO test program (`./a.out`) under `uftrace`'s recording mode (`-D 2`). `uftrace` captures detailed function call information, including duration and call stack, which is then displayed in a structured format. The output shows the execution flow and timing of functions within the program. ```bash $ uftrace -D 2 ./a.out onEvent: 42 # DURATION TID FUNCTION [ 22588] | _GLOBAL__sub_I_main() { 6.700 us [ 22588] | __static_initialization_and_destruction_0(); 9.453 us [ 22588] | } /* _GLOBAL__sub_I_main */ [ 22588] | main() { 5.527 us [ 22588] | Source::Source(); 2.147 us [ 22588] | Poco::Delegate::Delegate(); 16.177 us [ 22588] | Poco::AbstractEvent::operator+=(); 5.197 us [ 22588] | Poco::Delegate::~Delegate(); 81.363 us [ 22588] | Source::fireEvent(); 0.906 us [ 22588] | Poco::Delegate::Delegate(); 8.780 us [ 22588] | Poco::AbstractEvent::operator-=(); 0.553 us [ 22588] | Poco::Delegate::~Delegate(); 3.910 us [ 22588] | Source::~Source(); 128.059 us [ 22588] | } /* main */ 1.800 us [ 22588] | std::ios_base::Init::~Init(); ``` -------------------------------- ### uftrace graph output example Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-LevelDB-RocksDB-with-YCSB Example output from uftrace graph showing function call hierarchy and timing information. ```text $ uftrace graph # Function Call Graph for 'db_bench' (session: d9c40b08019dd6c8) ========== FUNCTION CALL GRAPH ========== # TOTAL TIME FUNCTION 2.857 s : (1) db_bench 2.001 ms : +-(1) _GLOBAL__sub_I_fLS::FLAGS_benchmarks::cxx11 1.998 ms : | (1) __static_initialization_and_destruction_0 0.185 us : | +-(1) std::ios_base::Init::Init : | | 2.086 us : | +-(34) __cxa_atexit : | | 25.533 us : | +-(38) std::__cxx11::basic_string::basic_string 9.717 us : | | +-(38) strlen : | | | 7.481 us : | | +-(38) std::__cxx11::basic_string::_M_construct 2.110 us : | | +-(2) std::__cxx11::basic_string::_M_create : | | | 1.095 us : | | +-(23) memcpy : | | 4.000 us : | +-(37) std::__cxx11::basic_string::_M_construct 0.114 us : | | +-(2) std::__cxx11::basic_string::_M_create ``` -------------------------------- ### Example /proc/TID/maps Content Source: https://github.com/namhyung/uftrace/wiki/Data-Format This snippet shows an example of the /proc//maps file content, which is copied by uftrace into its session map files. It details memory mappings of tasks, providing base addresses for modules. ```shell $ cat /proc/24290/maps 00400000-00401000 r-xp 00000000 08:01 11729337 /home/taeung/git/uftrace/tests/t-abc 00600000-00601000 rw-p 00000000 08:01 11729337 /home/taeung/git/uftrace/tests/t-abc 02443000-02475000 rw-p 00000000 00:00 0 [heap] ... 7fba87229000-7fba8722b000 rw-p 001c3000 08:01 9968358 /lib/x86_64-linux-gnu/libc-2.23.so 7fba8722b000-7fba8722f000 rw-p 00000000 00:00 0 7fba8722f000-7fba87249000 r-xp 00000000 08:01 6558157 /usr/local/lib/libmcount-fast.so ... 7fba87676000-7fba87677000 rw-p 00000000 00:00 0 7ffe88f83000-7ffe88fa1000 rwxp 00000000 00:00 0 [stack] 7ffe88fa1000-7ffe88fa4000 rw-p 00000000 00:00 0 7ffe88fbd000-7ffe88fc0000 r--p 00000000 00:00 0 [vvar] 7ffe88fc0000-7ffe88fc2000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] ``` -------------------------------- ### C: Fibonacci Example Source: https://github.com/namhyung/uftrace/wiki/Filters A simple C program to calculate the Fibonacci sequence, used to demonstrate uftrace filters. ```c #include int fib(int n) { if (n <= 2) return 1; return fib(n-1) + fib(n-2); } int main(int argc, char *argv[]) { int n = 5; if (argc > 1) n = atoi(argv[1]); fib(n); return 0; } ``` -------------------------------- ### GStreamer Basic Tutorial 1 - Hello World (C) Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-GStreamer A basic GStreamer application written in C that initializes GStreamer, parses a pipeline to play a video, and manages the pipeline's state. It requires the GStreamer libraries to be installed. ```c #include int main (int argc, char *argv[]) { GstElement *pipeline; GstBus *bus; GstMessage *msg; /* Initialize GStreamer */ gst_init (&argc, &argv); /* Build the pipeline */ pipeline = gst_parse_launch ("playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm", NULL); /* Start playing */ gst_element_set_state (pipeline, GST_STATE_PLAYING); /* Wait until error or EOS */ bus = gst_element_get_bus (pipeline); msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS); /* Free resources */ if (msg != NULL) gst_message_unref (msg); gst_object_unref (bus); gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); return 0; } ``` -------------------------------- ### Generate and Build Chromium with uftrace Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-chromium Generates Ninja build files with uftrace enabled and builds Chrome binary. The gn gen command configures build with specific flags including use_uftrace=true. The ninja command performs actual compilation. Requires build dependencies to be installed. Input: Chromium source root. Output: compiled Chrome binary with mcount symbols. ```shell gn gen out/Release.pg.g "--args=enable_nacl=false is_component_build=false is_debug=false use_jumbo_build=true symbol_level=2 use_uftrace=true" ``` ```shell ninja -C out/Release.pg.g chrome ``` ```shell cd out/Release.pg.g ``` ```shell nm ./chrome | grep mcount ``` -------------------------------- ### Uftrace Output of Live Execution Source: https://github.com/namhyung/uftrace/wiki/Tutorial Sample output from the 'uftrace hello' command, illustrating the traced execution of the 'hello world' program. It shows the duration, thread ID, and function names, including library calls like '__monstartup', '__cxa_atexit', and 'puts'. ```text Hello world # DURATION TID FUNCTION 1.337 us [26639] | __monstartup(); 0.897 us [26639] | __cxa_atexit(); [26639] | main() { 6.696 us [26639] | puts(); 7.582 us [26639] | } /* main */ ``` -------------------------------- ### Chromium Configuration - gclient Setup Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-chromium Configures gclient for Chromium source code management. The .gclient file specifies the repository URL, disables managed mode, and sets up custom dependencies. This is required for syncing Chromium source and dependencies. Input: current directory. Output: configured .gclient file. ```python solutions = [ { "url": "https://chromium.googlesource.com/chromium/src.git", "managed": False, "name": "src", "custom_deps": {}, }, ] ``` -------------------------------- ### C Hello World Program Source: https://github.com/namhyung/uftrace/wiki/Tutorial A simple 'Hello World' program written in C, used as a basic example for demonstrating uftrace functionality. It includes standard input/output and a main function. ```c #include int main(void) { printf("Hello world\n"); return 0; } ``` -------------------------------- ### Filter Functions by Regex Pattern with Uftrace Source: https://github.com/namhyung/uftrace/wiki/Filters This example shows how to use the '-F' option with a regular expression to filter trace output. The '^std' pattern matches all functions starting with 'std', useful for filtering by namespace or class prefix in C++. ```bash $ uftrace replay -F ^std # DURATION TID FUNCTION 125.297 us [26181] | std::ios_base::Init::Init(); 17.510 us [26181] | std::operator <<(); 18.502 us [26181] | std::basic_ostream::operator <<(); 2.665 us [26181] | std::ios_base::Init::~Init(); ``` -------------------------------- ### C++: Hello World Example Source: https://github.com/namhyung/uftrace/wiki/Filters A simple C++ program that prints "Hello C++" to the console, used to demonstrate function filters. ```cpp #include using namespace std; int main() { cout << "Hello C++" << endl; return 0; } ``` -------------------------------- ### Compile GStreamer Example with GCC (Shell) Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-GStreamer Compiles the 'basic-tutorial-1.c' file using GCC, linking against the GStreamer 1.0 libraries. The '-pg' flag enables profiling for tools like uftrace. ```shell $ gcc -pg basic-tutorial-1.c -o basic-tutorial-1 `pkg-config --cflags --libs gstreamer-1.0` ``` -------------------------------- ### Chromium Directory Creation Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-chromium Creates and navigates to a chromium directory for storing Chromium source code. This organizes the build environment and separates Chromium files from other projects. Input: current working directory. Output: new chromium directory. ```shell mkdir chromium && cd chromium ``` -------------------------------- ### Chromium Source Download Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-chromium Performs shallow git clone of Chromium source code at specific version tag and navigates to source directory. Uses depth=1 for faster download of specific version. Input: current directory. Output: Chromium source code at version 73.0.3676.0. ```shell git clone --depth=1 https://chromium.googlesource.com/chromium/src.git -b 73.0.3676.0 ``` ```shell cd src ``` -------------------------------- ### Execute Basic uftrace Live Tracing Source: https://github.com/namhyung/uftrace/blob/master/doc/uftrace-live.md Executes uftrace with default live tracing on the compiled program. Shows all function calls including library functions and the complete call chain. Demonstrates default behavior without filters before applying any filtering options. ```shell uftrace live ./abc ``` -------------------------------- ### C++ Parallel Sort Implementation and Profiling Setup Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-parallel-sort-algorithm This C++ code implements sequenced, parallel, and parallel unsequenced sorts for a vector of integers. It includes a function to fill the vector with random numbers and a main function to execute and profile these sorting methods using uftrace. Requires C++17 and Intel TBB. ```cpp #include #include #include #include #include void fill_random(std::vector &v, int n) { srand(static_cast(time(nullptr))); for (int i = 0; i < n; i++) v.push_back(rand() % n); } void sequenced_sort(std::vector v) { std::sort(std::execution::seq, v.begin(), v.end()); } void parallel_sort(std::vector v) { std::sort(std::execution::par, v.begin(), v.end()); } void parallel_unsequenced_sort(std::vector v) { std::sort(std::execution::par_unseq, v.begin(), v.end()); } int main(int argc, char *argv[]) { std::vector v; int n = 5000; if (argc == 2) n = std::atoi(argv[1]); fill_random(v, n); sequenced_sort(v); parallel_sort(v); parallel_unsequenced_sort(v); } ``` -------------------------------- ### Clone GStreamer Documentation Repository (Shell) Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-GStreamer Clones the GStreamer documentation repository from GitLab. This repository contains example source code and documentation for GStreamer tutorials. ```shell $ git clone https://gitlab.freedesktop.org/gstreamer/gst-docs ``` -------------------------------- ### uftrace Dynamic Tracing with Patching (No Compilation) Source: https://github.com/namhyung/uftrace/blob/master/doc/uftrace-record.md Shows how to dynamically trace a function 'a()' without recompiling the binary using the `-P` (patch) option. This is useful when the binary is not compiled with instrumentation flags. The example first shows an error when 'mcount' is missing, then demonstrates successful tracing with `-P a` and patching all functions with `-P .`. ```shell $ gcc -o abc tests/s-abc.c $ uftrace abc uftrace: /home/namhyung/project/uftrace/cmd-record.c:1305:check_binary ERROR: Can't find 'mcount' symbol in the 'abc'. It seems not to be compiled with -pg or -finstrument-functions flag which generates traceable code. Please check your binary file. $ uftrace record --no-libcall -P a abc $ uftrace replay # DURATION TID FUNCTION 0.923 us [19379] | a(); $ uftrace record --no-libcall -P . abc $ uftrace replay # DURATION TID FUNCTION [19387] | main() { [19387] | a() { [19387] | b() { 0.940 us [19387] | c(); 2.030 us [19387] | } /* b */ 2.451 us [19387] | } /* a */ 3.289 us [19387] | } /* main */ ``` -------------------------------- ### Watching CPU Changes with uftrace Source: https://github.com/namhyung/uftrace/blob/master/doc/uftrace-record.md Monitors the CPU number on which the current task runs using the -W cpu option. Displays changes as events in trace output at function entry/exit. Requires uftrace installed; outputs trace with comments like /* watch:cpu (cpu=8) */; may miss intra-function changes. ```bash uftrace -W cpu tests/t-abc ``` -------------------------------- ### Replay CUDA Trace with Full Dynamic Tracing (uftrace) Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-CUDA This snippet demonstrates how to use the `uftrace` command-line tool to perform a full dynamic trace of a CUDA application. It shows the command to initiate the tracing and a sample output illustrating the captured function calls, durations, and thread IDs, including CUDA runtime and related functions. ```bash $ uftrace -P . ./simpleCallback Starting simpleCallback Found 2 CUDA capable GPUs GPU[0] NVIDIA GeForce RTX 3080 supports SM 8.6, capable GPU Callback Functions GPU[1] NVIDIA GeForce RTX 3080 supports SM 8.6, capable GPU Callback Functions 2 GPUs available to run Callback Functions Starting 8 heterogeneous computing workloads Total of 8 workloads finished: Success # DURATION TID FUNCTION [ 31969] | __cudart426() { [ 31969] | __cudart1635() { [ 31969] | pthread_once() { [ 31969] | __cudart1670() { 0.140 us [ 31969] | malloc(); [ 31969] | __cudart1332() { 0.160 us [ 31969] | pthread_mutexattr_init(); 0.060 us [ 31969] | pthread_mutexattr_settype(); 0.060 us [ 31969] | pthread_mutexattr_setpshared(); 0.100 us [ 31969] | pthread_mutex_init(); 0.060 us [ 31969] | pthread_mutexattr_destroy(); 1.380 us [ 31969] | } /* __cudart1332 */ [ 31969] | atexit() { 0.110 us [ 31969] | __cxa_atexit(); 0.380 us [ 31969] | } /* atexit */ 2.890 us [ 31969] | } /* __cudart1670 */ 3.530 us [ 31969] | } /* pthread_once */ 4.530 us [ 31969] | } /* __cudart1635 */ 0.060 us [ 31969] | __cxa_atexit(); 5.320 us [ 31969] | } /* __cudart426 */ [ 31969] | __sti____cudaRegisterAll() { [ 31969] | __cudaRegisterFatBinary() { [ 31969] | __cudart667() { [ 31969] | __cudart1635() { 0.040 us [ 31969] | pthread_once(); 0.320 us [ 31969] | } /* __cudart1635 */ 0.570 us [ 31969] | } /* __cudart667 */ [ 31969] | __cudart524() { 0.090 us [ 31969] | malloc(); 0.340 us [ 31969] | } /* __cudart524 */ 1.150 us [ 31969] | } /* __cudaRegisterFatBinary */ [ 31969] | __nv_cudaEntityRegisterCallback() { 0.120 us [ 31969] | __nv_save_fatbinhandle_for_managed_rt(); [ 31969] | __cudaRegisterFunction() { [ 31969] | __cudart667() { [ 31969] | __cudart1635() { 0.050 us [ 31969] | pthread_once(); 0.250 us [ 31969] | } /* __cudart1635 */ 0.380 us [ 31969] | } /* __cudart667 */ [ 31969] | __cudart530() { 0.060 us [ 31969] | malloc(); 0.340 us [ 31969] | } /* __cudart530 */ 0.940 us [ 31969] | } /* __cudaRegisterFunction */ 1.330 us [ 31969] | } /* __nv_cudaEntityRegisterCallback */ [ 31969] | __cudaRegisterFatBinaryEnd() { [ 31969] | __cudart667() { [ 31969] | __cudart1635() { ... ``` -------------------------------- ### Install uftrace with Dependencies (Bash) Source: https://github.com/namhyung/uftrace/blob/master/doc/uftrace.html This extended Bash script installs required dependencies via a helper script before cloning, configuring, building, and installing uftrace. It enhances the basic install by enabling optional features like libdw, libpython, libluajit, libncursesw, and capstone. Requires access to package managers for dependency installation; configure output shows enabled features for advanced tracing support. ```bash $ git clone https://github.com/namhyung/uftrace && cd uftrace # To install required packages $ sudo ./misc/install-deps.sh $ ./configure uftrace detected system features: ... prefix: /usr/local ... libelf: [ on ] - more flexible ELF data handling ... libdw: [ on ] - DWARF debug info support ... libpython: [ on ] - python tracing & scripting support ... libluajit: [ on ] - luajit scripting support ... libncursesw: [ on ] - TUI support ... cxa_demangle: [ on ] - full demangler support with libstdc++ ... perf_event: [ on ] - perf (PMU) event support ... schedule: [ on ] - scheduler event support ... capstone: [ on ] - full dynamic tracing support $ make $ sudo make install ``` -------------------------------- ### C++: Hello World Compilation Source: https://github.com/namhyung/uftrace/wiki/Filters Demonstrates compiling hello.cpp using g++ to generate an executable ```bash $ g++ -pg -o hello hello.cpp ``` -------------------------------- ### uftrace function call example Source: https://github.com/namhyung/uftrace/wiki/Arguments A sample output from uftrace showing function calls with timing, thread ID, and arguments. It demonstrates the basic format of trace output including function names and their associated arguments. ```uftrace DURATION TID FUNCTION 2.059 us [28090] | __cxa_atexit(); [28090] | main() { 1.384 us [28090] | circumference(1, 3.141593) = 6.283185; 0.348 us [28090] | area(1, 3.141593) = 3.141593; 3.552 us [28090] | } /* main */ ``` -------------------------------- ### Apply Build Patch to Source Source: https://github.com/namhyung/uftrace/wiki/uftrace-for-chromium Applies the uftrace build patch to Chromium source tree using patch command. The patch modifies multiple build configuration files to enable uftrace support. Requires the use_uftrace.diff file to be present in current directory. Input: Chromium source tree. Output: modified build files supporting uftrace. ```shell patch -p1 < use_uftrace.diff ``` -------------------------------- ### uftrace Record Command Example Source: https://github.com/namhyung/uftrace/wiki/Tutorial Command to compile a C program with debugging symbols and record its execution trace using uftrace. This captures the program's runtime behavior for later analysis. ```bash gcc -o foobar -pg -pthread foobar.c uftrace record foobar ```