How to profile your C code using gprof and linux perf

  Рет қаралды 13,051

ANTSHIV ROBOTICS

ANTSHIV ROBOTICS

Күн бұрын

Пікірлер: 12
@antshivrobotics
@antshivrobotics 2 жыл бұрын
If you liked the video, please subscribe and turn notifications on to not miss any future videos, thank you!
@farzamdorostkar7816
@farzamdorostkar7816 2 жыл бұрын
Nice video, thanks! It would be great if you made the same tutorial for memory profiling.
@aymenkaze1539
@aymenkaze1539 2 жыл бұрын
thank you so much man insane video :)
@antshivrobotics
@antshivrobotics 2 жыл бұрын
Thank you!
@xinking2644
@xinking2644 2 жыл бұрын
Good video, thank you sir. subscribed!
@michaeldunlavey6015
@michaeldunlavey6015 2 жыл бұрын
Nice job, but I'm a contrarian. Sorry. I only care about the overall time and how to reduce it. To find out what to fix, I use stackshots. To get a stackshot, run under gdb, hit ^C, thread 1, and bt. If it doesn't run long enough, wrap a temporary loop around the outside. So what do I get? stack 1. in timewaster, no surprise. Fix: comment out timewaster stack 1. in printf, no surprise. Fix: comment out printf Result: loop 100e6 times, 12 sec. (120 nsec) stack 1. at line a[i] = fib3(i-1) + fib3(i-2); stack 2. at line int fib3(int i){ i.e. Spends all its time in the function call Fix: So get rid of the function call. Do a[j]=a[j-1]+a[j-2]. Now it takes 5 sec (50 nsec - 2 times faster than before). Usually, I take several stackshots, but less than 20. The point is, if something you can do will save X% of time, then it will be on at least X% of stackshots. That's not timing, it's identifying speedups. Added: as I think about it, the above code is going to spend most of its time indexing the a array. Not necessary. The inner loop could look something like this: int x, y=1, z=1; x = y+z; y = x+z; z = x+y; and when you get to the end, grab the right one.
@SuperWhatusername
@SuperWhatusername 2 жыл бұрын
Thank you
@ronensuperexplainer
@ronensuperexplainer 2 жыл бұрын
These performance profilers are a disgrace compared to the Microsoft Visual Studio Performance Profiler
@antshivrobotics
@antshivrobotics 2 жыл бұрын
Interesting. In what way?
@ronensuperexplainer
@ronensuperexplainer 2 жыл бұрын
@@antshivrobotics A GUI that gives line-by-line analysis of exactly which lines of code are taking a long time to run, with red highlighting of the problematic lines of code. That together with a function stack view that lets you "expand hot path". Visual Studio performance profiler lets you double-click a function name to see the code of that function with an analysis of each and every line of code. It works great with the Release build of your application! (not only debug) Essentially all AAA game devs use C++ and use Visual Studio for performance profiling. It even has GPU performance profiling.
@bhimsend1581
@bhimsend1581 2 жыл бұрын
@@ronensuperexplainer I second it. For large projects, I would recommend Visual studio.
@TheLordoftheDarkness
@TheLordoftheDarkness 5 ай бұрын
There are things a CLI do better than a GUI. Profiling and debugging are not part of those things. We have to admit that no tool comes even close to Visual studio when it comes to debugging and especially profiling.
GDB Tutorial
55:12
CS 246
Рет қаралды 73 М.
Linux Performance Tools, Brendan Gregg, part 1 of 2
54:29
Brendan Gregg
Рет қаралды 162 М.
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
Let's Create a Compiler (Pt.1)
1:11:03
Pixeled
Рет қаралды 579 М.
Language Performance Comparisons Are Junk
1:23:37
ThePrimeTime
Рет қаралды 151 М.
Testing code coverage in C using GCOV
8:53
ANTSHIV ROBOTICS
Рет қаралды 10 М.
The Only Unbreakable Law
53:25
Molly Rocket
Рет қаралды 344 М.
Kernel Recipes 2017 - Perf in Netflix - Brendan Gregg
51:06
Kernel Recipes
Рет қаралды 28 М.
When Optimisations Work, But for the Wrong Reasons
22:19
SimonDev
Рет қаралды 1,1 МЛН
Intro to the Zig Programming Language • Andrew Kelley • GOTO 2022
50:14
The Basics of Profiling - Mathieu Ropert - CppCon 2021
59:37