Dotnet agent : Btm trace is not showing few methods in the method stack trace.
The btm trace may not show few methods in the method stack trace. The possible reason may be the method is inlined .

The JIT compiler compiles and optimizes the code of a managed application during the application run. The compiler uses specific algorithms to decide whether to inline a function or not. Eg: If a method is too small or the execution of code in a method takes less time than the method invocation, then the funtion will be inlined.
Sample code:
[HttpGet]
public ActionResult<string> Get()
{
PrintTime();
// code here
return "";
}
public void PrintTime()
{
WriteTimeToConsole();
}
public void WriteTimeToConsole()
{
Console.WriteLine(new DateTime());
}
In the above code the method PrintTime() simply invokes another method and doesn't do any business logic. In this case that method will be inlined automatically by the compiler.
There are few ways to avoid inlining a function by the compiler. One way is to to specify the NoInlining method attribute in source code.
[MethodImpl(MethodImplOptions.NoInlining)]
public void PrintTime()
{
WriteTimeToConsole();
}
Generally it is not a good idea to avoid function inline. Because it will impact application performance.
Please sign in to leave a comment.
Comments
0 comments