내가 사용하는 메서드의 실행 시간을 기록하기로되어있는 PostSharp 애스펙트를 만들었습니다.PostSharp에서 StopWatch를 사용하여 비동기 메서드의 성능 로깅이 정확하지 않습니다. MethodInterceptionAspect
그러나 예상대로 작동하지 않는 것 같습니다. sw.ElapsedMilliseconds
은 항상 0 ~ 3 밀리 초입니다.
[Serializable]
[AttributeUsage(AttributeTargets.Method)]
public sealed class PerfLogAttribute : MethodInterceptionAspect
{
public override void OnInvoke(MethodInterceptionArgs args)
{
var sw = new Stopwatch();
sw.Start();
args.Proceed();
sw.Stop();
log.Debug(sw.ElapsedMilliseconds);
}
}
이런 식으로 사용 : @ Christian.K으로
[PerfLog]
public async Task<bool> DoSomethingAsync() {
// Adding a delay to test (or call database async)
await Task.Delay(5000);
return true;
}
Postsharp가 async/await에서 작동하는 것이 확실합니까? 그것은 단지 "기다리는 작업. 지연 (5000)"까지만 측정 할 수 있습니다. 인터넷 검색 "PostSharp 비동기 MethodInterceptor"는 관련성이있는 몇 가지 히트를 제공합니다. –