android - App Center如何统计和记录应用启动时间?

标签 android xamarin visual-studio-app-center

我目前正在开发一个 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/

相关文章:

java - 如何从网站接收动态变量(android)

android - IllegalStateException:无法执行 Activity 的方法

android - 如何提高Android上位图绘制的性能

android - 在Android Studio和AppCenter中,Gradle都找不到Flutter构建的APK

android - 更新数据库android时的AlertDialog或Toast

xamarin - 在Click事件上分配/返回值,在DependencyService上发送/接收返回值

xamarin.ios - 如何在模拟器中为 MonoTouch 应用程序生成 .dSYM?

c# - 如何从 Xamarin Forms View 创建 native UWP View ?

xamarin.android - Mobile Center 是 Xamarin Build 失败并出现 pthread_mutex_lock 错误

react-native - 有什么方法可以从 React Native 的 env 文件中获取 appcenter 配置