我目前正在开发一个 Xamarin.Android 应用程序,我不仅希望在每次提交时构建该应用程序,而且还希望记录启动时间(想法:如果启动时间增加,很容易识别由于哪个更改)。
这可以使用 App Center 吗?也许将 App Center 的启动测试功能与 Application Insights 结合使用?我知道 Logcat 会显示启动时间(从启动进程到完成绘制相应 Activity 之间的时间),是否可以使用 Application Insights 提取?
最佳答案
我一直在做的是,使用 Stopwatch 实例测量我正在调用的每个方法,将它们放入字典中,然后使用 TrackEvent 方法将所有信息一起发送。它可能不会告诉您渲染所需的时间,但它会让您很好地了解哪种方法执行时间最长。
你会得到这样的东西:
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
var dictionary = new Dictionary<string, string>();
var totalTime = 0L;
var stopWatch = new Stopwatch();
stopWatch.Start();
UserDialogs.Init(() => this);
stopWatch.Stop();
totalTime += stopWatch.ElapsedMilliseconds;
dictionary.Add("UserDialogs.Init(() => this); (ms)", stopWatch.ElapsedMilliseconds.ToString());
stopWatch.Restart();
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
stopWatch.Stop();
totalTime += stopWatch.ElapsedMilliseconds;
dictionary.Add("global::Xamarin.Forms.Forms.Init(this, savedInstanceState); (ms)", stopWatch.ElapsedMilliseconds.ToString());
stopWatch.Restart();
LoadApplication(new App(new AndroidInitializer()));
stopWatch.Stop();
totalTime += stopWatch.ElapsedMilliseconds;
dictionary.Add("LoadApplication(new App(new AndroidInitializer())) (ms)", stopWatch.ElapsedMilliseconds.ToString());
dictionary.Add("Total Startup Time", totalTime.ToString());
Analytics.TrackEvent("Load completed", dictionary);
}
关于android - App Center如何统计和记录应用启动时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58355129/