我必须使用xamarin profiler测试一个应用程序。在xamarin profiler中是否有任何导出日志的选项?并且可以过滤不需要的日志(系统日志)。以及如何计算从一个活动到另一个活动的应用程序响应时间?任何帮助表示赞赏?
答案 0 :(得分:2)
我不这么认为有办法导出日志。
关于从一个活动到另一个活动的计数使用下面的App类来实现计算间隔的有用方法,因为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 ();
}
}
}
在第二个活动的召唤和第二个活动开始后,用这样的方式测量时间: 在通话中:
DateTime startTime = DateTime.UtcNow;
在第二次活动开始后:
TimeSpan elapsedTime = DateTime.UtcNow - startTime;
答案 1 :(得分:2)
您可以配置输出路径,然后按CONTROL + S(Windows)或COMMAND + S(OSX)保存快照。
我总是难以从Xamarin.Profiler导出和重新加载快照;我无法保证它能按预期工作。
如果您在Xamarin.Profiler应用程序日志之后,它们位于:
您可以在应用程序中注册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");
}
}
}
这会将日志转储到Application Output中,如下所示:
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