public void NormalizedCPUPercenageGaugeBasicValidation() { int initialProcessorsCount = int.Parse(Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS"), CultureInfo.InvariantCulture); NormalizedCPUPercentageGauge normalizedGauge = new NormalizedCPUPercentageGauge( "CPU", new RawCounterGauge(@"\Process(??APP_WIN32_PROC??)\Normalized Private Bytes", "userTime", AzureWebApEnvironmentVariables.App, new CacheHelperTests())); CPUPercenageGauge gauge = new CPUPercenageGauge( "CPU", new RawCounterGauge(@"\Process(??APP_WIN32_PROC??)\Private Bytes", "userTime", AzureWebApEnvironmentVariables.App, new CacheHelperTests())); double value1 = gauge.GetValueAndReset(); double normalizedValue1 = normalizedGauge.GetValueAndReset(); Assert.IsTrue(Math.Abs(value1) < 0.000001); Assert.IsTrue(Math.Abs(normalizedValue1) < 0.000001); Stopwatch sw = Stopwatch.StartNew(); Thread.Sleep(TimeSpan.FromSeconds(10)); long actualSleepTimeTicks = sw.Elapsed.Ticks; double value2 = gauge.GetValueAndReset(); double normalizedValue2 = normalizedGauge.GetValueAndReset(); Assert.IsTrue( Math.Abs(value2 - (normalizedValue2 * initialProcessorsCount)) < 0.005, string.Format(CultureInfo.InvariantCulture, "Actual: {0}, Expected: {1}", normalizedValue2, value2 / initialProcessorsCount)); }
public void BasicValidation() { CPUPercenageGauge gauge = new CPUPercenageGauge( "CPU", new RawCounterGauge(@"\Process(??APP_WIN32_PROC??)\Private Bytes * 2", "userTime", AzureWebApEnvironmentVariables.App, new CacheHelperTests())); double value1 = gauge.GetValueAndReset(); Assert.IsTrue(Math.Abs(value1) < 0.000001); Thread.Sleep(TimeSpan.FromSeconds(10)); double value2 = gauge.GetValueAndReset(); Assert.IsTrue( Math.Abs(value2 - ((24843750 - 24062500.0) / TimeSpan.FromSeconds(10).Ticks * 100.0)) < 0.005, string.Format(CultureInfo.InvariantCulture, "Actual: {0}, Expected: {1}", value2, (24843750 - 24062500.0) / TimeSpan.FromSeconds(10).Ticks)); }