Esempio n. 1
0
        private static void Record(CrankArguments arguments)
        {
            var maxConnections = 0;

            foreach (var sample in _samples)
            {
                // metric simplified for reporting to reflect the counter name and machine where it was sampled
                var key     = String.Format("{0} ({1})", sample.Key.CounterName, ExpandMachineName(sample.Key.MachineName));
                var samples = sample.Value;

                var values = new long[samples.Count - 1];
                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = (long)Math.Round(CounterSample.Calculate(samples[i], samples[i + 1]));
                    Mark(arguments, (ulong)values[i], key);
                }

                if (key.StartsWith("Connections Connected"))
                {
                    maxConnections = (int)Math.Max(maxConnections, values.Max());
                }

                RecordAggregates(key, values);
            }
            Console.WriteLine("Max Connections Connected: " + maxConnections);
        }
Esempio n. 2
0
        public TimeSpan ExecuteProbe()
        {
            if (_perfCounter == null)
            {
                try
                {
                    if (!StartProbe(true))
                    {
                        return(ProbeFrequency);
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(_traceSource.Name + " " + ex.Message);
                    TraceEvent(TraceEventType.Critical, float.NaN, CategoryName + ": " + ex.Message);
                    return(ProbeFrequency);
                }
            }

            try
            {
                float value = 0;

                CounterSample curr = _perfCounter.NextSample();
                switch (_perfCounter.CounterType)
                {
                case PerformanceCounterType.NumberOfItemsHEX32:
                case PerformanceCounterType.NumberOfItemsHEX64:
                case PerformanceCounterType.NumberOfItems32:
                case PerformanceCounterType.NumberOfItems64:
                {
                    value = CounterSample.Calculate(curr);
                } break;

                default:
                {
                    value = CounterSample.Calculate(_prevSample.Value, curr);
                } break;
                }

                _prevSample = curr;

                TraceEvent(TraceEventType.Information, value, "Ok");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(_traceSource.Name + " " + ex.Message);

                try
                {
                    StartProbe(true);
                }
                catch (Exception startEx)
                {
                    System.Diagnostics.Trace.WriteLine(_traceSource.Name + " " + startEx.Message);
                    TraceEvent(TraceEventType.Critical, float.NaN, ex.Message); // Report initial exception
                }
            }
            return(ProbeFrequency);
        }
	//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
	//	PERF_COUNTER_COUNTER
	//	Description	 - This counter type shows the average number of operations completed
	//		during each second of the sample interval. Counters of this type
	//		measure time in ticks of the system clock. The F variable represents
	//		the number of ticks per second. The value of F is factored into the
	//		equation so that the result can be displayed in seconds.
	//
    //	Generic type - Difference
	//
	//	Formula - (N1 - N0) / ( (D1 - D0) / F), where the numerator (N) represents the number
	//		of operations performed during the last sample interval, the denominator
	//		(D) represents the number of ticks elapsed during the last sample
	//		interval, and F is the frequency of the ticks.
	//
	//	     Average - (Nx - N0) / ((Dx - D0) / F)
	//
	//       Example - System\ File Read Operations/sec
	//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
	private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
	{
		Single numerator = (Single)(s1.RawValue - s0.RawValue);
		Single denomenator = (Single)(s1.TimeStamp - s0.TimeStamp) / (Single)s1.SystemFrequency;
		Single counterValue = numerator / denomenator;
		return(counterValue);
	}
Esempio n. 4
0
 public static void Update()
 {
     if (pc != null)
     {
         int n = instance_names.Length;
         for (int i = 0; i < n; i++)
         {
             pc.InstanceName = instance_names[i];
             CounterSample newSample    = pc.NextSample();
             CounterSample oldSample    = counters[i];
             float         difference   = newSample.RawValue - oldSample.RawValue;
             float         timeInterval = newSample.TimeStamp100nSec - oldSample.TimeStamp100nSec;
             if (timeInterval != 0)
             {
                 float val = 100.0f * (1.0f - (difference / timeInterval));
                 if (val < 0)
                 {
                     val = 0;
                 }
                 if (val > 100.0f)
                 {
                     val = 100.0f;
                 }
                 values[i] = val;
             }
             counters[i] = newSample;
         }
     }
 }
Esempio n. 5
0
    public int GetCPUTotalUsage()
    {
        int num = 0;

        try
        {
            if (this.newValue.BaseValue == 0L)
            {
                this.newValue = Cpu_Counter.NextSample();
                return(0);
            }
            this.oldValue = this.newValue;
            this.newValue = Cpu_Counter.NextSample();
            float num2 = CounterSample.Calculate(this.oldValue, this.newValue);
            num = (int)num2;
            if (num2 * 10f % 10f >= 5f)
            {
                num = (int)num2 + 1;
            }
            if (num > 100)
            {
                num = 100;
            }
        }
        catch (Exception)
        {
            num = -1;
        }
        return(num);
    }
Esempio n. 6
0
            public Dictionary <string, float> Refresh(float minValue)
            {
                InstanceDataCollectionCollection allData = TryGetPerformanceData(() => this.category.ReadCategory(), out Exception ex);

                Dictionary <string, float> result = new Dictionary <string, float>(StringComparer.CurrentCultureIgnoreCase);

                if (allData != null)
                {
                    InstanceDataCollection processData = allData["% Processor Time"];
                    if (processData != null)
                    {
                        Dictionary <string, CounterSample> currentSamples = new Dictionary <string, CounterSample>();
                        foreach (InstanceData data in processData.Values)
                        {
                            string        instanceName  = data.InstanceName;
                            CounterSample currentSample = data.Sample;
                            currentSamples[instanceName] = currentSample;

                            if (this.previousSamples != null && this.previousSamples.TryGetValue(instanceName, out CounterSample previousSample))
                            {
                                // We have to average the usage across all the logical processors.
                                // On an 8 processor machine, the counter can return up to 800!
                                float value = CounterSampleCalculator.ComputeCounterValue(previousSample, currentSample) / ProcessorCount;
                                result[data.InstanceName] = value >= minValue ? value : float.NaN;
                            }
                        }

                        this.previousSamples = currentSamples;
                    }
                }

                return(result);
            }
Esempio n. 7
0
        protected void GenerarGraficoActividadDisco()
        {
            PerformanceCounter cpuCounter = new PerformanceCounter("PhysicalDisk", "% Disk Time", "_Total");
            CounterSample      cs1        = cpuCounter.NextSample();

            System.Threading.Thread.Sleep(100);
            CounterSample cs2 = cpuCounter.NextSample();
            double        PorcentajeUtilizado = Math.Round(CounterSample.Calculate(cs1, cs2), 2);
            double        PorcentajeLibre     = 100 - PorcentajeUtilizado;

            double[] yValues = { PorcentajeUtilizado, PorcentajeLibre };
            string[] xValues = { "Utilizado: " + PorcentajeUtilizado.ToString() + "%", "Disponible: " + PorcentajeLibre.ToString() + "%" };

            chartDiscoAc.Series["Default"].Points.DataBindXY(xValues, yValues);

            chartDiscoAc.Series["Default"].Points[0].Color = Color.DarkGoldenrod;
            chartDiscoAc.Series["Default"].Points[1].Color = Color.PaleGoldenrod;

            chartDiscoAc.Series["Default"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie;

            chartDiscoAc.Series["Default"]["PieLabelStyle"] = "Disabled";

            chartDiscoAc.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;

            chartDiscoAc.Legends[0].Enabled = false;
        }
        public sFlowDatagram(byte[] UDPDatagramBuffer)
        {
            DatagramVersion = UDPDatagramBuffer.ToUInt(0, 4);
            AgentAddress    = new IPAddress(UDPDatagramBuffer.AsSpan(8, 4).ToArray());
            SubAgentID      = UDPDatagramBuffer.ToUInt(12, 4);
            SequenceNumber  = UDPDatagramBuffer.ToUInt(16, 4);
            SystemUptimeMS  = UDPDatagramBuffer.ToUInt(20, 4);
            uint sampleCount = UDPDatagramBuffer.ToUInt(24, 4);

            Samples = new Sample[sampleCount];
            uint sampleIndex = 0;

            for (uint i = 0; i < sampleCount; i++)
            {
                Sample sample = new Sample(UDPDatagramBuffer.AsSpan((int)(HeaderLength + sampleIndex), (int)Sample.HeaderLengthBytes).ToArray());
                byte[] buffer = UDPDatagramBuffer.AsSpan((int)(HeaderLength + sampleIndex), (int)(sample.Length + Sample.StartIndexBytes)).ToArray();
                if (sample.Type == SampleType.Flow)
                {
                    Samples[i] = new FlowSample(buffer);
                }
                else if (sample.Type == SampleType.Counter)
                {
                    Samples[i] = new CounterSample(buffer);
                }
                sampleIndex += sample.Length + Sample.StartIndexBytes;
            }
        }
Esempio n. 9
0
        public Counter(PerformanceCounter performanceCounter, CounterSample lastSample)
        {
            PerformanceCounter = performanceCounter;
            samples            = new ConcurrentQueue <CounterSample>();

            samples.Enqueue(lastSample);
        }
Esempio n. 10
0
        public PerformanceInfo CheckParameters()
        {
            PerformanceInfo perfInfo = new PerformanceInfo();
            var             today    = DateTime.Now;

            PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            PerfomanceInfoData perfData   = PsApiWrapper.GetPerformanceInfo();

            CounterSample cs1 = cpuCounter.NextSample();

            System.Threading.Thread.Sleep(100);
            CounterSample cs2 = cpuCounter.NextSample();

            perfInfo.CpuPercentUsage = CounterSample.Calculate(cs1, cs2);

            perfInfo.CommitTotalPages    = perfData.CommitTotalPages;
            perfInfo.PageSizeMB          = Math.Round((double)perfData.PageSizeBytes / 1024 / 1024, 2, MidpointRounding.AwayFromZero);
            perfInfo.PhysicalAvailableMB = Math.Round((double)perfData.PhysicalAvailableBytes / 1024 / 1024, 2, MidpointRounding.AwayFromZero);
            perfInfo.PhysicalTotalMB     = Math.Round((double)perfData.PhysicalTotalBytes / 1024 / 1024, 2, MidpointRounding.AwayFromZero);
            perfInfo.ThreadCount         = perfData.ThreadCount;
            perfInfo.ProcessCount        = perfData.ProcessCount;
            perfInfo.Time = today.ToString("yyyy-MM-dd HH:mm:ss");
            logger.Info("Performance details chcecked succesfully");
            return(perfInfo);
        }
Esempio n. 11
0
 public float GetValue()
 {
     lock (_lockObject)
     {
         CounterSample currentSample = _perfCounter.NextSample();
         if (currentSample.SystemFrequency != 0)
         {
             // The recommended delay time between calls to the NextSample method is one second, to allow the counter to perform the next incremental read.
             float timeDifferenceSecs = (currentSample.TimeStamp - _nextSample.TimeStamp) / (float)currentSample.SystemFrequency;
             if (timeDifferenceSecs > 0.5F || timeDifferenceSecs < -0.5F)
             {
                 _prevSample = _nextSample;
                 _nextSample = currentSample;
                 if (_prevSample.Equals(CounterSample.Empty))
                 {
                     _prevSample = currentSample;
                 }
             }
         }
         else
         {
             _prevSample = _nextSample;
             _nextSample = currentSample;
         }
         float sampleValue = CounterSample.Calculate(_prevSample, currentSample);
         return(sampleValue);
     }
 }
Esempio n. 12
0
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    // Formula from MSDN -
    //      Description - This counter type shows the ratio of a subset to its set as a percentage.
    //			For example, it compares the number of bytes in use on a disk to the
    //			total number of bytes on the disk. Counters of this type display the
    //			current percentage only, not an average over time.
    //
    // Generic type - Instantaneous, Percentage
    //	    Formula - (N0 / D0), where D represents a measured attribute and N represents one
    //			component of that attribute.
    //
    //		Average - SUM (N / D) /x
    //		Example - Paging File\% Usage Peak
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    private static Single MyComputeCounterValue(CounterSample rfSample)
    {
        Single numerator    = (Single)rfSample.RawValue;
        Single denomenator  = (Single)rfSample.BaseValue;
        Single counterValue = (numerator / denomenator) * 100;

        return(counterValue);
    }
Esempio n. 13
0
        public CounterData(CounterKey key, Color color)
        {
            Key             = key;
            Color           = color;
            _previousSample = CounterSample.Empty;

            Id = Interlocked.Increment(ref _globalId);
        }
Esempio n. 14
0
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    //    Description - This counter type shows how many items are processed, on average,
    //        during an operation. Counters of this type display a ratio of the items
    //        processed (such as bytes sent) to the number of operations completed. The
    //        ratio is calculated by comparing the number of items processed during the
    //        last interval to the number of operations completed during the last interval.
    // Generic type - Average
    //      Formula - (N1 - N0) / (D1 - D0), where the numerator (N) represents the number
    //        of items processed during the last sample interval and the denominator (D)
    //        represents the number of operations completed during the last two sample
    //        intervals.
    //    Average (Nx - N0) / (Dx - D0)
    //    Example PhysicalDisk\ Avg. Disk Bytes/Transfer
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
    {
        Single numerator    = (Single)s1.RawValue - (Single)s0.RawValue;
        Single denomenator  = (Single)s1.BaseValue - (Single)s0.BaseValue;
        Single counterValue = numerator / denomenator;

        return(counterValue);
    }
Esempio n. 15
0
        internal float Sample(string counterName)
        {
            PerfData perfData = _counters[counterName];

            return(perfData != null
                       ? CounterSample.Calculate(perfData.Samples[0], perfData.Counter.NextSample())
                       : 0);
        }
        /// <summary>
        /// Create a new performance counter metric by sampling the provided performance counter object.
        /// </summary>
        /// <remarks>
        /// The counter packet provided must match the performance counter object.  The counter packet is used
        /// to provide clients with all of the information necessary to process performance metrics without using
        /// the performance counter infrastructure.
        /// </remarks>
        /// <param name="counter">The windows performance counter to sample</param>
        /// <param name="metric">The corresponding performance counter metric</param>
        public PerfCounterMetricSamplePacket(PerformanceCounter counter, PerfCounterMetric metric)
            : base(metric)
        {
            //we ask the perf counter for a value right now
            m_Sample = counter.NextSample();

            //and we have to stuff a few things into our base object so it knows what we're talking about
            RawValue = m_Sample.RawValue;
        }
Esempio n. 17
0
 public MemoryMeter()
 {
     if (SetupCategory())
     {
         return;
     }
     _cnt         = new PerformanceCounter("Memory", "Available MBytes");
     _startSample = _cnt.NextSample();
 }
        public float GetDiskTime()
        {
            CounterSample d1 = diskTime.NextSample();

            System.Threading.Thread.Sleep(1000);
            CounterSample d2 = diskTime.NextSample();

            return(CounterSample.Calculate(d1, d2));
        }
        // example : https://www.andygup.net/a-better-way-to-measure-cpu-using-windows-performancecounter-and-c/
        public float GetCpuTotal()
        {
            CounterSample c1 = cpuTotal.NextSample();

            System.Threading.Thread.Sleep(1000);
            CounterSample c2 = cpuTotal.NextSample();

            return(CounterSample.Calculate(c1, c2));
        }
        public float GetMemoryTotal()
        {
            CounterSample m1 = memoryTotal.NextSample();

            System.Threading.Thread.Sleep(1000);
            CounterSample m2 = memoryTotal.NextSample();

            return(CounterSample.Calculate(m1, m2));
        }
Esempio n. 21
0
    public static void Main()
    {
// <Snippet1>
        PerformanceCounter myPerformanceCounter1 = new PerformanceCounter
                                                       ("Processor", "% Processor Time", "0");
        CounterSample myCounterSample1 = new CounterSample(10L, 20L, 30L, 40L, 50L, 60L,
                                                           PerformanceCounterType.AverageCount64);

        Console.WriteLine("CounterTimeStamp = " + myCounterSample1.CounterTimeStamp);

        Console.WriteLine("BaseValue = " + myCounterSample1.BaseValue);
        Console.WriteLine("RawValue = " + myCounterSample1.RawValue);
        Console.WriteLine("CounterFrequency = " + myCounterSample1.CounterFrequency);
        Console.WriteLine("SystemFrequency = " + myCounterSample1.SystemFrequency);
        Console.WriteLine("TimeStamp = " + myCounterSample1.TimeStamp);
        Console.WriteLine("TimeStamp100nSec = " + myCounterSample1.TimeStamp100nSec);
        Console.WriteLine("CounterType = " + myCounterSample1.CounterType);
        // Hold the results of sample.
        myCounterSample1 = myPerformanceCounter1.NextSample();
        Console.WriteLine("BaseValue = " + myCounterSample1.BaseValue);
        Console.WriteLine("RawValue = " + myCounterSample1.RawValue);
        Console.WriteLine("CounterFrequency = " + myCounterSample1.CounterFrequency);
        Console.WriteLine("SystemFrequency = " + myCounterSample1.SystemFrequency);
        Console.WriteLine("TimeStamp = " + myCounterSample1.TimeStamp);
        Console.WriteLine("TimeStamp100nSec = " + myCounterSample1.TimeStamp100nSec);
        Console.WriteLine("CounterType = " + myCounterSample1.CounterType);
// </Snippet1>
        Console.WriteLine("");
        Console.WriteLine("");
// <Snippet2>
        PerformanceCounter myPerformanceCounter2 = new PerformanceCounter
                                                       ("Processor", "% Processor Time", "0");
        CounterSample myCounterSample2 = new CounterSample(10L, 20L, 30L, 40L, 50L, 60L,
                                                           PerformanceCounterType.AverageCount64, 300);

        Console.WriteLine("CounterTimeStamp = " + myCounterSample2.CounterTimeStamp);
        Console.WriteLine("BaseValue = " + myCounterSample2.BaseValue);
        Console.WriteLine("RawValue = " + myCounterSample2.RawValue);
        Console.WriteLine("CounterFrequency = " + myCounterSample2.CounterFrequency);
        Console.WriteLine("SystemFrequency = " + myCounterSample2.SystemFrequency);
        Console.WriteLine("TimeStamp = " + myCounterSample2.TimeStamp);
        Console.WriteLine("TimeStamp100nSec = " + myCounterSample2.TimeStamp100nSec);
        Console.WriteLine("CounterType = " + myCounterSample2.CounterType);
        Console.WriteLine("CounterTimeStamp = " + myCounterSample2.CounterTimeStamp);
        // Hold the results of sample.
        myCounterSample2 = myPerformanceCounter2.NextSample();
        Console.WriteLine("BaseValue = " + myCounterSample2.BaseValue);
        Console.WriteLine("RawValue = " + myCounterSample2.RawValue);
        Console.WriteLine("CounterFrequency = " + myCounterSample2.CounterFrequency);
        Console.WriteLine("SystemFrequency = " + myCounterSample2.SystemFrequency);
        Console.WriteLine("TimeStamp = " + myCounterSample2.TimeStamp);
        Console.WriteLine("TimeStamp100nSec = " + myCounterSample2.TimeStamp100nSec);
        Console.WriteLine("CounterType = " + myCounterSample2.CounterType);
        Console.WriteLine("CounterTimeStamp = " + myCounterSample2.CounterTimeStamp);
// </Snippet2>
    }
Esempio n. 22
0
        public static float GetCurrentCpuPercentage()
        {
            var           cpuCounter        = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            CounterSample cpuCounterSample1 = cpuCounter.NextSample();

            System.Threading.Thread.Sleep(500);
            CounterSample cpuCounterSample2 = cpuCounter.NextSample();

            return(CounterSample.Calculate(cpuCounterSample1, cpuCounterSample2));
        }
Esempio n. 23
0
 public bool Equals(CounterSample sample)
 {
     return((_rawValue == sample._rawValue) &&
            (_baseValue == sample._baseValue) &&
            (_timeStamp == sample._timeStamp) &&
            (_counterFrequency == sample._counterFrequency) &&
            (_counterType == sample._counterType) &&
            (_timeStamp100nSec == sample._timeStamp100nSec) &&
            (_systemFrequency == sample._systemFrequency) &&
            (_counterTimeStamp == sample._counterTimeStamp));
 }
Esempio n. 24
0
        private void GetCPUStatus()
        {
            PerformanceCounter theCPUCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            CounterSample      cs1           = theCPUCounter.NextSample();

            Thread.Sleep(100);
            CounterSample cs2 = theCPUCounter.NextSample();

            this.TotalCpuUsage       = CounterSample.Calculate(cs1, cs2);
            this.TotalProcessorCount = Environment.ProcessorCount;
        }
Esempio n. 25
0
        //calculates the global cpu usage with the performanceCounterCPU
        void getCpuUsage()
        {
            CounterSample cs1 = performanceCounterCPU.NextSample();

            System.Threading.Thread.Sleep(100);
            CounterSample cs2      = performanceCounterCPU.NextSample();
            float         cpuUsage = CounterSample.Calculate(cs1, cs2);

            cpuUsage = (cpuUsage < 1.00f) ? 1.00f : cpuUsage;
            CpuUsageValueLabel.Text = string.Format("{0:#,###.##} %", cpuUsage);
        }
Esempio n. 26
0
        public static void InstanceData_CreateInstanceData_FromCounterSample()
        {
            long          timestamp = DateTime.Now.ToFileTime();
            CounterSample cs        = new CounterSample(1, 2, 3, 4, timestamp, timestamp, PerformanceCounterType.SampleFraction);

            InstanceData id = new InstanceData("foo", cs);

            Assert.Equal(cs.RawValue, id.Sample.RawValue);
            Assert.Equal(cs.CounterType, id.Sample.CounterType);
            Assert.Equal(1, id.RawValue);
        }
Esempio n. 27
0
 /// <inheritdoc />
 protected override void CloseLayoutRenderer()
 {
     base.CloseLayoutRenderer();
     if (_perfCounter != null)
     {
         _perfCounter.Close();
         _perfCounter = null;
     }
     _prevSample = CounterSample.Empty;
     _nextSample = CounterSample.Empty;
 }
        /// <summary>
        /// 获取性能计数器下一个采样
        /// </summary>
        /// <returns></returns>
        public CounterSample NextSample()
        {
            CounterSample sample = new CounterSample();

            if (this.counter != null)
            {
                sample = this.counter.NextSample();
            }

            return(sample);
        }
Esempio n. 29
0
        public static Double Calculate(CounterSample oldSample, CounterSample newSample)
        {
            double difference   = newSample.RawValue - oldSample.RawValue;
            double timeInterval = newSample.TimeStamp100nSec - oldSample.TimeStamp100nSec;

            if (timeInterval != 0)
            {
                return(100 * (1 - (difference / timeInterval)));
            }
            return(0);
        }
Esempio n. 30
0
        public void Display()
        {
            PerformanceCounter theCPUCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            CounterSample      cs1           = theCPUCounter.NextSample();

            Thread.Sleep(100);
            CounterSample cs2             = theCPUCounter.NextSample();
            float         finalCpuCounter = CounterSample.Calculate(cs1, cs2);

            Console.WriteLine("Total Cpu Usage:" + finalCpuCounter);
        }
 // may throw InvalidOperationException, Win32Exception
 public CounterSample NextSample() {
     CounterSample sample;
     if (changed)
         UpdateInfo();
     GetSample(impl, false, out sample);
     valid_old = true;
     old_sample = sample;
     return sample;
 }
	// Constructor.
	public InstanceData(String instanceName, CounterSample sample)
			{
				this.instanceName = instanceName;
				this.sample = sample;
			}
	public static float ComputeCounterValue(CounterSample oldSample, CounterSample newSample) {}
 static extern bool GetSample(IntPtr impl, bool only_value, out CounterSample sample);
	public static float ComputeCounterValue(CounterSample oldSample,
											CounterSample newSample)
			{
				throw new NotImplementedException();
			}
	// Constructors
	public InstanceData(string instanceName, CounterSample sample) {}
Esempio n. 37
0
 private static void OutputSample(CounterSample s)
 {
     Console.WriteLine("\r\n+++++++++++");
     Console.WriteLine("Sample values - \r\n");
     Console.WriteLine("   BaseValue        = " + s.BaseValue);
     Console.WriteLine("   CounterFrequency = " + s.CounterFrequency);
     Console.WriteLine("   CounterTimeStamp = " + s.CounterTimeStamp);
     Console.WriteLine("   CounterType      = " + s.CounterType);
     Console.WriteLine("   RawValue         = " + s.RawValue);
     Console.WriteLine("   SystemFrequency  = " + s.SystemFrequency);
     Console.WriteLine("   TimeStamp        = " + s.TimeStamp);
     Console.WriteLine("   TimeStamp100nSec = " + s.TimeStamp100nSec);
     Console.WriteLine("++++++++++++++++++++++");
 }
 // may throw InvalidOperationException, Win32Exception
 public float NextValue() {
     CounterSample sample;
     if (changed)
         UpdateInfo();
     GetSample(impl, false, out sample);
     float val;
     if (valid_old)
         val = CounterSampleCalculator.ComputeCounterValue(old_sample, sample);
     else
         val = CounterSampleCalculator.ComputeCounterValue(sample);
     valid_old = true;
     old_sample = sample;
     return val;
 }
 public static float ComputeCounterValue(CounterSample newSample) {
     switch (newSample.CounterType) {
         case PerformanceCounterType.RawFraction:
         case PerformanceCounterType.NumberOfItems32:
         case PerformanceCounterType.NumberOfItemsHEX32:
         case PerformanceCounterType.NumberOfItems64:
         case PerformanceCounterType.NumberOfItemsHEX64:
             return (float)newSample.RawValue;
         default:
             return 0;
     }
 }
 public static float ComputeCounterValue(CounterSample oldSample,
     CounterSample newSample) {
     if (newSample.CounterType != oldSample.CounterType)
         throw new Exception("The counter samples must be of the same type");
     switch (newSample.CounterType) {
         case PerformanceCounterType.RawFraction:
         case PerformanceCounterType.NumberOfItems32:
         case PerformanceCounterType.NumberOfItemsHEX32:
         case PerformanceCounterType.NumberOfItems64:
         case PerformanceCounterType.NumberOfItemsHEX64:
             return (float)newSample.RawValue;
         case PerformanceCounterType.AverageCount64:
             return (float)(newSample.RawValue - oldSample.RawValue) / (float)(newSample.BaseValue - oldSample.BaseValue);
         case PerformanceCounterType.AverageTimer32:
             return (((float)(newSample.RawValue - oldSample.RawValue)) / newSample.SystemFrequency) / (float)(newSample.BaseValue - oldSample.BaseValue);
         case PerformanceCounterType.CounterDelta32:
         case PerformanceCounterType.CounterDelta64:
             return (float)(newSample.RawValue - oldSample.RawValue);
         case PerformanceCounterType.CounterMultiTimer:
             return ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp - oldSample.TimeStamp) * 100.0f / newSample.BaseValue;
         case PerformanceCounterType.CounterMultiTimer100Ns:
             return ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp100nSec - oldSample.TimeStamp100nSec) * 100.0f / newSample.BaseValue;
         case PerformanceCounterType.CounterMultiTimerInverse:
             return (newSample.BaseValue - ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp - oldSample.TimeStamp)) * 100.0f;
         case PerformanceCounterType.CounterMultiTimer100NsInverse:
             return (newSample.BaseValue - ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp100nSec - oldSample.TimeStamp100nSec)) * 100.0f;
         case PerformanceCounterType.CounterTimer:
         case PerformanceCounterType.CountPerTimeInterval32:
         case PerformanceCounterType.CountPerTimeInterval64:
             return ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp - oldSample.TimeStamp);
         case PerformanceCounterType.CounterTimerInverse:
             return (1.0f - ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp100nSec - oldSample.TimeStamp100nSec)) * 100.0f;
         case PerformanceCounterType.ElapsedTime:
             // FIXME
             return 0;
         case PerformanceCounterType.Timer100Ns:
             return ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp - oldSample.TimeStamp) * 100.0f;
         case PerformanceCounterType.Timer100NsInverse:
             return (1f - ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp - oldSample.TimeStamp)) * 100.0f;
         case PerformanceCounterType.RateOfCountsPerSecond32:
         case PerformanceCounterType.RateOfCountsPerSecond64:
             return ((float)(newSample.RawValue - oldSample.RawValue)) / (float)(newSample.TimeStamp - oldSample.TimeStamp) * 10000000;
         default:
             Console.WriteLine("Counter type {0} not handled", newSample.CounterType);
             return 0;
     }
 }
 public bool Equals(CounterSample sample);
 public static float Calculate(CounterSample counterSample, CounterSample nextCounterSample);
Esempio n. 43
0
		public static float Calculate (CounterSample counterSample,
			CounterSample nextCounterSample)
		{
			return CounterSampleCalculator.ComputeCounterValue (counterSample, nextCounterSample);
		}
Esempio n. 44
0
 //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
 //    Description - This counter type shows how many items are processed, on average,
 //        during an operation. Counters of this type display a ratio of the items
 //        processed (such as bytes sent) to the number of operations completed. The
 //        ratio is calculated by comparing the number of items processed during the
 //        last interval to the number of operations completed during the last interval.
 // Generic type - Average
 //  	Formula - (N1 - N0) / (D1 - D0), where the numerator (N) represents the number
 //        of items processed during the last sample interval and the denominator (D)
 //        represents the number of operations completed during the last two sample
 //        intervals.
 //    Average (Nx - N0) / (Dx - D0)
 //    Example PhysicalDisk\ Avg. Disk Bytes/Transfer
 //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
 private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
 {
     Single numerator = (Single)s1.RawValue - (Single)s0.RawValue;
     Single denomenator = (Single)s1.BaseValue - (Single)s0.BaseValue;
     Single counterValue = numerator / denomenator;
     return (counterValue);
 }
	// Methods
	public static float Calculate(CounterSample counterSample) {}
Esempio n. 46
0
		public bool Equals (CounterSample other)
		{
			return
				rawValue == other.rawValue &&
				baseValue == other.counterFrequency &&
				counterFrequency == other.counterFrequency &&
				systemFrequency == other.systemFrequency &&
				timeStamp == other.timeStamp &&
				timeStamp100nSec == other.timeStamp100nSec &&
				counterTimeStamp == other.counterTimeStamp &&
				counterType == other.counterType;
		}
	public static bool op_Inequality(CounterSample a, CounterSample b) {}