Ejemplo n.º 1
0
 public static void Init(CategoryWrapper wrapper)
 {
     _instance = wrapper.CreateSubCategory <AttributeCounters>();
     MultyCategory.Init(_instance);
 }
Ejemplo n.º 2
0
        public static void RunTest()
        {
            //TestPerf();
            //CompareCounters2();

            // Console.ReadLine();

            //var f = PerformanceCounterCategory.GetCategories();

            //CounterCreationDataCollection f = new CounterCreationDataCollection();
            //f.Add(new CounterCreationData("RawFraction", "RawFraction", PerformanceCounterType.RawFraction));
            //f.Add(new CounterCreationData("RawFractionBase", "RawFractionBase", PerformanceCounterType.RawBase));
            //var cat = PerformanceCounterCategory.Create("testCat3", "testCat3", f);

            //var perfCnt = new PerformanceCounter("testCat3", "RawFraction", false);
            //var perfCntBase = new PerformanceCounter("testCat3", "RawFractionBase", false);

            //double valDbl = 51.4;


            //perfCnt.RawValue = (long)(valDbl * 10000);
            //perfCntBase.RawValue = 100 * 10000;

            //for (int i = 0; i < 1000; i++)
            //{
            //    perfCnt.IncrementBy(10);
            //    Thread.Sleep(100);
            //}

            //return;


            //var rootFact = new Qoollo.PerformanceCounters.WinCounters.WinCounterFactory(Qoollo.PerformanceCounters.WinCounters.WinCountersInstantiationMode.UseExistedIfPossible);
            //var rootFact = new Qoollo.PerformanceCounters.InternalCounters.InternalCounterFactory();
            //var rootFact = Qoollo.PerformanceCounters.NullCounters.NullCounterFactory.Default;
            //var rootFact = new Qoollo.PerformanceCounters.CompositeCounters.CompositeCounterFactory(new CounterFactory[]
            //    {
            //        new Qoollo.PerformanceCounters.InternalCounters.InternalCounterFactory(),
            //        new Qoollo.PerformanceCounters.WinCounters.WinCounterFactory(Qoollo.PerformanceCounters.WinCounters.WinCountersInstantiationMode.UseExistedIfPossible)
            //    });

            var rootFact = PerfCountersInstantiationFactory.CreateCounterFactoryFromAppConfig("PerfCountersConfigurationSection");

            //var si = rootFact.CreateSingleInstanceCategory("aaa", "aaa");
            //var cntr = si.CreateNumberOfItemsCounter("asd", "asd");
            //cntr.Increment();

            //rootFact.InitAll();
            //cntr.SetValue(1000);

            AttributeCounters.Init(rootFact.CreateRootWrapper());
            rootFact.InitAll();


            var tmr = AttributeCounters.Instance.MomentTime.StartNew();
            var avg = AttributeCounters.Instance.AverageTimer32.StartNew();

            Thread.Sleep(1000);
            tmr.Complete();
            avg.Complete();

            Console.ReadLine();

            AttributeCounters.Instance.ElapsedTime.Reset();
            Thread.Sleep(10000);
            var tm = AttributeCounters.Instance.ElapsedTime.CurrentValue;

            tm = AttributeCounters.Instance.ElapsedTime.CurrentValue;
            tm = AttributeCounters.Instance.ElapsedTime.CurrentValue;
            AttributeCounters.Instance.ElapsedTime.Reset();
            var mv = TimeSpan.MaxValue;

            Stopwatch sw = Stopwatch.StartNew();

            for (int i = 0; i < 10000000; i++)
            {
                AttributeCounters.Instance.NumericalCounter.Increment();
                //Thread.Sleep(20);

                //var val = AttributeCounters.Instance.OpPerSec.CurrentValue;
                //if (val == -1)
                //    throw new Exception();
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed.TotalMilliseconds);


            sw = Stopwatch.StartNew();
            for (int i = 0; i < 10000000; i++)
            {
                MultyCategory.Instance[(i % 10).ToString()].ItemCnt.IncrementBy(2);
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed.TotalMilliseconds);

            for (int i = 0; i < 1000; i++)
            {
                AttributeCounters.Instance.OpPerSec.OperationFinished();
                Thread.Sleep(20);

                var val = AttributeCounters.Instance.OpPerSec.CurrentValue;
                if (val == -1)
                {
                    throw new Exception();
                }
            }

            Random rnd111 = new Random();

            //for (int i = 0; i < 100; i++)
            //{
            //    var timer = AttributeCounters.Instance.AverageTimer32.StartNew();
            //    Thread.Sleep(rnd111.Next(1000));
            //    timer.TimePoint();

            //    var val = AttributeCounters.Instance.AverageTimer32.CurrentValue;
            //    if (val == TimeSpan.MinValue)
            //        throw new Exception();
            //}

            //for (int i = 0; i < 1000; i++)
            //{
            //    AttributeCounters.Instance.AvgCount.RegisterValue(rnd111.Next(1000));
            //    Thread.Sleep(50);

            //    var val = AttributeCounters.Instance.AvgCount.CurrentValue;
            //    if (val == long.MinValue)
            //        throw new Exception();
            //}


            for (int cnt = 0; cnt < 4; cnt++)
            {
                int vvv = cnt;
                MultyCategory.Instance[vvv.ToString()].ItemCnt.Reset();
                Task.Run(() =>
                {
                    Random rnd = new Random(vvv * 10);
                    for (int i = 0; i < 500; i++)
                    {
                        MultyCategory.Instance[vvv.ToString()].ItemCnt.IncrementBy(rnd.Next(20));
                        Thread.Sleep(rnd.Next(100));
                    }
                });
            }

            Thread.Sleep(1000);

            MultyCategory.Instance["0"].Remove();


            Console.ReadLine();

            //rootFact.Dispose();

            //  CounterCreationDataCollection cntCol = new CounterCreationDataCollection();
            //  cntCol.Add(new CounterCreationData("c1", "c1", PerformanceCounterType.NumberOfItems32));
            //  cntCol.Add(new CounterCreationData("c2", "c2", PerformanceCounterType.NumberOfItems32));
            ////  PerformanceCounterCategory.Create("TestCat", "TestCat", cntCol);

            //  PerformanceCounter c1_i1 = new PerformanceCounter("TestCat", "c1", false);
            //  PerformanceCounter c1_i2 = new PerformanceCounter("TestCat", "c1", "inst2", false);

            //  c1_i1.Increment();
            //  c1_i2.Increment();

            //  Console.ReadLine();

            //  Counters.Instance.Inicialize();

            //  //Task.Factory.StartNew(Logic, TaskCreationOptions.LongRunning);
            //  Task.Factory.StartNew(AttributeCounterTest, TaskCreationOptions.LongRunning);
            //  Task.Factory.StartNew(MultyInstanceTest, TaskCreationOptions.LongRunning);

            //  Console.ReadLine();
        }