Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

วิธี Profile C++ Code บน Linux


1. Valgrind + Callgrind (ยอดนิยม)

$ g++ -o hello hello.cpp
$ valgrind --tool=callgrind ./hello
# ได้ไฟล์ callgrind.out.x
# อ่านด้วย kcachegrind (GUI)

Valgrind: memory debugging, leak detection, profiling

2. gprof (built-in GCC)

$ g++ -o hello hello.cpp -g -pg
$ ./hello
$ gprof hello gmon.out > analysis.txt

ต้อง compile ด้วย -pg รันโปรแกรมได้ gmon.out แล้ววิเคราะห์ด้วย gprof

เครื่องมืออื่นๆ

  • perf (Linux kernel profiler, hardware counters)
  • Intel VTune (advanced, commercial)
  • Google Benchmark (microbenchmarking)