What methods can you use to profile your code

Some of the platforms I'm developing do not have profiling tools. I am looking for suggestions / methods that you personally used to help you identify hot spots, without using a profiler.

The final language is C ++.

I'm interested in what you personally used.

+3
source share
7 answers

I found the following quite useful:

#ifdef PROFILING
# define PROFILE_CALL(x) do{ \
    const DWORD t1 = timeGetTime(); \
    x; \
    const DWORD t2 = timeGetTime(); \
    std::cout << "Call to '" << #x << "' took " << (t2 - t1) << " ms.\n"; \
  }while(false)
#else
# define PROFILE_CALL(x) x
#endif

What can be used in the calling function as such:

PROFILE_CALL(renderSlow(world));
int r = 0;
PROFILE_CALL(r = readPacketSize());
+5
source

. std:: cout , /, Beep(). -, "Beep", .

. rgb (255,0,0) .

, / Beeps , , , , , .. , .

+8

, , , . , , , , , / .

, / / , , . , , . , , .

, , , , .

+3

- (, ), , , , , (, 10 , , - !). , , ..

+2

, , , / .

+2

80/20 . , (, , ), , (QueryPerformanceCounters, gettimeofday ..).

- ( ) " ", , - . , sinks/srcs (sinks moreso), , (, ) .

+1

Visual Studio?

/Gh /GH.

, -, , , / .

Then you can log all profiling data, not just time information. Stack-dumps, call address, return address, etc. This is important because you may know that “function X uses Y-time under function Z” and not just the total time spent on function X.

+1
source

Source: https://habr.com/ru/post/1699493/


All Articles