Example #1
0
        protected override void OnEventCommand(System.Diagnostics.Tracing.EventCommandEventArgs command)
        {
            if (command.Command == EventCommand.Enable)
            {
                if (_counters == null)
                {
                    // NOTE: These counters will NOT be disposed on disable command because we may be introducing
                    // a race condition by doing that. We still want to create these lazily so that we aren't adding
                    // overhead by at all times even when counters aren't enabled.
                    _counters = new EventCounter[] {
                        // TODO: process info counters

                        // GC info counters
                        new EventCounter("Total Memory by GC", this),
                        new EventCounter("Gen 0 GC Count", this),
                        new EventCounter("Gen 1 GC Count", this),
                        new EventCounter("Gen 2 GC Count", this),

                        new EventCounter("Exception Count", this)
                    };
                }


                // Initialize the timer, but don't set it to run.
                // The timer will be set to run each time PollForTracingCommand is called.

                // TODO: We should not need this timer once we are done settling upon a high-level design for
                // what EventCounter is capable of doing. Once that decision is made, we should be able to
                // get rid of this.
                if (_timer == null)
                {
                    _timer = new Timer(
                        callback: new TimerCallback(PollForCounterUpdate),
                        state: null,
                        dueTime: Timeout.Infinite,
                        period: Timeout.Infinite,
                        flowExecutionContext: false);
                }
                // Trigger the first poll operation on when this EventSource is enabled
                PollForCounterUpdate(null);
            }
            else if (command.Command == EventCommand.Disable)
            {
                if (_timer != null)
                {
                    _timer.Change(Timeout.Infinite, Timeout.Infinite);  // disable the timer from running until System.Runtime is re-enabled
                }
            }
        }
        protected override void OnEventCommand(System.Diagnostics.Tracing.EventCommandEventArgs command)
        {
            if (command.Command == EventCommand.Enable)
            {
                // NOTE: These counters will NOT be disposed on disable command because we may be introducing
                // a race condition by doing that. We still want to create these lazily so that we aren't adding
                // overhead by at all times even when counters aren't enabled.

                // On disable, PollingCounters will stop polling for values so it should be fine to leave them around.
                _gcHeapSizeCounter = _gcHeapSizeCounter ?? new PollingCounter("GC Heap Size", this, () => GC.GetTotalMemory(false));
                _gen0GCCounter     = _gen0GCCounter ?? new IncrementingPollingCounter("Gen 0 GC Count", this, () => GC.CollectionCount(0));
                _gen1GCCounter     = _gen1GCCounter ?? new IncrementingPollingCounter("Gen 1 GC Count", this, () => GC.CollectionCount(1));
                _gen2GCCounter     = _gen2GCCounter ?? new IncrementingPollingCounter("Gen 2 GC Count", this, () => GC.CollectionCount(2));
                _exceptionCounter  = _exceptionCounter ?? new IncrementingPollingCounter("Exception Count", this, () => Exception.GetExceptionCount());
            }
        }
Example #3
0
        protected override void OnEventCommand(System.Diagnostics.Tracing.EventCommandEventArgs command)
        {
            if (command.Command == EventCommand.Enable)
            {
                // NOTE: These counters will NOT be disposed on disable command because we may be introducing
                // a race condition by doing that. We still want to create these lazily so that we aren't adding
                // overhead by at all times even when counters aren't enabled.

                // On disable, PollingCounters will stop polling for values so it should be fine to leave them around.
                _cpuTimeCounter = _cpuTimeCounter ?? new PollingCounter("cpu-usage", this, () => RuntimeEventSourceHelper.GetCpuUsage())
                {
                    DisplayName = "CPU Usage"
                };
                _workingSetCounter = _workingSetCounter ?? new PollingCounter("working-set", this, () => (double)(Environment.WorkingSet / 1000000))
                {
                    DisplayName = "Working Set"
                };
                _gcHeapSizeCounter = _gcHeapSizeCounter ?? new PollingCounter("gc-heap-size", this, () => (double)(GC.GetTotalMemory(false) / 1000000))
                {
                    DisplayName = "GC Heap Size"
                };
                _gen0GCCounter = _gen0GCCounter ?? new IncrementingPollingCounter("gen-0-gc-count", this, () => GC.CollectionCount(0))
                {
                    DisplayName = "Gen 0 GC Count", DisplayRateTimeScale = new TimeSpan(0, 1, 0)
                };
                _gen1GCCounter = _gen1GCCounter ?? new IncrementingPollingCounter("gen-1-gc-count", this, () => GC.CollectionCount(1))
                {
                    DisplayName = "Gen 1 GC Count", DisplayRateTimeScale = new TimeSpan(0, 1, 0)
                };
                _gen2GCCounter = _gen2GCCounter ?? new IncrementingPollingCounter("gen-2-gc-count", this, () => GC.CollectionCount(2))
                {
                    DisplayName = "Gen 2 GC Count", DisplayRateTimeScale = new TimeSpan(0, 1, 0)
                };
                _exceptionCounter = _exceptionCounter ?? new IncrementingPollingCounter("exception-count", this, () => Exception.GetExceptionCount())
                {
                    DisplayName = "Exception Count", DisplayRateTimeScale = new TimeSpan(0, 0, 1)
                };
            }
        }
 protected override void OnEventCommand(System.Diagnostics.Tracing.EventCommandEventArgs command)
 {
 }
 protected virtual void OnEventCommand(System.Diagnostics.Tracing.EventCommandEventArgs command)
 {
 }