Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 578
AndroidEnthusiastic Avatar asked Sep 02 '15 10:09

AndroidEnthusiastic


People also ask

Where are the xamarin logs?

Another option is to view the debug log via the command line. Open a Terminal window and navigate to the Android SDK platform-tools folder (typically, the SDK platform-tools folder is located at /Users/username/Library/Developer/Xamarin/android-sdk-macosx/platform-tools).

How do I add logs to xamarin?

Add NLog. Name it “NLog. config” in your root Android folder and modify the config according to your needs, see NLog Wiki about configuration file. NLog Documentation also contains detailled information about all different log targets and the available options for each target.

What is the use of xamarin profiler?

You can use the Android Profiler to measure the performance of a Xamarin Android app built with Visual Studio – without the need for a Visual Studio Enterprise license.

Where is xamarin diagnostic output?

Diagnostic output is visible within the Errors Pad (View > Pads > Errors ), by clicking the Build Output button.


2 Answers

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; 
like image 73
CDrosos Avatar answered Oct 31 '22 20:10

CDrosos


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
like image 41
matthewrdev Avatar answered Oct 31 '22 21:10

matthewrdev