Skip to content

uftrace for Clang LLVM

Honggyu Kim edited this page Aug 26, 2025 · 7 revisions

1. Download LLVM Project 20.1.8 and uncompress

$ wget https://github.com/llvm/llvm-project/releases/download/llvmorg-20.1.8/llvm-project-20.1.8.src.tar.xz 

$ tar xfx llvm-project-20.1.8.src.tar.xz 

$ cd llvm-project-20.1.8.src

2. Configuration

$ mkdir build.release.pg.g && cd build.release.pg.g

$ cmake -G Ninja ../llvm -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
      -DLLVM_TARGETS_TO_BUILD="host;AArch64" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-pg -g"

If you want see more detail and non-optimize code flow use Debug build but Debug build require many memory. In addition, if your system does not have enough memory then gold linker can be used as follows.

$ cmake -G Ninja ../llvm -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
      -DLLVM_TARGETS_TO_BUILD="host;AArch64" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-pg -g" \
      -DLLVM_USE_LINKER=gold

Reference: https://llvm.org/docs/GettingStarted.html#getting-the-source-code-and-building-llvm

3. Build clang

$ ninja clang

4. Test the generated clang image

$ cd ./bin

$ ./clang
clang: error: no input files

$ nm clang | grep mcount
                 U mcount@GLIBC_2.2.5

5. Run clang execution with uftrace

$ uftrace -F main -D 3 --no-libcall -- ./clang
clang: error: no input files
# DURATION     TID      FUNCTION
            [2353877] | main() {
            [2353877] |   llvm::InitLLVM::InitLLVM() {
  11.276 us [2353877] |     llvm::sys::SetOneShotPipeSignalFunction();
   0.191 us [2353877] |     llvm::PrettyStackTraceEntry::PrettyStackTraceEntry();
   0.298 us [2353877] |     llvm::EnablePrettyStackTrace();
   0.105 us [2353877] |     llvm::sys::PrintStackTraceOnErrorSignal();
   0.389 us [2353877] |     llvm::install_out_of_memory_new_handler();
  19.934 us [2353877] |   } /* llvm::InitLLVM::InitLLVM */
            [2353877] |   clang_main() {
   0.043 us [2353877] |     clang::noteBottomOfStack();
   0.044 us [2353877] |     llvm::setBugReportMsg();
   2.370 us [2353877] |     llvm::sys::Process::FixupStandardFileDescriptors();
   5.644 us [2353877] |     LLVMInitializeAArch64TargetInfo();
   0.272 us [2353877] |     LLVMInitializeX86TargetInfo();
 315.879 us [2353877] |     LLVMInitializeAArch64Target();
 151.266 us [2353877] |     LLVMInitializeX86Target();
  40.793 us [2353877] |     clang::driver::getDriverMode();
   0.053 us [2353877] |     clang::driver::IsClangCL();
   6.442 us [2353877] |     clang::driver::expandResponseFiles();
  25.098 us [2353877] |     GetExecutablePath::cxx11();
  43.821 us [2353877] |     clang::CreateAndPopulateDiagOpts();
   0.106 us [2353877] |     llvm::errs();
   0.070 us [2353877] |     clang::TextDiagnosticPrinter::TextDiagnosticPrinter();
   0.869 us [2353877] |     llvm::sys::path::stem();
   2.227 us [2353877] |     clang::DiagnosticIDs::DiagnosticIDs();
   0.857 us [2353877] |     clang::DiagnosticsEngine::DiagnosticsEngine();
   0.068 us [2353877] |     llvm::vfs::getRealFileSystem();
   0.841 us [2353877] |     clang::ProcessWarningOptions();
   9.846 us [2353877] |     llvm::sys::getDefaultTargetTriple::cxx11();
  14.915 us [2353877] |     clang::driver::Driver::Driver();
   0.375 us [2353877] |     clang::driver::ToolChain::getTargetAndModeFromProgramName();
   0.889 us [2353877] |     SetBackdoorDriverOutputsFromEnvVars();
   1.735 us [2353877] |     llvm::CrashRecoveryContext::Enable();
 551.189 us [2353877] |     clang::driver::Driver::BuildCompilation();
   0.122 us [2353877] |     llvm::opt::ArgList::getRange();
   0.291 us [2353877] |     clang::driver::Driver::ExecuteCompilation();
   0.045 us [2353877] |     clang::DiagnosticConsumer::finish();
   0.047 us [2353877] |     llvm::errs();
   8.871 us [2353877] |     llvm::TimerGroup::printAll();
   0.122 us [2353877] |     llvm::TimerGroup::clearAll();
   1.266 us [2353877] |     clang::driver::Compilation::~Compilation();
   4.266 us [2353877] |     clang::driver::Driver::~Driver();
   1.391 us [2353877] |     clang::DiagnosticsEngine::~DiagnosticsEngine();
   0.119 us [2353877] |     clang::DiagnosticIDs::~DiagnosticIDs();
   1.251 ms [2353877] |   } /* clang_main */
            [2353877] |   llvm::InitLLVM::~InitLLVM() {
  90.928 us [2353877] |     llvm::llvm_shutdown();
   0.067 us [2353877] |     llvm::PrettyStackTraceEntry::~PrettyStackTraceEntry();
  91.401 us [2353877] |   } /* llvm::InitLLVM::~InitLLVM */
   1.371 ms [2353877] | } /* main */

7. Visualized trace output of clang

uftrace-chrome-dump

Clone this wiki locally