Пример #1
0
        protected override bool ReleaseHandle()
        {
            //Do not release individual counters to avoid possible race condition where one thread is disposing the counter instance while other thread
            //is incrementing the counter. All counter related resources are released in the counter object finalizer method.

            //Remove this perf-counter instance
            FabricPerformanceCounterInterop.DeleteCounterSetInstance(this.handle);
            return(true);
        }
        public FabricPerformanceCounter(IntPtr instanceHandle, int index) : base(IntPtr.Zero, true)
        {
            IntPtr counterHandle = Marshal.AllocHGlobal(sizeof(long));

            SetHandle(counterHandle);
            unsafe
            {
                *(long *)counterHandle = 0;
            }
            FabricPerformanceCounterInterop.SetCounterRefValue(instanceHandle, index, counterHandle);
        }
Пример #3
0
        public FabricPerformanceCounterSet(
            FabricPerformanceCounterSetDefinition setDefinition,
            IEnumerable <FabricPerformanceCounterDefinition> counters) : base(IntPtr.Zero, true)
        {
            CounterSetDefinition = setDefinition;
            CounterNameToId      = new Dictionary <string, int>();

            foreach (var ctr in counters)
            {
                CounterNameToId[ctr.Name] = ctr.Id;
            }
            CounterSetDefinitionPtr = FabricPerformanceCounterInterop.CreateCounterSet(CounterSetDefinition, counters);
            SetHandle(CounterSetDefinitionPtr);
        }
Пример #4
0
        internal FabricPerformanceCounterSetInstance(FabricPerformanceCounterSet counterSet, string instanceName) : base(IntPtr.Zero, true)
        {
            IntPtr counterInstancePtr = FabricPerformanceCounterInterop.CreateCounterSetInstance(counterSet.CounterSetDefinitionPtr, instanceName);

            SetHandle(counterInstancePtr);
            counterNameToCounter = new Dictionary <string, FabricPerformanceCounter>();

            foreach (var key in counterSet.CounterNameToId.Keys)
            {
                int id = counterSet.CounterNameToId[key];
                try
                {
                    //Get the reference of individual counters.
                    FabricPerformanceCounter perfCtr = new FabricPerformanceCounter(counterInstancePtr, id);
                    counterNameToCounter.Add(key, perfCtr);
                }
                catch
                {
                    //Dispose counter set instance.
                    Dispose();
                    throw;
                }
            }
        }
Пример #5
0
 protected override bool ReleaseHandle()
 {
     FabricPerformanceCounterInterop.DeleteCounterSet(this.handle);
     return(true);
 }