Search code examples
c#.netvisual-studiocpu-usagevisual-studio-debugging

what are the external and native functions seen when i check cpu usage by visual studio debugger?


This is a screenshot of the recorded CPU profile

enter image description here

I was checking the CPU usage of my C# program using visual studio debugger. But I am unable to understand what is external function, native function, and what is the difference between total CPU% and self CPU%. I want to just analyze the CPU performance of my program


Solution

  • external function means system and framework functions that are executed by your code. External code functions start and stop the app, draw the UI, control threading, and provide other low-level services to the app.

    native function is written in the computer's `native machine language and executed directly by the processor. It will not "host" the memory, and the memory will not be released for you, such as C++. And the CPU usage can detect it.

    and what is the difference between total CPU% and self CPU%.

    total CPU%

    The milliseconds and CPU percentage used by calls to the function, and functions called by the function, in the selected time range.

    And Total CPU indicates how much work was done by the function and any functions called by it. High total CPU values point to the functions that are most expensive overall.

    self CPU%

    The milliseconds and CPU percentage used by calls to the function in the selected time range, excluding functions called by the function.

    Self CPU indicates how much work was done by the code in the function body, excluding the work done by functions that were called by it. High Self CPU values may indicate a performance bottleneck within the function itself.

    You can refer to this official document and Measure application performance by analyzing CPU usage for more detailed info.