如何通过.NET Profiler API提取函数参数和返回值? [英] How to extract function argument and return value through .NET profiler API ?
问题描述
通过Profiler Api,我们可以跟踪当前的方法及其性能。但我们可以捕获函数参数参数及其返回值吗?
Through Profiler Api we can track the current methods and their performance. but can we do capture the function argument parameter and their return value as also?
假设下面是一个用例:
public void FatDateNow()
      {
          DateTime dt = DateTime.Now;
          HttpClient http = new HttpClient();
          http.BaseAddress = new Uri(" http://dev-api-csplugin.crosscode.io");
          http.DefaultRequestHeaders.Accept.Clear();
          http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(" application / json"));
$
          AccountAPIInputParam input = new AccountAPIInputParam();
          input.AccountId = string.IsNullOrWhiteSpace(null)? " d2b5ec99-8123-3d20-866a-3d7d203b5479" :null;
          var d = JsonConvert.SerializeObject(输入);
          var content = new StringContent(d,Encoding.UTF8," application / json");
         试试
          {
              //http.Dispose();
$
              var output = http.PostAsync(" api / v1.0 / getAccountLibrary",new StringContent(" test")));
              var url = output.Result.RequestMessage.RequestUri;
              //InterceptLib.DebugLogger.Log(http.BaseAddress + http。)
          }¥b $ b           catch(例外情况)
          {
$
          }
          System.Console.Write(" AKS -DateTime.Now:");
          System.Console.WriteLine(dt.ToString(" HH:mm"));
      }
public void FatDateNow()
{
DateTime dt = DateTime.Now;
HttpClient http = new HttpClient();
http.BaseAddress = new Uri("http://dev-api-csplugin.crosscode.io");
http.DefaultRequestHeaders.Accept.Clear();
http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
AccountAPIInputParam input = new AccountAPIInputParam();
input.AccountId = string.IsNullOrWhiteSpace(null) ? "d2b5ec99-8123-3d20-866a-3d7d203b5479" : null;
var d = JsonConvert.SerializeObject(input);
var content = new StringContent(d, Encoding.UTF8, "application/json");
try
{
//http.Dispose();
var output = http.PostAsync("api/v1.0/getAccountLibrary", new StringContent("test"));
var url = output.Result.RequestMessage.RequestUri;
//InterceptLib.DebugLogger.Log(http.BaseAddress + http.)
}
catch (Exception ex)
{
}
System.Console.Write("AKS -DateTime.Now : ");
System.Console.WriteLine(dt.ToString("HH:mm"));
}
上面是C#方法,现在我想在运行时从上面的方法中捕获url变量或 RequestUri。我们怎么做?我们可以通过profiler的FunctionEnter / FunctionLeave api来做。如果是,那么请给我一些代码片段来实现
。谢谢Ashuosh
Above is C# method and now i want to capture url variable or RequestUri from above method in run time. How can we do that ? Can we do through FunctionEnter/FunctionLeave api of profiler.If yes then please show me with some code snippet to achieve that. Thanks Ashuosh
推荐答案
是的。
在调用SetEventMask时包含COR_PRF_ENABLE_FUNCTION_ARGS,并使用SetEnterLeaveFunctionHooks3WithInfo注册回调。您的ELT回调将接收COR_PRF_ELT_INFO作为其参数之一,您可以将其传递给GetFunctionEnter3Info
和GetFunctionLeave3Info以获取COR_PRF_FUNCTION_ARGUMENT_RANGE结构,该结构描述了可以找到值的连续内存块。
Include COR_PRF_ENABLE_FUNCTION_ARGS in your call to SetEventMask and register the callbacks using SetEnterLeaveFunctionHooks3WithInfo. Your ELT callbacks will receive a COR_PRF_ELT_INFO as one of their arguments, you can pass that to GetFunctionEnter3Info
and GetFunctionLeave3Info to get the COR_PRF_FUNCTION_ARGUMENT_RANGE structure which describes a contiguous block of memory where you can find the values.
这篇关于如何通过.NET Profiler API提取函数参数和返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!