在 xamarin Profiler 中导出日志

Export the logs in xamarin Profiler

我必须使用 xamarin 分析器测试一个应用程序。在 xamarin profiler 中是否有导出日志的选项?并可能过滤不需要的日志(系统日志)。以及如何计算从一个 activity 到另一个 activity 的应用程序响应时间?任何帮助表示赞赏?

我认为没有导出日志的方法。

关于从一个 activity 计数到另一个 activity 使用下面的应用程序 class 来实现计算间隔的有用方法,因为 2 个活动

using System;
using Android.App;
using Android.Runtime;

namespace Appname
{
[Application]
public class App : Application
{
    public App (IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
    {
    }

    public override void OnCreate ()
    {
        base.OnCreate ();

    }
}
}

在第 2 个 activity 调用时和第 2 个 activity 开始后用这样的东西测量时间: 通话中:

DateTime startTime = DateTime.UtcNow;

第2次开始后activity:

TimeSpan elapsedTime = DateTime.UtcNow - startTime; 

在 xamarin profiler 中是否有导出日志的选项?

您可以配置输出路径,然后按 CONTROL+S (Windows) 或 COMMAND+S (OSX) 保存快照。

  • Windows: 工具->选项->保存 *.mlpds 到...
  • OSX:首选项->常规->输出位置

我一直难以从 Xamarin.Profiler 导出和重新加载快照;我不能保证它会按预期工作。

如果您在寻找 Xamarin.Profiler 应用程序日志,它们位于:

  • Windows: [用户路径]/AppData/Local/Xamarin/Log/Xamarin.Profiler
  • OSX: ~/Library/Logs/Xamarin.Profiler/

如何计算应用程序从一个 activity 到另一个 activity 的响应时间?

您可以在应用程序中注册 IActivityLifecycleCallbacks 的实现来执行此操作。这是您可以构建的基本示例:

[Application]
public class MyApplication : Application
{
    public MyApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { 
    }

    public override void OnCreate ()
    {
        RegisterActivityLifecycleCallbacks(new LifecycleCallbacks());
        base.OnCreate ();
    }
}

public class LifecycleCallbacks : Java.Lang.Object, Android.App.Application.IActivityLifecycleCallbacks
{
    Dictionary<Type, System.Diagnostics.Stopwatch> _lifeTimeTrackers = new Dictionary<Type, Stopwatch>();

    public void OnActivityCreated (Activity activity, Bundle savedInstanceState)
    {
        _lifeTimeTrackers [activity.GetType ()] = Stopwatch.StartNew ();
        Event (activity, "created");
    }

    public void OnActivityDestroyed (Activity activity)
    {
        Event (activity, "destroyed");
        _lifeTimeTrackers.Remove(activity.GetType());
    }

    public void OnActivityPaused (Activity activity)
    {
        Event (activity, "paused");
    }

    public void OnActivityResumed (Activity activity)
    {
        Event (activity, "resume");
    }

    public void OnActivitySaveInstanceState (Activity activity, Bundle outState)
    {
        Event (activity, "save_state");
    }

    public void OnActivityStarted (Activity activity)
    {
        Event (activity, "started");
    }

    public void OnActivityStopped (Activity activity)
    {
        Event (activity, "stopped");
    }

    void Event (Activity activity, string eventName)
    {
        var type = activity.GetType ();
        if (_lifeTimeTrackers.ContainsKey (type)) {
            Console.WriteLine ("Lifecycle event " + eventName.ToUpper() + " for '" + type.Name + "' after " + _lifeTimeTrackers [type].ElapsedMilliseconds + "ms");
        }
    }
}

这会将日志转储到应用程序输出中,如下所示:

Lifecycle event STOPPED for 'MainActivity' after 3789ms
Lifecycle event DESTROYED for 'MainActivity' after 3789ms
Lifecycle event PAUSED for 'SecondActivity' after 3121ms
Lifecycle event CREATED for 'MainActivity' after 0ms
Lifecycle event STARTED for 'MainActivity' after 7ms
Lifecycle event RESUME for 'MainActivity' after 7ms
Lifecycle event STOPPED for 'SecondActivity' after 3568ms
Lifecycle event DESTROYED for 'SecondActivity' after 3568ms
Lifecycle event PAUSED for 'MainActivity' after 5918ms
Lifecycle event CREATED for 'SecondActivity' after 0ms
Lifecycle event STARTED for 'SecondActivity' after 2ms
Lifecycle event RESUME for 'SecondActivity' after 2ms