Increment() публичный Метод

public Increment ( ) : long
Результат long
Пример #1
0
        static void Main(string[] args)
        {
            if (CreatePerformanecCounters())
            {
                Console.WriteLine("Created performance counters");
                Console.WriteLine("Please restart the application");
                Console.ReadKey();

                return;
            }

            var totalOperationsCounter = new PerformanceCounter(
                "MyCategory",
                "# operations executed",
                "",
                false);
            var operationsPerSecondCounter = new PerformanceCounter(
                "MyCategory",
                "# operations sec",
                "",
                false);

            totalOperationsCounter.Increment();
            operationsPerSecondCounter.Increment();
        }
Пример #2
0
 protected void IncreaseCounter(object sender, EventArgs e)
 {
     using (var counter = new PerformanceCounter("Test Category", "Test Increment", readOnly: false))
     {
         counter.Increment();
     }
 }
Пример #3
0
        protected void Listener()
        {
            try
            {
                listener = new TcpListener(port);
                listener.Start();
                while (true)
                {
                    Socket          socket  = listener.AcceptSocket();
                    string          message = GetRandomQuoteOfTheDay();
                    UnicodeEncoding encoder = new UnicodeEncoding();
                    byte[]          buffer  = encoder.GetBytes(message);
                    socket.Send(buffer, buffer.Length, 0);
                    socket.Close();

                    performanceCounterRequestsTotal.Increment();
                    performanceCounterBytesSentTotal.IncrementBy(buffer.Length);
                    requestsPerSec++;
                    bytesPerSec += buffer.Length;
                }
            }
            catch (SocketException e)
            {
                string message = "Quote Server Exception in Listener: " +
                                 e.Message;
                eventLog.WriteEntry(e.Message, EventLogEntryType.Error);
            }
        }
 private void UpdateCounterConditional(PerformanceCounter c, CounterInvokeDirection expectedDirection)
 {
     if (c != null && (expectedDirection & _direction) == expectedDirection)
     {
         lock (c)
         {
             //reset name
             string ins = c.InstanceName;
             c.Increment();
             //also update overall insance!
             c.InstanceName = OverallInstance;
             c.Increment();
             c.InstanceName = ins;
         }
     }
 }
        private void btnCount_Click(object sender, RoutedEventArgs e)
        {
            if(!PerformanceCounterCategory.Exists("PerfApp"))
            {
                PerformanceCounterCategory.Create("PerfApp", "Conters for app", PerformanceCounterCategoryType.SingleInstance, "Clicks", "Times the user has clicked the button");
            }

            PerformanceCounter pc = new PerformanceCounter("PerfApp", "Clicks", false);
            pc.Increment();
            txbCounter.Content = pc.NextValue().ToString();
        }
		public void WriteCounters ()
		{
			using (var hitCounter = new PerformanceCounter ("Category", "Hits")) {
				using (var rateCounter = new PerformanceCounter ("Category", "Rate")) {
					for (var x = 0; x < 5; x++) {
						hitCounter.Increment ();
						rateCounter.IncrementBy (x + 10);
					}
				}
			}
		}
Пример #7
0
 public static void Increment()
 {
     if (_exists)
     {
         using (var counter = new PerformanceCounter(_category, _counter, false)
                                  {
                                      MachineName = "."
                                  })
         {
             counter.Increment();
         }
     }
 }
Пример #8
0
        static void IncrementCounter()
        {
            // get an instance of our perf counter
            PerformanceCounter counter = new PerformanceCounter();
            counter.CategoryName = "MyCategory";
            counter.CounterName = "AddCounter";
            counter.ReadOnly = false;

            // increment and close the perf counter
            counter.Increment();

            counter.Close();
        }
Пример #9
0
        public override void Run()
        {
            while (true)
            {
                using (var counter = new PerformanceCounter("category", "counter1", false))
                {
                    counter.Increment();
                }

                EventLog.WriteEntry("source", "running");

                Thread.Sleep(1000);
            }
        }
		public SaveMetrics()
		{
			if (!PerformanceCounterCategory.Exists(PerformanceCategoryName))
			{
				var counters = new CounterCreationDataCollection
				{
					new CounterCreationData(
						//
						"Save - Count", "Number of world saves.", PerformanceCounterType.NumberOfItems32),
					new CounterCreationData(
						//
						"Save - Items/sec", "Number of items saved per second.", PerformanceCounterType.RateOfCountsPerSecond32),
					new CounterCreationData(
						//
						"Save - Mobiles/sec", "Number of mobiles saved per second.", PerformanceCounterType.RateOfCountsPerSecond32),
					new CounterCreationData(
						//
						"Save - Customs/sec", "Number of cores saved per second.", PerformanceCounterType.RateOfCountsPerSecond32),
					new CounterCreationData(
						//
						"Save - Serialized bytes/sec",
						"Amount of world-save bytes serialized per second.",
						PerformanceCounterType.RateOfCountsPerSecond32),
					new CounterCreationData(
						//
						"Save - Written bytes/sec",
						"Amount of world-save bytes written to disk per second.",
						PerformanceCounterType.RateOfCountsPerSecond32)
				};

#if !MONO
				PerformanceCounterCategory.Create(
					PerformanceCategoryName, PerformanceCategoryDesc, PerformanceCounterCategoryType.SingleInstance, counters);
#endif
			}

			numberOfWorldSaves = new PerformanceCounter(PerformanceCategoryName, "Save - Count", false);

			itemsPerSecond = new PerformanceCounter(PerformanceCategoryName, "Save - Items/sec", false);
			mobilesPerSecond = new PerformanceCounter(PerformanceCategoryName, "Save - Mobiles/sec", false);
			dataPerSecond = new PerformanceCounter(PerformanceCategoryName, "Save - Customs/sec", false);

			serializedBytesPerSecond = new PerformanceCounter(PerformanceCategoryName, "Save - Serialized bytes/sec", false);
			writtenBytesPerSecond = new PerformanceCounter(PerformanceCategoryName, "Save - Written bytes/sec", false);

			// increment number of world saves
			numberOfWorldSaves.Increment();
		}
Пример #11
0
        /// <summary>
        /// Stops counting time (Happens at the end of the request)
        /// </summary>
        public void Stop()
        {
            _Stopwatch.Stop();

            if (_OperationsPerSecond != null)
            {
                _OperationsPerSecond.Increment();
            }

            if (_AverageDuration != null & _AverageDurationBase != null)
            {
                var elapsedTicks = _Stopwatch.ElapsedTicks;
                _AverageDuration.IncrementBy(elapsedTicks);
                _AverageDurationBase.Increment();
            }
        }
Пример #12
0
        static void Main(string[] args)
        {
            CounterCreationDataCollection counters = new CounterCreationDataCollection();
            counters.Add(new CounterCreationData("Sales", "Number of total sales", PerformanceCounterType.NumberOfItems64));
            counters.Add(new CounterCreationData("Active Users", "Number of active users", PerformanceCounterType.NumberOfItems64));
            counters.Add(new CounterCreationData("Sales value", "Total value of all sales", PerformanceCounterType.NumberOfItems64));
            PerformanceCounterCategory.Create("MyApp Counters", "Counters describing the performance of MyApp",
                PerformanceCounterCategoryType.SingleInstance, counters);

            PerformanceCounter pc = new PerformanceCounter("MyApp Counters", "Sales", false);

            pc.RawValue = 7;
            pc.Decrement();
            pc.Increment();
            pc.IncrementBy(3);
        }
Пример #13
0
        //
        // http://msdn.microsoft.com/en-us/library/5e3s61wf(v=vs.90).aspx
        //
        private static void Sample_CreatingPerformanceCounter()
        {
            var performanceMonitor = new PerformanceMonitor();
            performanceMonitor.AddCounter("CustomInstance");
            using (var counter = new PerformanceCounter(PerformanceMonitor.pcCategory, "CustomInstance", readOnly: false))
            {
                string command;
                do
                {
                    counter.Increment();
                    Console.Write("enter command: ");
                    command = Console.ReadLine();
                } while (command != "");
            }

            Console.WriteLine("press any key...");
            Console.ReadKey();
        }
        private static void IncrementUnhandledExceptions()
        {
            try
            {
                string performanceCounterCategory = Assembly.GetEntryAssembly().GetName().Name;
                string performanceCounterName = "UnhandledExceptions";

                PerformanceCounter counter = new PerformanceCounter();
                counter.CategoryName = performanceCounterCategory;
                counter.CounterName = performanceCounterName;
                counter.ReadOnly = false;
                counter.Increment();
                counter.Close();
            }
            catch (Exception)
            {
                return;
            }
        }
Пример #15
0
        //============================================================================== Performance counter API

        internal bool Increment()
        {
            if (!this.Accessible)
            {
                return(false);
            }

            try
            {
                _counter.Increment();
            }
            catch (Exception ex)
            {
                LogException(ex);
                return(false);
            }

            return(true);
        }
Пример #16
0
        public static void Main(string[] args)
        {
            if (CreatePerformanceCounters())
            {
                Console.WriteLine("Created performance counters");
                Console.WriteLine("Please restart application");
                Console.ReadKey();
                return;
            }

            var totalOperationsCounter = new PerformanceCounter("MyCategory", "# operations executed", "", false);
            var operationsPerSecondCounter = new PerformanceCounter("MyCategory", "# operations / sec", "", false);

            totalOperationsCounter.Increment();
            operationsPerSecondCounter.Increment();

            Console.WriteLine("Total number of operations: {0}", totalOperationsCounter.RawValue);
            Console.WriteLine("Operations / sec: {0}", operationsPerSecondCounter.RawValue);

            Console.ReadLine();
        }
        public void StopCounter()
        {
            this.stopWatch.Stop();

            using (
                var averageExecutionTimeCounter = new PerformanceCounter(Category, 
                                                                         AverageExecutionTimeCounterName, 
                                                                         this.instanceName, 
                                                                         false))
            {
                using (
                    var averageExecutionTimeBaseCounter = new PerformanceCounter(Category, 
                                                                                 AverageExecutionTimeBaseCounterName, 
                                                                                 this.instanceName, 
                                                                                 false))
                {
                    averageExecutionTimeCounter.IncrementBy(this.stopWatch.ElapsedTicks);
                    averageExecutionTimeBaseCounter.Increment();
                }
            }
        }
 //public static void CountBeginAverageTimerCounter
 //                        (
 //                            this PerformanceCounter performanceCounter
 //                            , PerformanceCounter basePerformanceCounter
 //                            , Stopwatch stopwatch
 //                        )
 //{
 //        //stopwatch.Reset();
 //        //stopwatch.Start();
 //        stopwatch.Restart();
 //}
 public static void CountEndAverageTimerCounter
                 (
                     this PerformanceCounter performanceCounter
                     , PerformanceCounter basePerformanceCounter
                     , Stopwatch stopwatch
                     , Func<PerformanceCounterProcessingFlagsType, PerformanceCounter, long> onBasePerformanceCounterChangeValueProcessFunc = null
                 )
 {
     if
         (
             stopwatch != null
         )
     {
         if (stopwatch.IsRunning)
         {
             stopwatch.Stop();
         }
         performanceCounter
                 .IncrementBy(stopwatch.ElapsedTicks);
         //stopwatch = null;
         var increment = 1L;
         if (onBasePerformanceCounterChangeValueProcessFunc != null)
         {
             increment = onBasePerformanceCounterChangeValueProcessFunc
                                 (
                                     PerformanceCounterProcessingFlagsType.TimeBasedOnEnd
                                     , basePerformanceCounter
                                 );
         }
         if (increment == 1)
         {
             basePerformanceCounter.Increment();
         }
         else
         {
             basePerformanceCounter.IncrementBy(increment);
         }
         
     }
 }
Пример #19
0
        public void PerformanceCounterTest()
        {
            // Delete the Performance Counter Category, if already exists
            if (PerformanceCounterCategory.Exists("SalesDistribution"))
                PerformanceCounterCategory.Delete("SalesDistribution");

            // Prepare for creation of the Performance Counter
            CounterCreationDataCollection counterCollection =
                new CounterCreationDataCollection();

            //Create the CounterCreationData
            CounterCreationData counterData = new CounterCreationData();
            counterData.CounterName = "RequestsPerSec";
            counterData.CounterType = PerformanceCounterType.NumberOfItems32;
            counterData.CounterHelp = "Requests Received per Second";
            counterCollection.Add(counterData);

            // Create the performance counter category
            PerformanceCounterCategory.Create("SalesDistribution",
                "Automated Sales Distribution System",
                PerformanceCounterCategoryType.SingleInstance, counterCollection);

            // Retrieve the performance counter for updation
            PerformanceCounter performanceCount =
                new PerformanceCounter("SalesDistribution", "RequestsPerSec", false);

            int x = 1;
            while (x <= 50)
            {
                Console.WriteLine("RequestsPerSec = {0}", performanceCount.RawValue);

                // Increment the performance counter
                performanceCount.Increment();
                System.Threading.Thread.Sleep(250);
                x = (x + 1);
            }

            // Close the performance counter
            performanceCount.Close();
        }
Пример #20
0
#pragma warning restore 649

		public static void Increment(PerformanceCounter counter)
		{
			if (counter != null)
				counter.Increment();
		}
Пример #21
0
		void PerformanceCountersEndRequest()
		{
			try
			{
			if (HttpContext.Current.Items["DsiPage"] != null)
			{
				if (PerformanceCounterCategory.Exists("DontStayIn"))
				{
					PerformanceCounter DsiPages = new PerformanceCounter();
					DsiPages.CategoryName = "DontStayIn";
					DsiPages.CounterName = "DsiPages per sec";
					DsiPages.MachineName = ".";
					DsiPages.ReadOnly = false;

					PerformanceCounter GenTime = new PerformanceCounter();
					GenTime.CategoryName = "DontStayIn";
					GenTime.CounterName = "DsiPage generation time";
					GenTime.MachineName = ".";
					GenTime.ReadOnly = false;

					PerformanceCounter GenTimeBase = new PerformanceCounter();
					GenTimeBase.CategoryName = "DontStayIn";
					GenTimeBase.CounterName = "DsiPage generation time base";
					GenTimeBase.MachineName = ".";
					GenTimeBase.ReadOnly = false;

					DsiPages.Increment();
					long ticksStart = (long)HttpContext.Current.Items["ApplicationStartTicks"];
					long ticksEnd = 0;
					QueryPerformanceCounter(ref ticksEnd);
					GenTime.IncrementBy(ticksEnd - ticksStart);
					GenTimeBase.Increment();
				}

			}
		}
			catch { }
		}
Пример #22
0
        private static void setupAndIncrement(PerformanceCounter counter, string counterName, long? value = null)
        {
            if (Diagnostics.CassandraPerformanceCountersEnabled)
            {
                if (counter == null)
                    counter = SetupCounter(CassandraCountersCategory, counterName);

                if (counter != null && CategoryReady)
                    if (value != null)
                        counter.IncrementBy((long)value);
                    else
                        counter.Increment();
            }
        }
Пример #23
0
        static void IncrementCounter(ref PerformanceCounter counter)
        {
            if (counter != null)
            {
                try
                {
                    counter.Increment();
                }
#pragma warning suppress 56500 // covered by FxCOP
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }

                    ListenerPerfCounters.TracePerformanceCounterUpdateFailure(counter.InstanceName, counter.CounterName);
                    counter = null;
                }
            }
        }
Пример #24
0
 private static void DoItem(PerformanceCounter c)
 {
     c.Increment();
     Thread.Sleep(5);
     c.Decrement();
 }
Пример #25
0
 private void counterButton_Click(object sender, RoutedEventArgs e)
 {
     PerformanceCounter pc = new PerformanceCounter("PerfApp", "Clicks", false);
     pc.Increment();
     counterLabel.Content = pc.NextValue().ToString();
 }
        /// <summary>
        /// Initialises the extension.
        /// </summary>
        /// <param name="extensionConfig"></param>
        /// <param name="server">The server that this extension is for.</param>
        public void Initialise(ICruiseServer server, ExtensionConfiguration extensionConfig)
        {
            if (!PerformanceCounterCategory.Exists("CruiseControl.NET"))
            {
                Log.Info("Initialising new performance counters for integration requests");
                var collection = new CounterCreationDataCollection();

                // Number of integrations completed counter
                var numberOfCompletedIntegrations = new CounterCreationData();
                numberOfCompletedIntegrations.CounterType = PerformanceCounterType.NumberOfItems32;
                numberOfCompletedIntegrations.CounterName = "Number of Completed Integrations";
                collection.Add(numberOfCompletedIntegrations);

                // Number of integrations failed counter
                var numberOfFailedIntegrations = new CounterCreationData();
                numberOfFailedIntegrations.CounterType = PerformanceCounterType.NumberOfItems32;
                numberOfFailedIntegrations.CounterName = "Number of Failed Integrations";
                collection.Add(numberOfFailedIntegrations);

                // Integration time counter
                var integrationElapsedTime = new CounterCreationData();
                integrationElapsedTime.CounterType = PerformanceCounterType.AverageTimer32;
                integrationElapsedTime.CounterName = "Integration Time";
                collection.Add(integrationElapsedTime);

                // Integration count counter
                var averageIntegrations = new CounterCreationData();
                averageIntegrations.CounterType = PerformanceCounterType.AverageBase;
                averageIntegrations.CounterName = "Average number of integrations";
                collection.Add(averageIntegrations);

                // Create the category
                PerformanceCounterCategory.Create("CruiseControl.NET",
                    "Performance counters for CruiseControl.NET",
                    collection);
            }

            // Retrieve the counters
            Log.Debug("Initialising performance monitoring - integration requests");
            var numberOfCompletedIntegrationsCounter = new PerformanceCounter("CruiseControl.NET", "Number of Completed Integrations", false);
            var numberOfFailedIntegrationsCounter = new PerformanceCounter("CruiseControl.NET", "Number of Failed Integrations", false);
            var integrationElapsedTimeCounter = new PerformanceCounter("CruiseControl.NET", "Integration Time", false);
            var averageIntegrationsCounter = new PerformanceCounter("CruiseControl.NET", "Average number of integrations", false);
            var stopwatches = new Dictionary<string, Stopwatch>();

            server.IntegrationStarted += (o, e) =>
            {
                Log.Debug(string.Format("Starting stopwatch for '{0}'", e.ProjectName));

                // Start a stopwatch for the project
                if (stopwatches.ContainsKey(e.ProjectName))
                {
                    stopwatches[e.ProjectName].Reset();
                }
                else
                {
                    var stopwatch = new Stopwatch();
                    stopwatches.Add(e.ProjectName, stopwatch);
                    stopwatch.Start();
                }
            };
            server.IntegrationCompleted += (o, e) =>
            {
                Log.Debug(string.Format("Performance logging for '{0}'", e.ProjectName));

                // Stop the stopwatch and record the elapsed time
                if (stopwatches.ContainsKey(e.ProjectName))
                {
                    var stopwatch = stopwatches[e.ProjectName];
                    stopwatch.Stop();
                    stopwatches.Remove(e.ProjectName);
                    averageIntegrationsCounter.Increment();
                    integrationElapsedTimeCounter.IncrementBy(stopwatch.ElapsedTicks);
                }

                // Record the result
                if (e.Status == IntegrationStatus.Success)
                {
                    numberOfCompletedIntegrationsCounter.Increment();
                }
                else
                {
                    numberOfFailedIntegrationsCounter.Increment();
                }
            };
        }