Ejemplo n.º 1
0
        public virtual void Sampler()
        {
            long[] value = new long[1];
            Instrumentation.Variable <long> var     = new _Variable_238(value);
            InstrumentationService.Sampler  sampler = new InstrumentationService.Sampler();
            sampler.Init(4, var);
            NUnit.Framework.Assert.AreEqual(sampler.GetRate(), 0f, 0.0001);
            sampler.Sample();
            NUnit.Framework.Assert.AreEqual(sampler.GetRate(), 0f, 0.0001);
            value[0] = 1;
            sampler.Sample();
            NUnit.Framework.Assert.AreEqual(sampler.GetRate(), (0d + 1) / 2, 0.0001);
            value[0] = 2;
            sampler.Sample();
            NUnit.Framework.Assert.AreEqual(sampler.GetRate(), (0d + 1 + 2) / 3, 0.0001);
            value[0] = 3;
            sampler.Sample();
            NUnit.Framework.Assert.AreEqual(sampler.GetRate(), (0d + 1 + 2 + 3) / 4, 0.0001);
            value[0] = 4;
            sampler.Sample();
            NUnit.Framework.Assert.AreEqual(sampler.GetRate(), (4d + 1 + 2 + 3) / 4, 0.0001);
            JSONObject json = (JSONObject) new JSONParser().Parse(sampler.ToJSONString());

            NUnit.Framework.Assert.AreEqual(json.Count, 2);
            NUnit.Framework.Assert.AreEqual(json["sampler"], sampler.GetRate());
            NUnit.Framework.Assert.AreEqual(json["size"], 4L);
            StringWriter writer = new StringWriter();

            sampler.WriteJSONString(writer);
            writer.Close();
            json = (JSONObject) new JSONParser().Parse(writer.ToString());
            NUnit.Framework.Assert.AreEqual(json.Count, 2);
            NUnit.Framework.Assert.AreEqual(json["sampler"], sampler.GetRate());
            NUnit.Framework.Assert.AreEqual(json["size"], 4L);
        }
Ejemplo n.º 2
0
 public override void AddSampler(string group, string name, int samplingSize, Instrumentation.Variable
                                 <long> variable)
 {
     InstrumentationService.Sampler sampler = GetToAdd <InstrumentationService.Sampler>
                                                  (group, name, samplerLock, samplers);
     samplerLock.Lock();
     try
     {
         sampler.Init(samplingSize, variable);
         samplersList.AddItem(sampler);
     }
     finally
     {
         samplerLock.Unlock();
     }
 }