---
title: "#290: Monitoring Performance with GDPerformanceView 📈"
url: https://littlebitesofcocoa.com/290-monitoring-performance-with-gdperformanceview
author: Jake Marsh
date: 2017-01-17
published: 2017-01-17
topics: ["Libraries"]
description: "Optimizing for responsiveness is a huge part of making great apps. Before we can optimize though, we'll need to measure."
---

# #290: Monitoring Performance with GDPerformanceView 📈

By Jake Marsh, January 17, 2017. HTML: https://littlebitesofcocoa.com/290-monitoring-performance-with-gdperformanceview

Optimizing for responsiveness is a huge part of making great apps. Before we can optimize though, we'll need to measure. **Xcode** and **Instruments** offer some incredible tools to do "deep-dives" for answers ([Bite #68](https://littlebitesofcocoa.com/68-time-profiler-basics), [Bite #113](https://littlebitesofcocoa.com/113-profiling-core-animation)), but often we just want to keep an eye on our app's performance and respond as needed.

Today we'll try out a library called [GDPerformanceView](https://github.com/dani-gavrilov/GDPerformanceView-Swift) by [Gavrilov Daniil](https://github.com/dani-gavrilov) that lets us easily monitor our app's **rendering speed** and **CPU usage** in the device's status bar while we use the app. Let's begin.

We'll install [GDPerformanceView](https://github.com/dani-gavrilov/GDPerformanceView-Swift) and head over to our `AppDelegate`. We'll add a bit of code:

``` swift
GDPerformanceMonitor.sharedInstance.startMonitoring { (textLabel) in
  textLabel?.backgroundColor = .black
  textLabel?.textColor = .white
}
```

Here we're telling `GDPerofrmanceMonitor` to start its engines, then customizing the look and feel of the label that appears in the status bar.

When we Build & Run, here's what we get:

<img src="https://media.littlebitesofcocoa.com/290-1.png" style="max-width: 375px; border-radius: 4px;" />

Neat! By default [GDPerformanceView](https://github.com/dani-gavrilov/GDPerformanceView-Swift) will show the app and device version. This is great in some cases (QA testing, beta builds), but in our case we don't really need it. Let's them both off:

``` swift
GDPerformanceMonitor.sharedInstance.appVersionHidden = true
GDPerformanceMonitor.sharedInstance.deviceVersionHidden = true
```

<img src="https://media.littlebitesofcocoa.com/290-2.png" style="max-width: 374px; border-radius: 4px;" />

Beautiful. Now we'll always know exactly how well our app is behaving, and we'll be able to identify issues as they happen.

[GDPerformanceView](https://github.com/dani-gavrilov/GDPerformanceView-Swift) has one more trick up its sleeve. 🎩 

We can actually subscribe to performance updates and do whatever we'd like with the data.

Let's try this out. First we'll subscribe to updates by making our `AppDelegate` conform to the provided `GDPerformanceMonitorDelegate` protocol:

``` swift
extension AppDelegate : GDPerformanceMonitorDelegate {
  func performanceMonitorDidReport(fpsValue: Float, cpuValue: Float) {
    // TODO
  }
}
```

Then, we'll set it as the delegate for the shared `GDPerformanceMonitor` in our `didFinishLaunching`:

``` swift
GDPerformanceMonitor.sharedInstance.delegate = self
```

Nice. Now we need to do something interesting with these updates. Let's use the [Taptic Engine](http://www.imore.com/iphone-7s-taptic-engine) ([Bite #269](https://littlebitesofcocoa.com/269-taptic-engine-basics)) to provide some force feedback if we hit the CPU too hard:

``` swift
func performanceMonitorDidReport(fpsValue: Float, cpuValue: Float) {
  if cpuValue > 50 {
    UIImpactFeedbackGenerator(style: .heavy)
      .impactOccurred()
  }
}
```

Neat! We could also toss these values into an array somewhere and use it to build charts, etc.

Learn more about [GDPerformanceView](https://github.com/dani-gavrilov/GDPerformanceView-Swift) at [git.io/gdperformance](git.io/gdperformance).
