public void CategorySampleReadsDataCorrectly() { // ARRANGE var dataList = new List <byte>(); string resourceName = "Unit.Tests.QuickPulse.PerfLib.PerfData.data"; Stream stream = null; try { stream = typeof(CategorySampleTests).Assembly.GetManifestResourceStream(resourceName); using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { stream = null; dataList.AddRange(reader.ReadToEnd().Split(',').Select(byte.Parse)); } } finally { stream?.Dispose(); } byte[] data = dataList.ToArray(); var perfLib = PerfLib.GetPerfLib(); // ACT var categorySample = new CategorySample(data, 230, 6, perfLib); // ASSERT // the test data has 28 counters, 165 instances, with the first counter being index 6 (% Processor Time). Assert.AreEqual(28, categorySample.CounterTable.Count); Assert.AreEqual(165, categorySample.InstanceNameTable.Count); Assert.AreEqual(6, categorySample.CounterTable.First().Key); Assert.AreEqual("Idle", categorySample.InstanceNameTable.First().Key); }
/// <summary> /// Initialize method is called after all configuration properties have been loaded from the configuration. /// </summary> /// <param name="configuration">TelemetryConfiguration passed to the module.</param> public void Initialize(TelemetryConfiguration configuration) { if (!this.isInitialized) { lock (this.moduleInitializationLock) { if (!this.isInitialized) { QuickPulseEventSource.Log.ModuleIsBeingInitializedEvent( this.QuickPulseServiceEndpoint, this.DisableFullTelemetryItems, this.DisableTopCpuProcesses, this.AuthenticationApiKey); QuickPulseEventSource.Log.TroubleshootingMessageEvent("Validating configuration..."); ValidateConfiguration(configuration); this.config = configuration; QuickPulseEventSource.Log.TroubleshootingMessageEvent("Initializing members..."); this.collectionTimeSlotManager = this.collectionTimeSlotManager ?? new QuickPulseCollectionTimeSlotManager(); this.performanceCollector = this.performanceCollector ?? PerformanceCounterUtility.GetPerformanceCollector(); this.timeProvider = this.timeProvider ?? new Clock(); this.topCpuCollector = this.topCpuCollector ?? new QuickPulseTopCpuCollector(this.timeProvider, new QuickPulseProcessProvider(PerfLib.GetPerfLib())); this.timings = timings ?? QuickPulseTimings.Default; CollectionConfigurationError[] errors; this.collectionConfiguration = new CollectionConfiguration( new CollectionConfigurationInfo() { ETag = string.Empty }, out errors, this.timeProvider); this.dataAccumulatorManager = this.dataAccumulatorManager ?? new QuickPulseDataAccumulatorManager(this.collectionConfiguration); this.InitializeServiceClient(configuration); this.stateManager = new QuickPulseCollectionStateManager( this.ServiceClient, this.timeProvider, this.timings, this.OnStartCollection, this.OnStopCollection, this.OnSubmitSamples, this.OnReturnFailedSamples, this.OnUpdatedConfiguration); this.CreateStateThread(); this.isInitialized = true; } } } }
/// <summary> /// Initialize method is called after all configuration properties have been loaded from the configuration. /// </summary> /// <param name="configuration">TelemetryConfiguration passed to the module.</param> public void Initialize(TelemetryConfiguration configuration) { if (!this.isInitialized) { lock (this.lockObject) { if (!this.isInitialized) { QuickPulseEventSource.Log.ModuleIsBeingInitializedEvent( this.QuickPulseServiceEndpoint, this.DisableFullTelemetryItems, this.DisableTopCpuProcesses); QuickPulseEventSource.Log.TroubleshootingMessageEvent("Validating configuration..."); this.ValidateConfiguration(configuration); this.config = configuration; QuickPulseEventSource.Log.TroubleshootingMessageEvent("Initializing members..."); this.collectionTimeSlotManager = this.collectionTimeSlotManager ?? new QuickPulseCollectionTimeSlotManager(); this.dataAccumulatorManager = this.dataAccumulatorManager ?? new QuickPulseDataAccumulatorManager(); this.performanceCollector = this.performanceCollector ?? (PerformanceCounterUtility.IsWebAppRunningInAzure() ? (IPerformanceCollector) new WebAppPerformanceCollector() : (IPerformanceCollector) new StandardPerformanceCollector()); this.timeProvider = this.timeProvider ?? new Clock(); this.topCpuCollector = this.topCpuCollector ?? new QuickPulseTopCpuCollector(this.timeProvider, new QuickPulseProcessProvider(PerfLib.GetPerfLib())); this.timings = timings ?? QuickPulseTimings.Default; this.InitializeServiceClient(configuration); this.stateManager = new QuickPulseCollectionStateManager( this.serviceClient, this.timeProvider, this.timings, this.OnStartCollection, this.OnStopCollection, this.OnSubmitSamples, this.OnReturnFailedSamples); this.CreateStateThread(); this.isInitialized = true; } } } }