Fix unbalanced profiler push/pop (#8213)
authorkingces95 <kingces95@users.noreply.github.com>
Mon, 28 Oct 2019 22:37:49 +0000 (12:37 -1000)
committerGitHub <noreply@github.com>
Mon, 28 Oct 2019 22:37:49 +0000 (12:37 -1000)
Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs
Xamarin.Forms.Core/Profiler.cs
Xamarin.Forms.Core/Registrar.cs
Xamarin.Forms.Platform.Android/Forms.cs
Xamarin.Forms.Platform.Android/Renderers/ShellFlyoutTemplatedContentRenderer.cs
Xamarin.Forms.Platform.Android/Renderers/ShellRenderer.cs

index 2ee5a7c..f96eda8 100644 (file)
@@ -10,6 +10,7 @@ using Xamarin.Forms.Controls.Issues;
 using Xamarin.Forms.Platform.Android;
 using Xamarin.Forms.Platform.Android.AppLinks;
 using System.Linq;
+using Xamarin.Forms.Internals;
 
 namespace Xamarin.Forms.ControlGallery.Android
 {
@@ -32,6 +33,8 @@ namespace Xamarin.Forms.ControlGallery.Android
        {
                protected override void OnCreate(Bundle bundle)
                {
+                       Profile.Start();
+
                        ToolbarResource = Resource.Layout.Toolbar;
                        TabLayoutResource = Resource.Layout.Tabbar;
 
@@ -90,7 +93,12 @@ namespace Xamarin.Forms.ControlGallery.Android
                        }
                }
 
-               
+               protected override void OnResume()
+               {
+                       base.OnResume();
+                       Profile.Stop();
+               }
+
                [Export("IsPreAppCompat")]
                public bool IsPreAppCompat()
                {
index 4d12242..f00a45b 100644 (file)
@@ -52,21 +52,21 @@ namespace Xamarin.Forms.Internals
 
                public static void FrameBegin(
                        [CallerMemberName] string name = "",
-                       string id = null,
                        [CallerLineNumber] int line = 0)
                {
                        if (!Running)
                                return;
 
-                       FrameBeginBody(name, id, line);
+                       FrameBeginBody(name, null, line);
                }
 
-               public static void FrameEnd()
+               public static void FrameEnd(
+                       [CallerMemberName] string name = "")
                {
                        if (!Running)
                                return;
 
-                       FrameEndBody();
+                       FrameEndBody(name);
                }
 
                public static void FramePartition(
@@ -90,9 +90,12 @@ namespace Xamarin.Forms.Internals
                        Stack.Push(new Profile(name, id, line));
                }
 
-               static void FrameEndBody()
+               static void FrameEndBody(string name)
                {
                        var profile = Stack.Pop();
+                       if (profile._name != name)
+                               throw new InvalidOperationException(
+                                       $"Expected to end frame '{profile._name}', not '{name}'.");
                        profile.Dispose();
                }
 
@@ -104,7 +107,7 @@ namespace Xamarin.Forms.Internals
                        var name = profile._name;
                        profile.Dispose();
 
-                       FrameBegin(name, id, line);
+                       FrameBeginBody(name, id, line);
                }
 
                Profile(
index f341624..0fa4a32 100644 (file)
@@ -331,7 +331,8 @@ namespace Xamarin.Forms.Internals
                        Profile.FramePartition("Reflect");
                        foreach (Assembly assembly in assemblies)
                        {
-                               Profile.FrameBegin(assembly.GetName().Name);
+                               var assemblyName = assembly.GetName().Name;
+                               Profile.FrameBegin(assemblyName);
 
                                foreach (Type attrType in attrTypes)
                                {
@@ -370,7 +371,7 @@ namespace Xamarin.Forms.Internals
                                Array.Copy(effectAttributes, typedEffectAttributes, effectAttributes.Length);
                                RegisterEffects(resolutionName, typedEffectAttributes);
 
-                               Profile.FrameEnd();
+                               Profile.FrameEnd(assemblyName);
                        }
 
                        if ((flags & InitializationFlags.DisableCss) == 0)
index cc4dced..062e6f9 100644 (file)
@@ -147,7 +147,7 @@ namespace Xamarin.Forms
 
                        Profile.FrameBegin("Assembly.GetCallingAssembly");
                        resourceAssembly = Assembly.GetCallingAssembly();
-                       Profile.FrameEnd();
+                       Profile.FrameEnd("Assembly.GetCallingAssembly");
 
                        Profile.FrameBegin();
                        SetupInit(activity, resourceAssembly, null);
index b68a6ba..3103d98 100644 (file)
@@ -122,8 +122,6 @@ namespace Xamarin.Forms.Platform.Android
                        Profile.FramePartition("UpdateFlyoutBackground");
                        UpdateFlyoutBackground();
 
-                       Profile.FrameEnd();
-
                        Profile.FramePartition(nameof(UpdateVerticalScrollMode));
                        UpdateVerticalScrollMode();
                        Profile.FrameEnd();
index 9df3ba9..abd5714 100644 (file)
@@ -353,7 +353,7 @@ namespace Xamarin.Forms.Platform.Android
                                decorView.SetBackground(split);
                        }
 
-                       Profile.FrameEnd();
+                       Profile.FrameEnd("UpdtStatBarClr");
                }
 
                class SplitDrawable : Drawable