def analyze_service
      now = Time.now.to_i
      if @last_analysis && @last_event == @last_update
        delta = now - @last_analysis_time
        @last_analysis[:uptime] += delta
        @last_analysis[:total_uptime] += delta
      else
        last_run = last_crash = @last_event = {:time => 0, :pid => 0, :event => nil}
        restarts = graceful_exits = crashes = accumulated_uptime = 0
        crashed_last = false
        load.each do |event|
          event = SerializationHelper.symbolize_keys(event)
          case event[:event]
          when "start"
            case @last_event[:event]
            when "stop", "graceful exit"
              restarts += 1
            when "start"
              crashes += 1
              last_crash = event
              crashed_last = true
            when "run"
              crashes += 1
              last_crash = event
              crashed_last = true
              # Accumulating uptime here although this will wrongly include recovery time
              accumulated_uptime += (event[:time] - @last_event[:time])
            end
          when "run"
            last_run = event
          when "stop"
            crashed_last = false
            if @last_event[:event] == "run" && @last_event[:pid] == event[:pid]
              accumulated_uptime += (event[:time] - @last_event[:time])
            end
          when "graceful exit"
            crashed_last = false
            graceful_exits += 1
          else
            next
          end
          @last_event = event
        end
        current_uptime = last_run[:pid] == @pid ? (now - last_run[:time]) : 0
        @last_analysis = {
          :uptime => current_uptime,
          :total_uptime => accumulated_uptime + current_uptime
        }
        if restarts > 0
          @last_analysis[:restarts] = restarts
          @last_analysis[:graceful_exits] = graceful_exits
        end
        if crashes > 0
          @last_analysis[:crashes] = crashes
          @last_analysis[:last_crash_time] = last_crash[:time]
          @last_analysis[:crashed_last] = crashed_last
        end
      end
      @last_analysis_time = now
      @last_analysis
    end
def analyze_service
      now = Time.now.to_i
      if @last_analysis && @last_event == @last_update
        delta = now - @last_analysis_time
        @last_analysis[:uptime] += delta
        @last_analysis[:total_uptime] += delta
      else
        last_run = last_crash = @last_event = {:time => 0, :pid => 0, :event => nil}
        restarts = graceful_exits = crashes = accumulated_uptime = 0
        crashed_last = false
        load.each do |event|
          event = SerializationHelper.symbolize_keys(event)
          case event[:event]
          when "start"
            case @last_event[:event]
            when "stop", "graceful exit"
              restarts += 1
            when "start"
              crashes += 1
              last_crash = event
              crashed_last = true
            when "run"
              crashes += 1
              last_crash = event
              crashed_last = true
              # Accumulating uptime here although this will wrongly include recovery time
              accumulated_uptime += (event[:time] - @last_event[:time])
            end
          when "run"
            last_run = event
          when "stop"
            crashed_last = false
            if @last_event[:event] == "run" && @last_event[:pid] == event[:pid]
              accumulated_uptime += (event[:time] - @last_event[:time])
            end
          when "graceful exit"
            crashed_last = false
            graceful_exits += 1
          else
            next
          end
          @last_event = event
        end
        current_uptime = last_run[:pid] == @pid ? (now - last_run[:time]) : 0
        @last_analysis = {
          :uptime => current_uptime,
          :total_uptime => accumulated_uptime + current_uptime
        }
        if restarts > 0
          @last_analysis[:restarts] = restarts
          @last_analysis[:graceful_exits] = graceful_exits
        end
        if crashes > 0
          @last_analysis[:crashes] = crashes
          @last_analysis[:last_crash_time] = last_crash[:time]
          @last_analysis[:crashed_last] = crashed_last
        end
      end
      @last_analysis_time = now
      @last_analysis
    end
Analyze history to determine service attributes like uptime and restart/crash counts

 === Return
 (Hash):: Results of analysis
   :uptime(Integer):: Current time in service
   :total_uptime(Integer):: Total time in service (but if there were crashes
     this total includes recovery time, which makes it inaccurate)
   :restarts(Integer|nil):: Number of restarts, if any
   :graceful_exits(Integer|nil):: Number of graceful terminations, if any
   :crashes(Integer|nil):: Number of crashes, if any
   :last_crash_time(Integer|nil):: Time in seconds in Unix-epoch when last crash occurred, if any
   :crashed_last(Boolean):: Whether crashed last time it was started