這是aspects的理想場所。退房post sharp。
然後,您可以創建一個方面有點像:
/// <summary>
/// Adds execution timing and automatic logging to the tagged method
/// </summary>
[Serializable]
public class MethodTimeAttribute : OnMethodBoundaryAspect
{
private String MethodName { get; set; }
private DateTime StartTime { get; set; }
/// <summary>
/// Method executed at build time. Initializes the aspect instance. After the execution
/// of <see cref="CompileTimeInitialize"/>, the aspect is serialized as a managed
/// resource inside the transformed assembly, and deserialized at runtime.
/// </summary>
/// <param name="method">Method to which the current aspect instance
/// has been applied.</param>
/// <param name="aspectInfo">Unused.</param>
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo)
{
MethodName = method.DeclaringType.FullName "." method.Name;
}
public override void OnEntry(MethodExecutionArgs args)
{
StartTime = DateTime.Now;
}
public override void OnExit(MethodExecutionArgs args)
{
Log.Debug(this, "Method {0} took {1} to execute", MethodName, DateTime.Now - StartTime);
}
}
和所有你需要做的就是標記你的方法是這樣的:
[MethodTime]
private void RunFor(TimeSpan runTime){
// do stuff
}
先進的後急劇功能需要一個許可證,但簡單像方法邊界方面的是免費的。
儘管這不會測試您的wcf服務的任何網絡邊界,但它會測試您的服務實施時間。
如果您真的想要創建一些自定義行爲並將其注入到WCF鏈中來測試計時,但該階段出現瓶頸的可能性不大。更有可能的是,您發送大量數據的速度很慢,或者實施過程中的速度很慢,所有這些都可以通過服務器端或客戶端進行獨立測試。
查看性能計數器以及秒錶。 – DarthVader