Performance Peak Analysis

I have a C ++ feature set that does some image processing operation. As a rule, I see that the final output comes in the range of 5-6 ms. I measure the time spent using the QueryPerformanceCounterWin32 API. But when working in a continuous cycle with 100 images, I see that the performance reaches 20 ms for some images. My question is: how can I analyze such problems. Basically, I want to determine if spikes are caused due to some delay in this code, or if some other task is running inside the CPU, because of which this operation takes time. I tried using the API GetThreadTimesto find out how much time my thread spent inside the CPU, but I cannot conclude based on these numbers. What is the standard way to resolve these issues?

+4
source share
3 answers

What is the standard way to resolve these issues?

There are real-time operating systems (RTOS) that guarantee such delays. This is a completely different class of operating systems than Windows or Linux.

But still, you can do something that can be done with delays even on general-purpose operating systems.

1. Avoid system calls

As soon as you ask your OS to read or write something to disk, there are no guarantees regarding delays. Therefore, avoid any system functions on your critical path:

  • even functions like gettimeofday () can cause unpredictable delays, so you should really avoid system calls in time-critical code;
  • - .

, , strace Linux Dr Memory Windows, .

2.

Windows . , , CPU. , RTOS, , :

  • , ​​;
  • SetThreadAffinityMask() (Windows) sched_setaffinity() (Linux) - , CPU;
  • , ; CPU 0, CPU 1 +;
  • , .

, perf (Linux) Intel VTune (Windows), .

3.

:

  • swap, , ;
  • CPU turbo boost - , (TDP);
  • - , , .

, .

+1

-, , ..

, / . - ( ). .

/ , ,

  • -
  • . , - (% util - , SAR/NMON Linux ).
  • (Affinity ) , , . Taskset - . .

.

+3

, , , .

, (100 , ), .

, .


A typical way to check "if there is some other task running inside the CPU" will run your program once and mark the images that produce this splash. For example, images 2, 4, 5, and 67 take too much time to process. Launch your program several times and note again which images create the splashes.

If the same images create these bursts, then this is not what is caused by another external task.

+2
source

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


All Articles