StartupPerformance sample
|
@ -0,0 +1,35 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.28902.138
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StartupPerformance.Android", "StartupPerformance\StartupPerformance.Android\StartupPerformance.Android.csproj", "{B40F3902-B17F-4C05-BD4F-D79AB4465129}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StartupPerformance", "StartupPerformance\StartupPerformance\StartupPerformance.csproj", "{9C05E336-7C4B-4A58-A2AC-4311EEBD91D0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{B40F3902-B17F-4C05-BD4F-D79AB4465129}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B40F3902-B17F-4C05-BD4F-D79AB4465129}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B40F3902-B17F-4C05-BD4F-D79AB4465129}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{B40F3902-B17F-4C05-BD4F-D79AB4465129}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B40F3902-B17F-4C05-BD4F-D79AB4465129}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B40F3902-B17F-4C05-BD4F-D79AB4465129}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
{9C05E336-7C4B-4A58-A2AC-4311EEBD91D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9C05E336-7C4B-4A58-A2AC-4311EEBD91D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9C05E336-7C4B-4A58-A2AC-4311EEBD91D0}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{9C05E336-7C4B-4A58-A2AC-4311EEBD91D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9C05E336-7C4B-4A58-A2AC-4311EEBD91D0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9C05E336-7C4B-4A58-A2AC-4311EEBD91D0}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {EB83BD66-5080-482B-ABB0-CC032079A7EA}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,19 @@
|
|||
Any raw assets you want to be deployed with your application can be placed in
|
||||
this directory (and child directories) and given a Build Action of "AndroidAsset".
|
||||
|
||||
These files will be deployed with you package and will be accessible using Android's
|
||||
AssetManager, like this:
|
||||
|
||||
public class ReadAsset : Activity
|
||||
{
|
||||
protected override void OnCreate (Bundle bundle)
|
||||
{
|
||||
base.OnCreate (bundle);
|
||||
|
||||
InputStream input = Assets.Open ("my_asset.txt");
|
||||
}
|
||||
}
|
||||
|
||||
Additionally, some Android functions will automatically load asset files:
|
||||
|
||||
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
|
|
@ -0,0 +1,67 @@
|
|||
using Java.IO;
|
||||
using Java.Lang;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace StartupPerformance.Droid.Helpers
|
||||
{
|
||||
// Based on: https://github.com/toomasz/XamarinAppStartupTime
|
||||
// By Tomasz Ścisłowicz
|
||||
public class ProfilerTimeHelper
|
||||
{
|
||||
const string LogcatTimeFormat = "yyyy-MM-dd HH:mm:ss.fff";
|
||||
|
||||
private static DateTime? StartupTime;
|
||||
private static bool _attemptedToGetStartupTime;
|
||||
|
||||
public static DateTime? GetAppStartupTime()
|
||||
{
|
||||
if (_attemptedToGetStartupTime)
|
||||
{
|
||||
return StartupTime;
|
||||
}
|
||||
if (!StartupTime.HasValue)
|
||||
{
|
||||
StartupTime = GetStartupTimeFromLogcat();
|
||||
_attemptedToGetStartupTime = true;
|
||||
}
|
||||
return StartupTime;
|
||||
}
|
||||
|
||||
private static DateTime? GetStartupTimeFromLogcat()
|
||||
{
|
||||
var pid = Android.OS.Process.MyPid();
|
||||
|
||||
var process = new ProcessBuilder().
|
||||
RedirectErrorStream(true).
|
||||
Command("/system/bin/logcat", $"--pid={pid}", "-m", "1", "-v", "year").Start();
|
||||
|
||||
using (var bufferedReader = new BufferedReader(new InputStreamReader(process.InputStream)))
|
||||
{
|
||||
string line = null;
|
||||
while ((line = bufferedReader.ReadLine()) != null)
|
||||
{
|
||||
if (ParseLogDateTime(line, out DateTime date))
|
||||
{
|
||||
return date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool ParseLogDateTime(string logLine, out DateTime dateTime)
|
||||
{
|
||||
if (logLine.Length < LogcatTimeFormat.Length)
|
||||
{
|
||||
dateTime = new DateTime();
|
||||
return false;
|
||||
}
|
||||
var timeStr = logLine.Substring(0, LogcatTimeFormat.Length);
|
||||
|
||||
return DateTime.TryParseExact(timeStr, LogcatTimeFormat,
|
||||
CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out dateTime);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using Android.App;
|
||||
using Android.Content.PM;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using Android.OS;
|
||||
using StartupPerformance.Droid.Services;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace StartupPerformance.Droid
|
||||
{
|
||||
[Activity(
|
||||
Label = "StartupPerformance",
|
||||
Icon = "@mipmap/icon",
|
||||
Theme = "@style/MainTheme",
|
||||
MainLauncher = true,
|
||||
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
|
||||
public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
|
||||
{
|
||||
protected override void OnCreate(Bundle savedInstanceState)
|
||||
{
|
||||
TabLayoutResource = Resource.Layout.Tabbar;
|
||||
ToolbarResource = Resource.Layout.Toolbar;
|
||||
|
||||
base.OnCreate(savedInstanceState);
|
||||
|
||||
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
|
||||
Forms.Init(this, savedInstanceState);
|
||||
DependencyService.Register<ProfilerService>();
|
||||
LoadApplication(new App());
|
||||
}
|
||||
|
||||
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
|
||||
{
|
||||
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname">
|
||||
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
|
||||
<application android:label="StartupPerformance.Android"></application>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
</manifest>
|
|
@ -0,0 +1,34 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Android.App;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("StartupPerformance.Android")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("StartupPerformance.Android")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
||||
// Add some common permissions, these can be removed if not needed
|
||||
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
|
||||
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
|
|
@ -0,0 +1,50 @@
|
|||
Images, layout descriptions, binary blobs and string dictionaries can be included
|
||||
in your application as resource files. Various Android APIs are designed to
|
||||
operate on the resource IDs instead of dealing with images, strings or binary blobs
|
||||
directly.
|
||||
|
||||
For example, a sample Android app that contains a user interface layout (main.xml),
|
||||
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
|
||||
would keep its resources in the "Resources" directory of the application:
|
||||
|
||||
Resources/
|
||||
drawable-hdpi/
|
||||
icon.png
|
||||
|
||||
drawable-ldpi/
|
||||
icon.png
|
||||
|
||||
drawable-mdpi/
|
||||
icon.png
|
||||
|
||||
layout/
|
||||
main.xml
|
||||
|
||||
values/
|
||||
strings.xml
|
||||
|
||||
In order to get the build system to recognize Android resources, set the build action to
|
||||
"AndroidResource". The native Android APIs do not operate directly with filenames, but
|
||||
instead operate on resource IDs. When you compile an Android application that uses resources,
|
||||
the build system will package the resources for distribution and generate a class called
|
||||
"Resource" that contains the tokens for each one of the resources included. For example,
|
||||
for the above Resources layout, this is what the Resource class would expose:
|
||||
|
||||
public class Resource {
|
||||
public class drawable {
|
||||
public const int icon = 0x123;
|
||||
}
|
||||
|
||||
public class layout {
|
||||
public const int main = 0x456;
|
||||
}
|
||||
|
||||
public class strings {
|
||||
public const int first_string = 0xabc;
|
||||
public const int second_string = 0xbcd;
|
||||
}
|
||||
}
|
||||
|
||||
You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main
|
||||
to reference the layout/main.xml file, or Resource.strings.first_string to reference the first
|
||||
string in the dictionary file values/strings.xml.
|
12361
src/Startup/StartupPerformance/StartupPerformance.Android/Resources/Resource.designer.cs
сгенерированный
Normal file
Двоичные данные
src/Startup/StartupPerformance/StartupPerformance.Android/Resources/drawable/xamarin_logo.png
Normal file
После Ширина: | Высота: | Размер: 21 KiB |
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/sliding_tabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
app:tabIndicatorColor="@android:color/white"
|
||||
app:tabGravity="fill"
|
||||
app:tabMode="fixed" />
|
|
@ -0,0 +1,9 @@
|
|||
<android.support.v7.widget.Toolbar
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
android:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/launcher_background" />
|
||||
<foreground android:drawable="@mipmap/launcher_foreground" />
|
||||
</adaptive-icon>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/launcher_background" />
|
||||
<foreground android:drawable="@mipmap/launcher_foreground" />
|
||||
</adaptive-icon>
|
Двоичные данные
src/Startup/StartupPerformance/StartupPerformance.Android/Resources/mipmap-hdpi/icon.png
Normal file
После Ширина: | Высота: | Размер: 4.6 KiB |
Двоичные данные
src/Startup/StartupPerformance/StartupPerformance.Android/Resources/mipmap-hdpi/launcher_foreground.png
Normal file
После Ширина: | Высота: | Размер: 11 KiB |
Двоичные данные
src/Startup/StartupPerformance/StartupPerformance.Android/Resources/mipmap-mdpi/icon.png
Normal file
После Ширина: | Высота: | Размер: 2.7 KiB |
Двоичные данные
src/Startup/StartupPerformance/StartupPerformance.Android/Resources/mipmap-mdpi/launcher_foreground.png
Normal file
После Ширина: | Высота: | Размер: 6.3 KiB |
Двоичные данные
src/Startup/StartupPerformance/StartupPerformance.Android/Resources/mipmap-xhdpi/icon.png
Normal file
После Ширина: | Высота: | Размер: 6.9 KiB |
Двоичные данные
src/Startup/StartupPerformance/StartupPerformance.Android/Resources/mipmap-xhdpi/launcher_foreground.png
Normal file
После Ширина: | Высота: | Размер: 18 KiB |
Двоичные данные
src/Startup/StartupPerformance/StartupPerformance.Android/Resources/mipmap-xxhdpi/icon.png
Normal file
После Ширина: | Высота: | Размер: 12 KiB |
Двоичные данные
src/Startup/StartupPerformance/StartupPerformance.Android/Resources/mipmap-xxhdpi/launcher_foreground.png
Normal file
После Ширина: | Высота: | Размер: 33 KiB |
Двоичные данные
src/Startup/StartupPerformance/StartupPerformance.Android/Resources/mipmap-xxxhdpi/icon.png
Normal file
После Ширина: | Высота: | Размер: 19 KiB |
Двоичные данные
src/Startup/StartupPerformance/StartupPerformance.Android/Resources/mipmap-xxxhdpi/launcher_foreground.png
Normal file
После Ширина: | Высота: | Размер: 51 KiB |
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="launcher_background">#FFFFFF</color>
|
||||
<color name="colorPrimary">#3F51B5</color>
|
||||
<color name="colorPrimaryDark">#303F9F</color>
|
||||
<color name="colorAccent">#FF4081</color>
|
||||
</resources>
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<resources>
|
||||
|
||||
<style name="MainTheme" parent="MainTheme.Base">
|
||||
</style>
|
||||
<!-- Base theme applied no matter what API -->
|
||||
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
|
||||
<item name="windowNoTitle">true</item>
|
||||
<!--We will be using the toolbar so no need to show ActionBar-->
|
||||
<item name="windowActionBar">false</item>
|
||||
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
|
||||
<!-- colorPrimary is used for the default action bar background -->
|
||||
<item name="colorPrimary">#2196F3</item>
|
||||
<!-- colorPrimaryDark is used for the status bar -->
|
||||
<item name="colorPrimaryDark">#1976D2</item>
|
||||
<!-- colorAccent is used as the default value for colorControlActivated
|
||||
which is used to tint widgets -->
|
||||
<item name="colorAccent">#FF4081</item>
|
||||
<!-- You can also set colorControlNormal, colorControlActivated
|
||||
colorControlHighlight and colorSwitchThumbNormal. -->
|
||||
<item name="windowActionModeOverlay">true</item>
|
||||
|
||||
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
|
||||
</style>
|
||||
|
||||
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
|
||||
<item name="colorAccent">#FF4081</item>
|
||||
</style>
|
||||
</resources>
|
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using StartupPerformance.Droid.Helpers;
|
||||
using StartupPerformance.Services;
|
||||
|
||||
namespace StartupPerformance.Droid.Services
|
||||
{
|
||||
public class ProfilerService : IProfilerService
|
||||
{
|
||||
private static Dictionary<string, DateTime?> _eventTimingsSinceStartup = new Dictionary<string, DateTime?>();
|
||||
|
||||
public static void RegisterInternalEvent(string eventName)
|
||||
{
|
||||
if (_eventTimingsSinceStartup.ContainsKey(eventName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_eventTimingsSinceStartup.Add(eventName, DateTime.Now);
|
||||
}
|
||||
|
||||
public void RegisterEvent(string eventName)
|
||||
{
|
||||
RegisterInternalEvent(eventName);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, TimeSpan?>> GetTimingsSinceStartup()
|
||||
{
|
||||
return await Task.Factory.StartNew(() =>
|
||||
{
|
||||
var timings = new Dictionary<string, TimeSpan?>();
|
||||
var startupTime = ProfilerTimeHelper.GetAppStartupTime();
|
||||
|
||||
foreach (var eventInfo in _eventTimingsSinceStartup)
|
||||
{
|
||||
timings.Add(eventInfo.Key, eventInfo.Value - startupTime);
|
||||
}
|
||||
return timings;
|
||||
});
|
||||
}
|
||||
|
||||
public DateTime? GetStartupTime()
|
||||
{
|
||||
return ProfilerTimeHelper.GetAppStartupTime();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{B40F3902-B17F-4C05-BD4F-D79AB4465129}</ProjectGuid>
|
||||
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<TemplateGuid>{9AA2D3C6-3393-45F1-8E7C-5A9901728795}</TemplateGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>StartupPerformance.Droid</RootNamespace>
|
||||
<AssemblyName>StartupPerformance.Android</AssemblyName>
|
||||
<AndroidApplication>True</AndroidApplication>
|
||||
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
|
||||
<AndroidResgenClass>Resource</AndroidResgenClass>
|
||||
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
|
||||
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
|
||||
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
|
||||
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
|
||||
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
|
||||
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
|
||||
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>portable</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AndroidLinkMode>None</AndroidLinkMode>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AndroidManagedSymbols>true</AndroidManagedSymbols>
|
||||
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
|
||||
<AotAssemblies>true</AotAssemblies>
|
||||
<EnableLLVM>true</EnableLLVM>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Mono.Android" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Xamarin.Forms" Version="4.0.0.425677" />
|
||||
<PackageReference Include="Xamarin.Android.Support.Design" Version="28.0.0.1" />
|
||||
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.1" />
|
||||
<PackageReference Include="Xamarin.Android.Support.v4" Version="28.0.0.1" />
|
||||
<PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="28.0.0.1" />
|
||||
<PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="28.0.0.1" />
|
||||
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.1" />
|
||||
<PackageReference Include="Xamarin.Android.Support.CustomTabs" Version="28.0.0.1" />
|
||||
<PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Helpers\ProfilerTimeHelper.cs" />
|
||||
<Compile Include="MainActivity.cs" />
|
||||
<Compile Include="Resources\Resource.designer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\ProfilerService.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\AboutResources.txt" />
|
||||
<None Include="Assets\AboutAssets.txt" />
|
||||
<None Include="Properties\AndroidManifest.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\layout\Tabbar.axml" />
|
||||
<AndroidResource Include="Resources\layout\Toolbar.axml" />
|
||||
<AndroidResource Include="Resources\values\styles.xml" />
|
||||
<AndroidResource Include="Resources\values\colors.xml" />
|
||||
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon.xml" />
|
||||
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon_round.xml" />
|
||||
<AndroidResource Include="Resources\mipmap-hdpi\icon.png" />
|
||||
<AndroidResource Include="Resources\mipmap-hdpi\launcher_foreground.png" />
|
||||
<AndroidResource Include="Resources\mipmap-mdpi\icon.png" />
|
||||
<AndroidResource Include="Resources\mipmap-mdpi\launcher_foreground.png" />
|
||||
<AndroidResource Include="Resources\mipmap-xhdpi\icon.png" />
|
||||
<AndroidResource Include="Resources\mipmap-xhdpi\launcher_foreground.png" />
|
||||
<AndroidResource Include="Resources\mipmap-xxhdpi\icon.png" />
|
||||
<AndroidResource Include="Resources\mipmap-xxhdpi\launcher_foreground.png" />
|
||||
<AndroidResource Include="Resources\mipmap-xxxhdpi\icon.png" />
|
||||
<AndroidResource Include="Resources\mipmap-xxxhdpi\launcher_foreground.png" />
|
||||
<AndroidResource Include="Resources\drawable\xamarin_logo.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\drawable-hdpi\" />
|
||||
<Folder Include="Resources\drawable-xhdpi\" />
|
||||
<Folder Include="Resources\drawable-xxhdpi\" />
|
||||
<Folder Include="Resources\drawable-xxxhdpi\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\StartupPerformance\StartupPerformance.csproj">
|
||||
<Project>{9CB9F235-9A76-4D15-B982-1F2D128B0529}</Project>
|
||||
<Name>StartupPerformance</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Application xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="StartupPerformance.App">
|
||||
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<!--Global Styles-->
|
||||
<Color x:Key="NavigationPrimary">#2196F3</Color>
|
||||
<Style TargetType="NavigationPage">
|
||||
<Setter Property="BarBackgroundColor" Value="{StaticResource NavigationPrimary}" />
|
||||
<Setter Property="BarTextColor" Value="White" />
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
|
||||
</Application>
|
|
@ -0,0 +1,33 @@
|
|||
using StartupPerformance.Services;
|
||||
using StartupPerformance.Views;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace StartupPerformance
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
public static IProfilerService ProfilerService { get; set; } = DependencyService.Get<IProfilerService>();
|
||||
|
||||
public App()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
MainPage = new MainView();
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
ProfilerService.RegisterEvent("Xamarin.Forms App OnStart");
|
||||
}
|
||||
|
||||
protected override void OnSleep()
|
||||
{
|
||||
// Handle when your app sleeps
|
||||
}
|
||||
|
||||
protected override void OnResume()
|
||||
{
|
||||
// Handle when your app resumes
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
using Xamarin.Forms.Xaml;
|
||||
|
||||
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
|
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
|
||||
namespace StartupPerformance.Extensions
|
||||
{
|
||||
public static class TimeSpanExtensions
|
||||
{
|
||||
public static string ToCanonicString(this TimeSpan? timeSpan)
|
||||
{
|
||||
if (!timeSpan.HasValue)
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
return timeSpan.Value.ToCanonicString();
|
||||
}
|
||||
|
||||
public static string ToCanonicString(this TimeSpan timeSpan, int secondsToSkipMsPart = 40)
|
||||
{
|
||||
int totalDays = (int)timeSpan.TotalDays;
|
||||
|
||||
if (totalDays > 0)
|
||||
{
|
||||
return $"{totalDays}d{timeSpan.Hours}h{timeSpan.Minutes}m{timeSpan.Seconds}s";
|
||||
}
|
||||
|
||||
if (timeSpan.Hours > 0)
|
||||
{
|
||||
return $"{timeSpan.Hours}h{timeSpan.Minutes}m{timeSpan.Seconds}s";
|
||||
}
|
||||
|
||||
if (timeSpan.Minutes > 0)
|
||||
{
|
||||
return $"{timeSpan.Minutes}m{timeSpan.Seconds}s";
|
||||
}
|
||||
|
||||
if (timeSpan.Seconds < 1)
|
||||
{
|
||||
return $"{timeSpan.Milliseconds}ms";
|
||||
}
|
||||
|
||||
if (timeSpan.Seconds < secondsToSkipMsPart)
|
||||
{
|
||||
return $"{timeSpan.Seconds}s{timeSpan.Milliseconds}ms";
|
||||
}
|
||||
|
||||
return $"{timeSpan.Seconds}s";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
using StartupPerformance.Extensions;
|
||||
using System;
|
||||
|
||||
namespace StartupPerformance.Models
|
||||
{
|
||||
public class Timing
|
||||
{
|
||||
public Timing(string eventName, TimeSpan? elapsedTime)
|
||||
{
|
||||
EventName = eventName;
|
||||
ElapsedTime = elapsedTime?.ToCanonicString();
|
||||
}
|
||||
|
||||
public string EventName { get; }
|
||||
public string ElapsedTime { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StartupPerformance.Services
|
||||
{
|
||||
public interface IProfilerService
|
||||
{
|
||||
void RegisterEvent(string eventName);
|
||||
Task<Dictionary<string, TimeSpan?>> GetTimingsSinceStartup();
|
||||
DateTime? GetStartupTime();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<ProduceAssemblyReference>true</ProduceAssemblyReference>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Xamarin.Forms" Version="4.0.0.425677" />
|
||||
<PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Views\MainView.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,52 @@
|
|||
using StartupPerformance.Models;
|
||||
using StartupPerformance.Services;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace StartupPerformance.ViewModels
|
||||
{
|
||||
public class MainViewModel : BindableObject
|
||||
{
|
||||
private string _startupTime;
|
||||
private List<Timing> _timings;
|
||||
|
||||
private readonly IProfilerService _profilerService;
|
||||
|
||||
public MainViewModel(IProfilerService profilerService)
|
||||
{
|
||||
_profilerService = profilerService;
|
||||
}
|
||||
|
||||
public string StartupTime
|
||||
{
|
||||
get => _startupTime;
|
||||
set
|
||||
{
|
||||
_startupTime = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Timing> Timings
|
||||
{
|
||||
get => _timings;
|
||||
set
|
||||
{
|
||||
_timings = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LoadDataAsync()
|
||||
{
|
||||
StartupTime = _profilerService.GetStartupTime()?.ToLocalTime().ToString() ?? "-";
|
||||
var timings = await _profilerService.GetTimingsSinceStartup();
|
||||
|
||||
Timings = timings
|
||||
.Select(t => new Timing(t.Key, t.Value))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="StartupPerformance.Views.MainView">
|
||||
<ContentPage.Content>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="200" />
|
||||
</Grid.RowDefinitions>
|
||||
<Label
|
||||
Grid.Row="0"
|
||||
Text="Performance Results"
|
||||
FontSize="18"
|
||||
Margin="10"/>
|
||||
<Frame
|
||||
Grid.Row="1"
|
||||
Padding="10">
|
||||
<StackLayout>
|
||||
<StackLayout Orientation="Horizontal">
|
||||
<Label
|
||||
Text="App Startup Time:"
|
||||
FontSize="12"
|
||||
WidthRequest="100"/>
|
||||
<Label
|
||||
FontSize="12"
|
||||
FontAttributes="Bold"
|
||||
Text="{Binding StartupTime}"/>
|
||||
</StackLayout>
|
||||
<Label
|
||||
Text="Timings since startup:"
|
||||
FontSize="12"
|
||||
FontAttributes="Bold"/>
|
||||
<ListView
|
||||
ItemsSource="{Binding Timings}"
|
||||
SelectionMode="None"
|
||||
SeparatorVisibility="None"
|
||||
HasUnevenRows="True"
|
||||
Margin="10,0,0,0">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<StackLayout
|
||||
Orientation="Horizontal"
|
||||
HeightRequest="18">
|
||||
<Label
|
||||
Text="{Binding EventName}"
|
||||
FontSize="12"
|
||||
VerticalOptions="Center"
|
||||
WidthRequest="220"/>
|
||||
<Label
|
||||
Text="{Binding ElapsedTime}"
|
||||
FontSize="12"
|
||||
VerticalOptions="Center"
|
||||
FontAttributes="Bold"/>
|
||||
</StackLayout>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</StackLayout>
|
||||
</Frame>
|
||||
</Grid>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
|
@ -0,0 +1,21 @@
|
|||
using StartupPerformance.Services;
|
||||
using StartupPerformance.ViewModels;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace StartupPerformance.Views
|
||||
{
|
||||
public partial class MainView : ContentPage
|
||||
{
|
||||
public MainView()
|
||||
{
|
||||
InitializeComponent();
|
||||
BindingContext = new MainViewModel(DependencyService.Get<IProfilerService>());
|
||||
}
|
||||
|
||||
protected override async void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
await (BindingContext as MainViewModel).LoadDataAsync();
|
||||
}
|
||||
}
|
||||
}
|