/// <summary> /// Notify the stability tracker that a crash has occured /// </summary> public void NotifyCrash() { InstrumentationLogger.LogAnonymousTimedEvent( "Stability", "TimeBetweenFailure", timeSinceLastCrash.Elapsed); timeSinceLastCrash.Restart(); }
/// <summary> /// Start up and report the status of the last shutdown /// </summary> public static void Startup() { StabilityUtils.IsLastShutdownClean = IsLastShutdownClean(); String cleanShutdownValue = Registry.GetValue(REG_KEY, SHUTDOWN_TYPE_NAME, null) as String; String uptimeValue = Registry.GetValue(REG_KEY, UPTIME_NAME, null) as String; bool isUptimeSpanValid = false; TimeSpan uptimeSpan = TimeSpan.MinValue; long uptimeMs; if (long.TryParse(uptimeValue, out uptimeMs)) { uptimeSpan = TimeSpan.FromMilliseconds(uptimeMs); isUptimeSpanValid = true; } if (cleanShutdownValue == null || uptimeValue == null) { InstrumentationLogger.LogAnonymousEvent("FirstTimeStartup", "Stability"); } else { switch (cleanShutdownValue) { case CLEAN_SHUTDOWN_VALUE: InstrumentationLogger.LogAnonymousEvent("Clean shutdown", "Stability"); if (isUptimeSpanValid) { InstrumentationLogger.LogAnonymousTimedEvent("Stability", "Clean Uptime", uptimeSpan); } break; case CRASHING_SHUTDOWN_VALUE: InstrumentationLogger.LogAnonymousEvent("Crashing shutdown", "Stability"); if (isUptimeSpanValid) { InstrumentationLogger.LogAnonymousTimedEvent("Stability", "Dirty Uptime", uptimeSpan); } break; case ASSUMING_CRASHING_SHUTDOWN_VALUE: //This is the case where we don't know what happened, so we're defaulting InstrumentationLogger.LogAnonymousEvent("Assumed crashing shutdown", "Stability"); if (isUptimeSpanValid) { InstrumentationLogger.LogAnonymousTimedEvent("Stability", "Assumed Dirty Uptime", uptimeSpan); } break; default: //Something went wrong, fail out with 'unknown' data. InstrumentationLogger.LogAnonymousEvent("Unknown shutdown", "Stability"); Debug.WriteLine("Unknown shutdown key value: " + cleanShutdownValue); break; } } // If we don't do anything to explicitly set the type of shutdown assume we hard-crashed // this is pesimistic Registry.SetValue(REG_KEY, SHUTDOWN_TYPE_NAME, ASSUMING_CRASHING_SHUTDOWN_VALUE); }