قالب وردپرس درنا توس
Home / IOS Development / # 290: Monitor Performance with GDPerformanceView 📈 – Little Bites of Cocoa

# 290: Monitor Performance with GDPerformanceView 📈 – Little Bites of Cocoa



Subjects

Topics

Response Response is a big part of creating great apps. Before we can optimize though, we must measure. Xcode and Instruments offer some incredible tools for making "Deep Dives" for answers (Bite # 68, Bite # 113), but often we just want to keep an eye on the app's performance and respond as required.

Today we will try a library called GDPerformanceView by Gavrilov Daniil that lets us easily monitor our apps rendering speed and CPU usage in the device status bar while using the app. Let us begin.

We install GDPerformanceView and transfer to our AppDelegate . We add some code:

  GDPerformanceMonitor .   sharedInstance .   startMonitoring    {   (  textLabel )    in [1
9659017] TextLabel
. background color = . black text label . text color = white }

Here we tell GDPerofrmanceMonitor to start their engines and customize the appearance of the label shown in the status bar.

When We Build and Drive, Here's What We Get:

Tidy! By default, GDPerformanceView will show the app and device version. This is good in some cases (QA testing, beta buildings), but in our case we do not really need it. Let's both take off:

  GDPerformanceMonitor .   sharedInstance .   appVersionHidden    =    true 
  GDPerformanceMonitor .   sharedInstance . [19659009] deviceVersionHidden    =    true 

beautiful. Now we always know exactly how well our app behaves, and we can identify issues as they happen.

GDPerformanceView has yet another trick on the sleeve. 🎩

We can actually subscribe to performance updates and do what we want with the data.

Let's try this out. First, we subscribe to updates by making our AppDelegate in accordance with the specified GDPerformanceMonitorDelegate Protocol:

  Extension    AppDelegate  :    GDPerformanceMonitorDelegate    { 
    FUNC    performanceMonitorDidReport  (  fpsValue :    Float     cpuValue :    Float )    {[19659070] 

]
}

Then we will put it as representative of the shared GDPerformanceMonitor in our didFinishLaunching :

  GDPerformanceMonitor .   sharedInstance .   Delegate    =    Self 

Nice. Now, we need to do something interesting with these updates. Let's use the Taptic Engine (Bite # 269) to provide some power feedback if we hit the CPU too hard:

  func    performanceMonitorDidReport  (  fpsValue :    Float        cpuValue  >    50    {
      UIImpactFeedbackGenerator  ([19659061] style :      tung ) 
         impactOccurred  () 
  } 
} 

Neat ..! We can also throw these values ​​into a matrix somewhere and use it to create charts, etc.

Learn more about GDPerformanceView at git.io/gdperformance.


Source link