     for e in events
       applyEvent state, e
 
-    starts = state.startups.map (s) -> s.duration/1000
-    stops = state.shutdowns.map (s) -> s.duration/1000
-    scaleups = state.scaleups.map (s) -> s.duration/1000
-    uptimes = state.uptimes.map (s) -> s.duration/1000
-    results =
-      scaleup: statistics.median scaleups
-      scaleup_stddev: statistics.standard_deviation scaleups
-      scaleup_length: scaleups.length
-      uptime: statistics.median uptimes
-      uptime_stddev: statistics.standard_deviation uptimes
-      uptime_length: uptimes.length
-      startup: statistics.mean starts
-      startup_stddev: statistics.standard_deviation starts
-      startup_length: starts.length
-      shutdown: statistics.mean stops
-      shutdown_stddev: statistics.standard_deviation stops
-      shutdown_length: stops.length
-    wasted = results.scaleup + results.startup + results.shutdown # assumes Heroku charges for all these steps
-    results.utilization = results.uptime / (results.uptime + wasted)
+    state.startups = state.startups.filter hasDynos(dynos)
+    state.shutdowns = state.shutdowns.filter hasDynos(dynos)
+    state.scaleups = state.scaleups.filter hasDynos(dynos)
+    state.uptimes = state.uptimes.filter hasDynos(dynos)
+
+    results = calculateStats state
 
     return callback null, results
+
+collectOption = (value, array) ->
+  array.push value
+  return array
 
 # TODO: calculate whole delay from scaling to up by default, and scaling down to down
 # TODO: allow to separate between (module) loading time, and startup time


  started = (info) ->
    return program.started.test info
  analyzeStartups filename, started, (err, res) ->
    throw err if err
    console.log res


    # FIXME: handle. Maybe outside/before


calculateStats = (state) ->
  starts = state.startups.map (s) -> s.duration/1000
  stops = state.shutdowns.map (s) -> s.duration/1000
  scaleups = state.scaleups.map (s) -> s.duration/1000
  uptimes = state.uptimes.map (s) -> s.duration/1000
  results =
    scaleup: statistics.median scaleups
    scaleup_stddev: statistics.standard_deviation scaleups
    scaleup_length: scaleups.length
    uptime: statistics.median uptimes
    uptime_stddev: statistics.standard_deviation uptimes
    uptime_length: uptimes.length
    startup: statistics.mean starts
    startup_stddev: statistics.standard_deviation starts
    startup_length: starts.length
    shutdown: statistics.mean stops
    shutdown_stddev: statistics.standard_deviation stops
    shutdown_length: stops.length
  wasted = results.scaleup + results.startup + results.shutdown # assumes Heroku charges for all these steps
  results.utilization = results.uptime / (results.uptime + wasted)

  return results

hasDynos = (roles) ->
  return (s) ->
    hasRoles = roles? and roles.length # empty array means include everything
    return true if not hasRoles
    [role, number] = s.dyno.split '.'
    include = role in roles

    return include

analyzeStartups = (filename, started, dynos, callback) ->
  fs = require 'fs'

  state = {}
