gpt4 book ai didi

azure - Application Insight (Azure) 中的计时事件

转载 作者:行者123 更新时间:2023-12-03 00:36:10 24 4
gpt4 key购买 nike

我一直在寻找一种对事件进行计时并在 Azure 上绘制图表的方法。寻找事件较慢的热点以进行进一步分析。

例如,我当前可以执行以下操作:

var p = new Dictionary<string, string> {{ "StartTime", startTime.Value.ToString("g") }, { "EndTime", endTime.Value.ToString("g") }};
var m = new Dictionary<string, double> {{ "ElapsedSeconds", (endTime.Value - startTime.Value).TotalSeconds }};

ai.TrackEvent(eventName, p, m);

这将使我一次查看一个事件并知道它花了多长时间。但没有简单的方法来查看它的图表。但是,我注意到他的 javascript 库有一个 startTrackEvent 和 stopTrackEvent ( AI docs ),这看起来很理想。

有人见过跟踪定时服务器事件的内置方法或现有方法吗?

最佳答案

然后您可以采取类似 Ketan 的答案的内容,并用一次性纸包裹它,例如:

internal class TimedEvent : IDisposable
{
private string name;
private Dictionary<string,string> properties;
private Stopwatch timer = Stopwatch.StartNew();

public TimedEvent(string name, Dictionary<string,string> properties = null)
{
this.name = name;
this.properties = properties;
}

public void Dispose()
{
timer.Stop();
YourTelemetryClientHere.TrackEvent(this.name, this.properties,
new Dictionary<string, double> { { "duration", timer.ElapsedMilliseconds } });
}
}

然后在你的代码中你可以做类似的事情

using (new TimedEvent("myEvent"))
{
// do something that takes time
}

关于azure - Application Insight (Azure) 中的计时事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28163352/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com