public static ExponentialHistogramValueStatistic Create_ExponentialHistogram(StatisticName name, int numBuckets) { var hist = new ExponentialHistogramValueStatistic(name.Name, numBuckets); StringValueStatistic.FindOrCreate(name, hist.PrintHistogram); return(hist); }
public static bool TryFind(StatisticName name, out AverageTimeSpanStatistic result) { lock (classLock) { return(registeredStatistics.TryGetValue(name.Name, out result)); } }
public static LinearHistogramValueStatistic Create_LinearHistogram(StatisticName name, int numBuckets, double maximumValue) { var hist = new LinearHistogramValueStatistic(name.Name, numBuckets, maximumValue); StringValueStatistic.FindOrCreate(name, hist.PrintHistogram); return(hist); }
public static StringValueStatistic Find(StatisticName name) { lock (lockable) { return(registeredStatistics.ContainsKey(name.Name) ? registeredStatistics[name.Name] : null); } }
public static LinearHistogramValueStatistic Create_LinearHistogram_ForTiming(StatisticName name, int numBuckets, TimeSpan maximumValue) { var hist = new LinearHistogramValueStatistic(name.Name, numBuckets, maximumValue.Ticks); StringValueStatistic.FindOrCreate(name, hist.PrintHistogramInMillis); return(hist); }
public void Counter_Increment() { StatisticName name = new StatisticName(CounterName); CounterStatistic ctr = CounterStatistic.FindOrCreate(name); Assert.AreEqual(0, ctr.GetCurrentValue()); ctr.Increment(); Assert.AreEqual(1, ctr.GetCurrentValue()); }
public void Counter_SetValue() { StatisticName name = new StatisticName(CounterName); int val = random.Next(1000000); CounterStatistic ctr = CounterStatistic.FindOrCreate(name); ctr.IncrementBy(val); Assert.AreEqual(val, ctr.GetCurrentValue()); }
public void Counter_InitialValue() { StatisticName name = new StatisticName(CounterName); ICounter<long> ctr = CounterStatistic.FindOrCreate(name); Assert.AreEqual(name.ToString(), ctr.Name); Assert.IsTrue(ctr.ToString().Contains(name.Name)); Assert.AreEqual(0, ctr.GetCurrentValue()); }
public static StringValueStatistic Find(StatisticName name) { lock (dict) { dict.TryGetValue(name.Name, out var stat); return(stat); } }
private static CounterStatistic FindOrCreate_Impl(StatisticName name, bool useDelta, CounterStorage storage, bool isHidden) { if (registeredStatistics.TryGetValue(name.Name, out var stat)) { return(stat); } return(registeredStatistics.GetOrAdd(name.Name, new CounterStatistic(name.Name, useDelta, storage, isHidden))); }
public static void Delete(StatisticName name) { lock (classLock) { if (registeredStatistics.TryGetValue(name.Name, out _)) { registeredStatistics.Remove(name.Name); } } }
public static void Delete(StatisticName name) { lock (classLock) { AverageTimeSpanStatistic stat; if (registeredStatistics.TryGetValue(name.Name, out stat)) { registeredStatistics.Remove(name.Name); } } }
public static void Delete(StatisticName name) { lock (dict) { if (dict.TryGetValue(name.Name, out var stat)) { dict.Remove(name.Name); // Null the fetcher delegate to prevent memory leaks via undesirable reference capture by the fetcher lambda. stat.fetcher = null; } } }
public void Counter_IncrementFromMinInt() { StatisticName name = new StatisticName(CounterName); int val = int.MinValue; CounterStatistic ctr = CounterStatistic.FindOrCreate(name); ctr.IncrementBy(val); Assert.AreEqual(val, ctr.GetCurrentValue()); ctr.Increment(); Assert.AreEqual(val + 1, ctr.GetCurrentValue()); ctr.Increment(); Assert.AreEqual(val + 2, ctr.GetCurrentValue()); }
ThrowIfNotConsistent( AverageTimeSpanStatistic expected, StatisticName name, CounterStorage storage) { if (storage != expected.Storage) { throw new ArgumentException( $"Please verity that all invocations of AverageTimeSpanStatistic.FindOrCreate() for instance \"{name.Name}\" all specify the same storage type {Enum.GetName(typeof(CounterStorage), expected.Storage)}", nameof(storage)); } }
static public void Delete(StatisticName name) { lock (lockable) { IntValueStatistic stat; if (registeredStatistics.TryGetValue(name.Name, out stat)) { registeredStatistics.Remove(name.Name); // Null the fetcher delegate to prevent memory leaks via undesirable reference capture by the fetcher lambda. stat.fetcher = null; } } }
public void Counter_IncrementFromMaxInt() { StatisticName name = new StatisticName("Counter6"); int val = int.MaxValue; long longVal = int.MaxValue; Assert.AreEqual(longVal, val); CounterStatistic ctr = CounterStatistic.FindOrCreate(name); ctr.IncrementBy(val); Assert.AreEqual(val, ctr.GetCurrentValue()); ctr.Increment(); Assert.AreEqual(longVal + 1, ctr.GetCurrentValue()); ctr.Increment(); Assert.AreEqual(longVal + 2, ctr.GetCurrentValue()); }
public static FloatValueStatistic Find(StatisticName name) { lock (lockable) { if (registeredStatistics.ContainsKey(name.Name)) { return(registeredStatistics[name.Name]); } else { return(null); } } }
private CounterStatistic FindGrainCounter(string grainTypeName) { CounterStatistic ctr; if (grainCounts.TryGetValue(grainTypeName, out ctr)) { return(ctr); } var counterName = new StatisticName(StatisticNames.GRAIN_COUNTS_PER_GRAIN, grainTypeName); ctr = grainCounts[grainTypeName] = CounterStatistic.FindOrCreate(counterName, false); return(ctr); }
private CounterStatistic FindSystemTargetCounter(string systemTargetTypeName) { CounterStatistic ctr; if (systemTargetCounts.TryGetValue(systemTargetTypeName, out ctr)) { return(ctr); } var counterName = new StatisticName(StatisticNames.SYSTEM_TARGET_COUNTS, systemTargetTypeName); ctr = systemTargetCounts[systemTargetTypeName] = CounterStatistic.FindOrCreate(counterName, false); return(ctr); }
private static CounterStatistic FindOrCreate_Impl(StatisticName name, bool useDelta, CounterStorage storage, bool isHidden) { lock (lockable) { CounterStatistic stat; if (registeredStatistics.TryGetValue(name.Name, out stat)) { return(stat); } var ctr = new CounterStatistic(name.Name, useDelta, storage, isHidden); registeredStatistics[name.Name] = ctr; return(ctr); } }
public static FloatValueStatistic FindOrCreate(StatisticName name, Func <float> f, CounterStorage storage) { lock (dict) { if (dict.TryGetValue(name.Name, out var stat)) { return(stat); } var ctr = new FloatValueStatistic(name.Name, f) { Storage = storage }; dict[name.Name] = ctr; return(ctr); } }
public static StringValueStatistic FindOrCreate(StatisticName name, Func <string> f, CounterStorage storage = CounterStorage.LogOnly) { lock (dict) { if (dict.TryGetValue(name.Name, out var stat)) { return(stat); } var ctr = new StringValueStatistic(name.Name, f) { Storage = storage }; dict[name.Name] = ctr; return(ctr); } }
public static FloatValueStatistic FindOrCreate(StatisticName name, Func <float> f, CounterStorage storage) { lock (lockable) { FloatValueStatistic stat; if (registeredStatistics.TryGetValue(name.Name, out stat)) { return(stat); } var ctr = new FloatValueStatistic(name.Name, f) { Storage = storage }; registeredStatistics[name.Name] = ctr; return(ctr); } }
public static StringValueStatistic FindOrCreate(StatisticName name, Func <string> f, CounterStorage storage = CounterStorage.LogOnly) { lock (lockable) { StringValueStatistic stat; if (registeredStatistics.TryGetValue(name.Name, out stat)) { return(stat); } var ctr = new StringValueStatistic(name.Name, f) { Storage = storage }; registeredStatistics[name.Name] = ctr; return(ctr); } }
FindOrCreate( StatisticName name, CounterStorage storage = CounterStorage.LogOnly) { lock (classLock) { AverageTimeSpanStatistic result; if (TryFind(name, out result)) { ThrowIfNotConsistent(result, name, storage); return(result); } else { var newOb = new AverageTimeSpanStatistic(name.Name, storage); registeredStatistics[name.Name] = newOb; return(newOb); } } }
static private AverageValueStatistic FindOrCreate_Impl(StatisticName name, CounterStorage storage, bool multiThreaded) { AverageValueStatistic stat; #if COLLECT_AVERAGE if (multiThreaded) { stat = new MultiThreadedAverageValueStatistic(name); } else { stat = new SingleThreadedAverageValueStatistic(name); } stat.average = FloatValueStatistic.FindOrCreate(name, () => stat.GetAverageValue(), storage); #else stat = new AverageValueStatistic(name); #endif return stat; }
static private AverageValueStatistic FindOrCreate_Impl(StatisticName name, CounterStorage storage, bool multiThreaded) { AverageValueStatistic stat; #if COLLECT_AVERAGE if (multiThreaded) { stat = new MultiThreadedAverageValueStatistic(name); } else { stat = new SingleThreadedAverageValueStatistic(name); } stat.average = FloatValueStatistic.FindOrCreate(name, () => stat.GetAverageValue(), storage); #else stat = new AverageValueStatistic(name); #endif return(stat); }
public static LinearHistogramValueStatistic Create_LinearHistogram(StatisticName name, int numBuckets, double maximumValue) { var hist = new LinearHistogramValueStatistic(name.Name, numBuckets, maximumValue); StringValueStatistic.FindOrCreate(name, hist.PrintHistogram); return hist; }
private static CounterStatistic FindCounter(ConcurrentDictionary <string, CounterStatistic> counters, StatisticName name, CounterStorage storage) { CounterStatistic stat; if (counters.TryGetValue(name.Name, out stat)) { return(stat); } stat = CounterStatistic.FindOrCreate(name, storage); counters.TryAdd(name.Name, stat); return(stat); }
public void Counter_DecrementBy() { StatisticName name = new StatisticName(CounterName); int startValue = 10; int newValue = startValue - 1; CounterStatistic ctr = CounterStatistic.FindOrCreate(name); ctr.IncrementBy(startValue); Assert.AreEqual(startValue, ctr.GetCurrentValue()); ctr.DecrementBy(1); Assert.AreEqual(newValue, ctr.GetCurrentValue()); }
public static CounterStatistic FindOrCreate(StatisticName name, bool useDelta, CounterStorage storage, bool isHidden = false) { return(FindOrCreate_Impl(name, useDelta, storage, isHidden)); }
public static CounterStatistic FindOrCreate(StatisticName name) { return(FindOrCreate_Impl(name, true, CounterStorage.LogAndTable, false)); }
private static CounterStatistic FindCounter(ConcurrentDictionary<string, CounterStatistic> counters, StatisticName name, CounterStorage storage) { CounterStatistic stat; if (counters.TryGetValue(name.Name, out stat)) { return stat; } stat = CounterStatistic.FindOrCreate(name, storage); counters.TryAdd(name.Name, stat); return stat; }
internal SingleThreadedAverageValueStatistic(StatisticName name) : base(name) { totalSum = 0; numItems = 0; }
static public AverageValueStatistic FindOrCreate(StatisticName name, CounterStorage storage = CounterStorage.LogOnly) { return(FindOrCreate_Impl(name, storage, true)); }
protected AverageValueStatistic(StatisticName name) { Name = name.Name; }
internal MultiThreadedAverageValueStatistic(StatisticName name) : base(name) { totalSum = CounterStatistic.FindOrCreate(new StatisticName(String.Format("{0}.{1}", name.Name, "TotalSum.Hidden")), false, CounterStorage.DontStore); numItems = CounterStatistic.FindOrCreate(new StatisticName(String.Format("{0}.{1}", name.Name, "NumItems.Hidden")), false, CounterStorage.DontStore); }
static public AverageValueStatistic FindOrCreate(StatisticName name, CounterStorage storage = CounterStorage.LogOnly) { return FindOrCreate_Impl(name, storage, true); }
public static LinearHistogramValueStatistic Create_LinearHistogram_ForTiming(StatisticName name, int numBuckets, TimeSpan maximumValue) { var hist = new LinearHistogramValueStatistic(name.Name, numBuckets, maximumValue.Ticks); StringValueStatistic.FindOrCreate(name, hist.PrintHistogramInMillis); return hist; }
private void DeactivateActivationImpl(ActivationData data, StatisticName statisticName) { bool promptly = false; bool alreadBeingDestroyed = false; lock (data) { if (data.State == ActivationState.Valid) { // Change the ActivationData state here, since we're about to give up the lock. data.PrepareForDeactivation(); // Don't accept any new messages ActivationCollector.TryCancelCollection(data); if (!data.IsCurrentlyExecuting) { promptly = true; } else // busy, so destroy later. { data.AddOnInactive(() => DestroyActivationVoid(data)); } } else if (data.State == ActivationState.Create) { throw new InvalidOperationException(String.Format( "Activation {0} has called DeactivateOnIdle from within a constructor, which is not allowed.", data.ToString())); } else if (data.State == ActivationState.Activating) { throw new InvalidOperationException(String.Format( "Activation {0} has called DeactivateOnIdle from within OnActivateAsync, which is not allowed.", data.ToString())); } else { alreadBeingDestroyed = true; } } logger.Info(ErrorCode.Catalog_ShutdownActivations_2, "DeactivateActivationOnIdle: {0} {1}.", data.ToString(), promptly ? "promptly" : (alreadBeingDestroyed ? "already being destroyed or invalid" : "later when become idle")); CounterStatistic.FindOrCreate(statisticName).Increment(); if (promptly) { DestroyActivationVoid(data); // Don't await or Ignore, since we are in this activation context and it may have alraedy been destroyed! } }
public static ExponentialHistogramValueStatistic Create_ExponentialHistogram(StatisticName name, int numBuckets) { var hist = new ExponentialHistogramValueStatistic(name.Name, numBuckets); StringValueStatistic.FindOrCreate(name, hist.PrintHistogram); return hist; }
static public void Delete(StatisticName name) { FloatValueStatistic.Delete(name); }
public static FloatValueStatistic FindOrCreate(StatisticName name, Func <float> f) { return(FindOrCreate(name, f, CounterStorage.LogOnly)); }
public void Logger_Stats_MessageSizeLimit() { const string testName = "Logger_Stats_MessageSizeLimit"; TestLogConsumer logConsumer = new TestLogConsumer(); TraceLogger.LogConsumers.Add(logConsumer); TraceLogger logger1 = TraceLogger.GetLogger(testName); const string StatsCounterBaseName = "LoggerTest.Stats.Size"; for (int i = 1; i <= 1000; i++) { StatisticName counterName = new StatisticName(StatsCounterBaseName + "." + i); CounterStatistic ctr = CounterStatistic.FindOrCreate(counterName); ctr.IncrementBy(i); } LogStatistics statsLogger = new LogStatistics(TimeSpan.Zero, true); statsLogger.DumpCounters().Wait(); int count = logConsumer.GetEntryCount((int)ErrorCode.PerfCounterDumpAll); Console.WriteLine(count + " stats log message entries written"); Assert.IsTrue(count > 1, "Should be some stats log message entries - saw " + count); Assert.AreEqual(0, logConsumer.GetEntryCount((int)ErrorCode.Logger_LogMessageTruncated), "Should not see any 'Message truncated' message"); }