What is the best tool for general C/C++ sample profiling?

I have installed NSight, but it seems geared towards GPU, CUDA etc and I can’t see the options for just normal CPU sampling and ranking the C/C++ function calls etc.

I am interested in seeing what my C/C++ code is doing, with the usual breakdowns/call graphs etc that I am used to from MSVC and Xcode desktop development.

Googling just reveals a myriad of different options stretching back to the early 2000s, I wonder what is the main thing people use in 2024?

Hi,

Please check if our Nsight System can meet your requirements.

Thanks.

Thanks, but please read my first sentence again.

Hi,

Do you want a debugger or a profiler?
Nsys supports CPU-side sampling and profiling.

Thanks.

Profiling. I ran a quick profile but the only stats it outputted were to tell me I hadn’t made any CUDA calls.

So there must be some way to enable the CPU-side sampling and profiling which I haven’t yet found.

Hi,

Please try it like below:

$ sudo /opt/nvidia/nsight-systems/2023.2.4/target-linux-tegra-armv8/nsys profile /usr/bin/uname
$ sudo /opt/nvidia/nsight-systems/2023.2.4/target-linux-tegra-armv8/nsys stats /home/nvidia/report1.nsys-rep
...

 ** OS Runtime Summary (osrt_sum):

 Time (%)  Total Time (ns)  Num Calls  Avg (ns)  Med (ns)  Min (ns)  Max (ns)  StdDev (ns)       Name
 --------  ---------------  ---------  --------  --------  --------  --------  -----------  --------------
     48.9           10,976          2   5,488.0   5,488.0     4,256     6,720      1,742.3  fclose
     47.0           10,560          1  10,560.0  10,560.0    10,560    10,560          0.0  fputs_unlocked
      4.1              928          2     464.0     464.0        32       896        610.9  fflush

Thanks.

Thanks - but that only reports calls to OS run time functions.

How do I get it to report how long it spends in my own C/C++ functions?

Hi,

Please change the [app] to your c code.

$ sudo /opt/nvidia/nsight-systems/2023.2.4/target-linux-tegra-armv8/nsys profile [app] 
$ sudo /opt/nvidia/nsight-systems/2023.2.4/target-linux-tegra-armv8/nsys stats /home/nvidia/report1.nsys-rep

Thanks

Well, obviously I did that. rolls eyes

But it only records OSRT function calls made from my code, not the profiling of my own code, how long it spends in my own functions etc.

I don’t think you even understand what I am asking, never mind.

In the end I used gprofng to give me what I wanted.

This is part of binutils and as the profiler is quite a recent tool it wasn’t available in Ubuntu 20.04 so I had to manually build it. I think it should be already available or installable for Ubuntu 22.04.

I found the html output option wasn’t supported for arm64 for some reason, but I was able to view the results using the project below:

This was better than the somewhat tedious command-line output options, but I guess if you’re a command-line guru that might float your boat!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.