protected override void Dispose(bool disposing) { _requestCounter?.Dispose(); _requestCounter = null; base.Dispose(disposing); }
/// <summary> /// Writes specific metric if the source is enabled. /// </summary> /// <param name="source">The event source to check.</param> /// <param name="counter">The counter to write metric.</param> /// <param name="value">The value to write.</param> internal static void WriteMetricIfEnabled(EventSource source, EventCounter counter, float value) { if (source.IsEnabled()) { counter.WriteMetric(value); } }
private EventCounter addCounter(Type type) { var counter = new EventCounter(type); counterLookup.Add(type, counter); return(counter); }
public SimpleEventSource(string _displayName, string _displayUnits) { _myCounter = new EventCounter("test-counter", this) { DisplayName = _displayName, DisplayUnits = _displayUnits }; }
public void FeatureEvaluated(string featureName, string productName, string deploymentName, long elapsedMilliseconds) { Interlocked.Increment(ref _perSecondFeatureEvaluations); if (featureName != null) { var counterName = $"{featureName.Trim().ToLower()}-evaluation-time"; #if NETSTANDARD2_1 if (!_featureDynamicCounters.TryGetValue(counterName, out EventCounter counter)) { counter = new EventCounter(counterName, this) { DisplayName = $"Feature [{featureName.Trim().ToLower()}] Evaluation Time / ms" }; _featureDynamicCounters.TryAdd(counterName, counter); } counter?.WriteMetric(elapsedMilliseconds); #endif } WriteEvent(4, featureName, productName, deploymentName, elapsedMilliseconds); }
public void FeatureEvaluated(string featureName, string productName, long elapsedMilliseconds) { productName = productName ?? EsquioConstants.DEFAULT_PRODUCT_NAME; Interlocked.Increment(ref _perSecondFeatureEvaluations); if (featureName != null) { var counterName = $"{featureName.Trim().ToLower()}-evaluation-time"; if (!_featureDynamicCounters.TryGetValue(counterName, out EventCounter counter)) { counter = new EventCounter(counterName, this) { DisplayName = $"Feature [{featureName.Trim().ToLower()}] Evaluation Time / ms" }; _featureDynamicCounters.TryAdd(counterName, counter); } counter?.WriteMetric(elapsedMilliseconds); } WriteEvent(4, featureName, productName, elapsedMilliseconds); }
public CustomMetricsEventSource(string name) : base(name) { // There's currently a bug in the framework that means we need to create at // least one EventCounter within the EventSource constructor for dynamic // EventCounter creation to work. _methodDurationCounter = new EventCounter(nameof(_methodDurationCounter), this); }
private SocketEventSource() { _connectionsStarted = new EventCounter("ConnectionsStarted", this); _connectionsStopped = new EventCounter("ConnectionsStopped", this); _connectionsTimedOut = new EventCounter("ConnectionsTimedOut", this); _connectionDuration = new EventCounter("ConnectionDuration", this); }
public virtual int CompareTo(LogItemViewModelBase other) { // First compare the items by time int i = this.Time.CompareTo(other.Time); if (i != 0) { return(i); } // If the time is equal, consider the event counter value and handle overflows const int range = 10000; if (EventCounter > int.MaxValue - range && other.EventCounter < int.MinValue + range) { // Overflow, other is newer return(-1); } if (EventCounter < int.MinValue + range && other.EventCounter > int.MaxValue - range) { // Overflow, other is older return(1); } return(EventCounter.CompareTo(other.EventCounter)); }
private BMCounterSource() : base(EventSourceSettings.EtwSelfDescribingEventFormat) { // Counter names should ideally be the same length, so I'm naming them with number-suffix. this.m_eventCounter = new EventCounter("BenchmarkCounter1", this) { // Same thing for these fields DisplayName = "ADisplayName", DisplayUnits = "MSec" }; this.m_pollingCounter = new PollingCounter("BenchmarkCounter2", this, () => 1) { DisplayName = "ADisplayName", DisplayUnits = "MSec" }; this.m_incrementingEventCounter = new IncrementingEventCounter("BenchmarkCounter3", this) { DisplayName = "ADisplayName", DisplayUnits = "MSec" }; this.m_incrementingPollingCounter = new IncrementingPollingCounter("BenchmarkCounter4", this, () => 1) { DisplayName = "ADisplayName", DisplayUnits = "MSec" }; }
private DemoCounterSource() : base() { sqlResponseTimeCounter = new EventCounter("sql-response-time", this) { DisplayName = "SQL response time (ms)", DisplayUnits = "ms" }; }
public UserController(HttpClient httpClient, StatelessServiceContext context, FabricClient fabricClient, EventCounter requestCounter) { this.fabricClient = fabricClient; this.httpClient = httpClient; this.serviceContext = context; this.reverseProxyBaseUri = Environment.GetEnvironmentVariable("ReverseProxyBaseUri"); this.requestCounter = requestCounter; }
/// <summary> /// working-time 是dotnet-counters --counters的参数 /// </summary> private WorkingEventSource() { _workingCounter = new EventCounter("working-time", this) { DisplayName = "Working Time", DisplayUnits = "ms" }; }
public DbEventCountersSource(string name) : base(name) { NumExecutions = new EventCounter("executions", this); NumExecutionErrors = new EventCounter("execution_errors", this); NumQueries = new EventCounter("queries", this); NumETx = new EventCounter("execute_transactions", this); NumQTx = new EventCounter("query_transactions", this); }
public IpBlockerService(IOptions <IpBlockerSettings> settings, ILogger <IpBlockerService> log) { this.settings = settings.Value; this.events = new EventCounter(() => DateTimeOffset.Now, this.settings.SurveyTime); this.log = log; this.cleanupTask = Observable.Interval(TimeSpan.FromMinutes(5)) .Subscribe(_ => this.events.Cleanup()); }
public SubstemOverrideEventsTests() { _eventCounter = new EventCounter(); var testContext = new StemTestContext(); testContext.TestDependencyResolver.Add(_eventCounter); _artistCollection = testContext.GetArtistsCollection <ArtistsStem>(); }
internal static void AddEventCounter(EventSource eventSource, EventCounter eventCounter) { int eventSourceIndex = EventListenerHelper.EventSourceIndex(eventSource); EventCounterGroup.EnsureEventSourceIndexAvailable(eventSourceIndex); EventCounterGroup eventCounterGroup = GetEventCounterGroup(eventSource); eventCounterGroup.Add(eventCounter); }
public void ReportOccurence(string name) { if (!_dynamicCounters.TryGetValue(name, out EventCounter counterInstance)) { counterInstance = new EventCounter(name, this); _dynamicCounters.Add(name, counterInstance); } counterInstance.WriteMetric(float.NaN); }
public void ReportMetric(string name, float value) { if (!dynamicCounters.TryGetValue(name, out EventCounter counterInstance)) { counterInstance = new EventCounter(name, this); dynamicCounters.Add(name, counterInstance); } counterInstance.WriteMetric(value); }
/// <summary> /// Initializes a new instance of the <see cref="GraphSearchEventSource"/> class. /// </summary> private GraphSearchEventSource() : base(EventSourceSettings.EtwSelfDescribingEventFormat) { var graphKNearestLatency = new EventCounter("KNearest.Latency", this); GraphKNearestLatencyReporter = (float value) => WriteMetricIfEnabled(this, graphKNearestLatency, value); var graphKNearestVisitedNodes = new EventCounter("KNearest.VisitedNodes", this); GraphKNearestVisitedNodesReporter = (float value) => WriteMetricIfEnabled(this, graphKNearestVisitedNodes, value); }
public void ClearTest() { var target = new EventCounter(() => DateTimeOffset.Now, TimeSpan.FromHours(1)); target.Count("a"); target.Count("a"); target.Clear("a"); target.GetCount("a").Should().Be(0); }
public StoreEventCountersSource(string name) : base(name) { NumSnapshots = new EventCounter("num_snapshots", this); NumSnaphotsBlocked = new EventCounter("num_snapshots_blocked", this); NumBackups = new EventCounter("num_backups", this); NumRestores = new EventCounter("num_restores", this); NumConnects = new EventCounter("num_connects", this); NumDisconnects = new EventCounter("num_disconnects", this); NumConnTimeouts = new EventCounter("num_conn_timeouts", this); }
/// <summary> /// Initializes a new instance of the <see cref="GraphBuildEventSource"/> class. /// </summary> private GraphBuildEventSource() : base(EventSourceSettings.EtwSelfDescribingEventFormat) { var coreGetDistanceCacheHitRate = new EventCounter("GetDistance.CacheHitRate", this); CoreGetDistanceCacheHitRateReporter = (float value) => WriteMetricIfEnabled(this, coreGetDistanceCacheHitRate, value); var graphInsertNodeLatency = new EventCounter("InsertNode.Latency", this); GraphInsertNodeLatencyReporter = (float value) => WriteMetricIfEnabled(this, graphInsertNodeLatency, value); }
private async Task Run() { await _client.Authenticate(); EventCounter eventCounter = _productRepository.GetEventCounter(EVENT_COUNTER_ID); if (eventCounter == null) { _productRepository.AddEventCounter(new EventCounter() { Id = EVENT_COUNTER_ID, Value = 0 }); _unitOfWork.CommitChanges(); eventCounter = _productRepository.GetEventCounter(EVENT_COUNTER_ID); } while (_isListening) { try { IEnumerable <EventDTO> events = await _client.GetEvents(eventCounter.Value, 50); if (events == null || events.Count() == 0) { //TODO: Change this so that thread dont sleep. Not strictly needed but nice. //Events updated every 20 seconds Logger.Debug("No product catalog events found. Waiting {seconds} seconds before next update.", DELAY_SECONDS); Thread.Sleep(DELAY_SECONDS * MILISECONDS_PER_SECONDS); continue; } Logger.Debug("Product events received"); IEnumerable <EventDTO> productEvents = events.Where(x => x.ObjectType == "Product"); IEnumerable <Guid> productsToRemove = events.Where(x => x.Event == "Deleted").Select(x => x.ObjectId).ToHashSet(); IEnumerable <Guid> productsToUpdate = events.Where(x => x.Event == "Updated" || x.Event == "Added").Select(x => x.ObjectId).ToHashSet(); await UpdateProductCache(productsToUpdate, productsToRemove); eventCounter.Value += events.Count(); _unitOfWork.CommitChanges(); Logger.Info("Product changes applied to: {@ids}", productsToRemove.Concat(productsToUpdate).ToHashSet()); } catch (AccessDeniedException) { Logger.Info("Access denied to Product catalog. Retrying."); await _client.Authenticate(); } catch (HttpRequestException) { Logger.Warn("Cannot connect to ProductCatalog. Waiting before retry."); Thread.Sleep(DELAY_SECONDS * MILISECONDS_PER_SECONDS); } } }
public void AddWriteDuration(double writeDurationInMilliseconds) { if (_cacheWriteDurationCounter is null) { _cacheWriteDurationCounter = new EventCounter(CacheWriteDurationCounterName, this) { DisplayName = "Cache write duration", DisplayUnits = "ms" }; } _cacheWriteDurationCounter.WriteMetric(writeDurationInMilliseconds); }
public void SimpleCountTest() { var target = new EventCounter(() => DateTimeOffset.Now, TimeSpan.FromHours(1)); target.Count("a"); target.Count("a"); target.Count("b"); target.GetCount("a").Should().Be(2); target.GetCount("b").Should().Be(1); target.GetCount("c").Should().Be(0); }
protected override void OnEventCommand(EventCommandEventArgs command) { if (command.Command == EventCommand.Enable) { TriggerHeader = new EventCounter(Constants.TriggerHeaderCounterName, this) { DisplayName = "Count of the custom header received on any request", DisplayUnits = "Num", }; } //base.OnEventCommand(command); }
public void eventCounter_Returns0_whenFileDoesNotContainAnyFault() { // Arrange var eventCounter = new EventCounter(); // Act eventCounter.ParseEvents("4", EventLog4); // Verify / Assert var eventCounts = JsonConvert.DeserializeObject <List <EventCount> >(eventCounter.GetEventCounts()); Assert.AreEqual(eventCounts.First().eventCount, 0); }
public void CheckEventListening() { TestSuiteBuilder builder = new TestSuiteBuilder(); Test testSuite = builder.Build( new TestPackage( testsDll ) ); EventCounter counter = new EventCounter(); testSuite.Run(counter, TestFilter.Empty); Assert.AreEqual(testSuite.CountTestCases(TestFilter.Empty), counter.testCaseStart); Assert.AreEqual(testSuite.CountTestCases(TestFilter.Empty), counter.testCaseFinished); Assert.AreEqual(MockAssembly.SuitesRun, counter.suiteStarted); Assert.AreEqual(MockAssembly.SuitesRun, counter.suiteFinished); }
public void eventCounter_Returns1_whenFileContainsSingleFaultWithRedundantStages() { // Arrange var eventCounter = new EventCounter(); // Act eventCounter.ParseEvents("2", EventLog2); // Verify / Assert var eventCounts = JsonConvert.DeserializeObject <List <EventCount> >(eventCounter.GetEventCounts()); Assert.AreEqual(eventCounts.First().eventCount, 1); }
public void eventCounter_Returns2_whenFileContainsTwoFaults() { // Arrange var eventCounter = new EventCounter(); // Act eventCounter.ParseEvents("3", EventLog3); // Verify / Assert var eventCounts = JsonConvert.DeserializeObject <List <EventCount> >(eventCounter.GetEventCounts()); Assert.AreEqual(eventCounts.First().eventCount, 2); }
/// <summary> /// Initializes the <see cref="EventCounterManager"/> class. /// </summary> static EventCounterManager() { // Create a dedicated dbController for the EventCounters since they are all executed in non-blocking mode, // none of the queries touch the normal game tables, and none of the queries do not rely on order of execution var dbConnSettings = new DbConnectionSettings(); var dbController = new ServerDbController(dbConnSettings.GetMySqlConnectionString()); // Create the query objects var pool = dbController.ConnectionPool; var userECQuery = EventCounterHelper.CreateQuery<CharacterID, UserEventCounterType>(pool, EventCountersUserTable.TableName, "user_id", "user_event_counter_id"); var guildECQuery = EventCounterHelper.CreateQuery<GuildID, GuildEventCounterType>(pool, EventCountersGuildTable.TableName, "guild_id", "guild_event_counter_id"); var shopECQuery = EventCounterHelper.CreateQuery<ShopID, ShopEventCounterType>(pool, EventCountersShopTable.TableName, "shop_id", "shop_event_counter_id"); var mapECQuery = EventCounterHelper.CreateQuery<MapID, MapEventCounterType>(pool, EventCountersMapTable.TableName, "map_id", "map_event_counter_id"); var questECQuery = EventCounterHelper.CreateQuery<QuestID, QuestEventCounterType>(pool, EventCountersQuestTable.TableName, "quest_id", "quest_event_counter_id"); var itemTemplateECQuery = EventCounterHelper.CreateQuery<ItemTemplateID, ItemTemplateEventCounterType>(pool, EventCountersItemTemplateTable.TableName, "item_template_id", "item_template_event_counter_id"); var npcECQuery = EventCounterHelper.CreateQuery<CharacterTemplateID, NPCEventCounterType>(pool, EventCountersNpcTable.TableName, "npc_template_id", "npc_event_counter_id"); // Create the event counters _userEventCounter = new EventCounter<CharacterID, UserEventCounterType>(userECQuery); _guildEventCounter = new EventCounter<GuildID, GuildEventCounterType>(guildECQuery); _shopEventCounter = new EventCounter<ShopID, ShopEventCounterType>(shopECQuery); _mapEventCounter = new EventCounter<MapID, MapEventCounterType>(mapECQuery); _questEventCounter = new EventCounter<QuestID, QuestEventCounterType>(questECQuery); _itemTemplateEventCounter = new EventCounter<ItemTemplateID, ItemTemplateEventCounterType>(itemTemplateECQuery); _npcEventCounter = new EventCounter<CharacterTemplateID, NPCEventCounterType>(npcECQuery); }
public void TestChangeRenderingSet() { EventCounter ec = new EventCounter(); Application app = new Application(); app.OnApplicationClosed += new ApplicationClosedEventHandler(ec.OnApplicationClosed); try { Assert.AreEqual(false, IsDVVisible()); string original = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\original.doc"); string modified = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\modified.doc"); Assert.AreEqual(0, app.Comparisons.Count); IComparison comp = app.Comparisons.New(original, modified, "Standard no moves", ComparisonMode.Fast, false); comp.OnComparisonClosed += new ComparisonClosedEventHandler(ec.OnComparisonClosed); comp.OnComparisonRedone += new ComparisonRedoneEventHandler(ec.OnComparisonRedone); Assert.IsNotNull(comp); Assert.IsFalse(string.IsNullOrEmpty(comp.Name)); var changes = comp.Changes; Assert.AreNotEqual(0, changes.Count); bool seenTextBeforeChange = false; bool seenTextAfterChange = false; foreach (IChange c in changes) { Assert.IsNotNull(c); Assert.AreNotEqual(0, c.FirstChangeNumber); Assert.IsTrue(c.LastChangeNumber >= c.FirstChangeNumber); Assert.IsFalse(string.IsNullOrEmpty(c.OriginalText) && string.IsNullOrEmpty(c.ModifiedText), c.FirstChangeNumber.ToString()); seenTextBeforeChange |= !string.IsNullOrEmpty(c.TextBeforeChange); seenTextAfterChange |= !string.IsNullOrEmpty(c.TextAfterChange); } Assert.IsTrue(seenTextBeforeChange); Assert.IsTrue(seenTextAfterChange); Assert.AreEqual("Standard no moves", comp.RenderingSetName); comp.ChangeRenderingSet("Standard"); Assert.AreEqual(1, ec.Redone); Assert.Throws(typeof(COMException), delegate() { int i = changes.Count; }); Assert.AreEqual("Standard", comp.RenderingSetName); } finally { app.Quit(false); } }
public void TestSwap() { EventCounter ec = new EventCounter(); Application app = new Application(); app.OnApplicationClosed += new ApplicationClosedEventHandler(ec.OnApplicationClosed); try { Assert.AreEqual(false, IsDVVisible()); app.Visible = true; string original = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\original.doc"); string modified = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\modified.doc"); Assert.AreEqual(0, app.Comparisons.Count); IComparison comp = app.Comparisons.New(original, modified, "Standard no moves", ComparisonMode.Fast, false); comp.OnComparisonClosed += new ComparisonClosedEventHandler(ec.OnComparisonClosed); comp.OnComparisonRedone += new ComparisonRedoneEventHandler(ec.OnComparisonRedone); Assert.IsNotNull(comp); Assert.IsFalse(string.IsNullOrEmpty(comp.Name)); string name = comp.Name; IChangeCollection changes = comp.Changes; Assert.AreEqual(0, ec.Redone); comp.SwapOriginalModified(); Assert.AreEqual(1, ec.Redone); Assert.Throws(typeof(COMException), delegate() { int i = changes.Count; }); string newName = comp.Name; Assert.AreNotEqual(name, newName); Assert.AreEqual(0, ec.Closed); Assert.AreEqual(0, ec.AppClosed); } finally { app.Quit(false); } Assert.AreEqual(1, ec.AppClosed); Assert.AreEqual(1, ec.Closed); }
protected void CopyTo(EventCounter other) { other.Trades = (CounterData)this.Trades.Clone(); other.Quotes = (CounterData)this.Quotes.Clone(); }