我目前正在开发Xamarin.Android应用程序,我不仅希望在每次提交时都构建该应用程序,而且还希望记录启动时间(想法:如果启动时间增加,由于发生了更改,很容易识别)。
使用App Center可以吗?也许结合使用App Center的启动测试功能和Application Insights?我知道Logcat会显示启动时间(从启动流程到完成绘制相应活动的时间),可以使用Application Insights提取出来吗?
答案 0 :(得分:0)
我一直在做的事情是,使用一个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);
}