code: def measure_fps(self, window=1, callback='%1.1f FPS'):
          
          # Connect update_fps function to draw
          self.events.draw.disconnect(self._update_fps)
          if callback:
              if isinstance(callback, string_types):
                  callback_str = callback  # because callback gets overwritten
  
                  def callback(x):
                      print(callback_str % x)
  
              self._fps_window = window
              self.events.draw.connect(self._update_fps)
              self._fps_callback = callback
          else:
              self._fps_callback = None
docs: Measure the current FPS
  
          Sets the update window, connects the draw event to update_fps
          and sets the callback function.
  
          Parameters
          ----------
          window : float
              The time-window (in seconds) to calculate FPS. Default 1.0.
          callback : function | str
              The function to call with the float FPS value, or the string
              to be formatted with the fps value and then printed. The
              default is ``'%1.1f FPS'``. If callback evaluates to False, the
              FPS measurement is stopped.