AndroidEnthusiastic
AndroidEnthusiastic

Reputation: 931

Export the logs in xamarin Profiler

I have to test one app using xamarin profiler. In xamarin profiler is there any option for export the logs? and possible to filter unwanted logs(System logs). and how to calculate application response time from one activity to another activity? any help is appreciated?

Upvotes: 9

Views: 291

Answers (2)

matthewrdev
matthewrdev

Reputation: 12190

In xamarin profiler is there any option for export the logs?

You can configure the output path and then press CONTROL+S (Windows) or COMMAND+S (OSX) to save the snaphot.

  • Windows: Tools->Options->Save *.mlpds to...
  • OSX: Preferences->General->Output Location

I've always had difficulty in exporting and reloading the snapshots from Xamarin.Profiler; I can't guarantee it will work as expected.

If you are after the Xamarin.Profiler application logs, they are located under:

  • Windows: [User-Path]/AppData/Local/Xamarin/Log/Xamarin.Profiler
  • OSX: ~/Library/Logs/Xamarin.Profiler/

How to calculate application response time from one activity to another activity?

You can register an implementation of IActivityLifecycleCallbacks with the application to do this. Here is a rudimentary sample you can build from:

[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");
        }
    }
}

This will dump a log into Application Output that looks like this:

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

Upvotes: 2

CDrosos
CDrosos

Reputation: 2528

I dont think so that there is a way to export the logs.

About counting from one activity to another use the App class below to implement helpful methods that count the interval because 2 activities

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 ();

    }
}
}

On the call of the 2nd activity and after the start of the 2nd activity measure the time with something like this: On the call:

DateTime startTime = DateTime.UtcNow;

after the start of the 2nd activity:

TimeSpan elapsedTime = DateTime.UtcNow - startTime; 

Upvotes: 2

Related Questions