Ejemplo n.º 1
0
        public static TimingMeter GetMeter(string title, string category, bool accumulate)
        {
            TimingMeter meter = GetMeter(title, category);

            meter.accumulate = true;
            return(meter);
        }
Ejemplo n.º 2
0
 // Enable or disable only a single category
 public static void EnableOnlyCategory(string categoryName, bool enable)
 {
     Init();
     foreach (var pair in instance.metersById)
     {
         TimingMeter meter = pair.Value;
         meter.enabled = (meter.category == categoryName ? enable : !enable);
     }
 }
Ejemplo n.º 3
0
        protected void SaveToFileInternal(string pathname)
        {
            var f      = new FileStream(pathname, FileMode.Create, FileAccess.Write);
            var writer = new StreamWriter(f);

            writer.Write(string.Format("MeterCount={0}\n", this.metersById.Count));
            foreach (var pair in instance.metersById)
            {
                TimingMeter meter = pair.Value;
                writer.Write(string.Format("{0},{1},{2}\n", meter.title, meter.category, meter.meterId));
            }
        }
Ejemplo n.º 4
0
        public static int AddEvent(TimingMeter meter, short eventKind, string info)
        {
            long  time       = CaptureCurrentTime();
            short meterId    = (meter == null) ? (short)0 : meter.meterId;
            var   meterEvent = new MeterEvent(meterId, eventKind, time, info);

#if DEBUG
            DebugAddEvent(meter, meterEvent);
#endif
            instance.eventTrace.Add(meterEvent);
            return(instance.eventTrace.Count);
        }
Ejemplo n.º 5
0
 // Enable or disable meters by category
 public static void EnableCategory(string categoryName, bool enable)
 {
     Init();
     foreach (var pair in instance.metersById)
     {
         TimingMeter meter = pair.Value;
         if (meter.category == categoryName)
         {
             meter.enabled = enable;
         }
     }
 }
Ejemplo n.º 6
0
        protected void DumpEventLog()
        {
            if (File.Exists(MeterEventsFilename))
            {
                File.Delete(MeterEventsFilename);
            }
            var f      = new FileStream(MeterEventsFilename, FileMode.Create, FileAccess.Write);
            var writer = new StreamWriter(f);

            writer.Write(string.Format("Dumping meter event log on {0} at {1}; units are usecs\r\n", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString()));
            int  indent         = 0;
            var  meterStack     = new List <MeterStackEntry>();
            long firstEventTime = 0;

            for (int i = 0; i < this.eventTrace.Count; i++)
            {
                short kind = this.eventTrace[i].eventKind;
                long  t    = this.eventTrace[i].eventTime;
                if (i == 0)
                {
                    firstEventTime = t;
                }
                if (kind == ekInfo)
                {
                    writer.WriteLine(string.Format("{0,12:D} {1}{2} {3}{4}", ToMicroseconds(t - firstEventTime), IndentCount(indent), "Info ", " ", this.eventTrace[i].info));
                    continue;
                }
                TimingMeter meter = GetMeterById(this.eventTrace[i].meterId);
                if (kind == ekEnter)
                {
                    indent++;
                    writer.WriteLine(string.Format("{0,12:D} {1}{2} {3}.{4}", ToMicroseconds(t - firstEventTime), IndentCount(indent), "Enter", meter.category, meter.title));
                    meterStack.Add(new MeterStackEntry(meter, t));
                }
                else if (kind == ekExit)
                {
                    Debug.Assert(meterStack.Count > 0, "Meter stack is empty during ekExit");
                    MeterStackEntry s = meterStack[meterStack.Count - 1];
                    Debug.Assert(s.meter == meter, "Entered " + s.meter.title + "; Exiting " + meter.title);
                    writer.WriteLine(string.Format("{0,12:D} {1}{2} {3}.{4}", ToMicroseconds(t - s.eventTime), IndentCount(indent), "Exit ", meter.category, meter.title));
                    indent--;
                    meterStack.RemoveAt(meterStack.Count - 1);
                }
            }
            writer.Close();
        }
Ejemplo n.º 7
0
        // Look up the timing meter by title; if it doesn't exist
        // create one with the title and category
        public static TimingMeter GetMeter(string title, string category)
        {
            string      name = title + "&" + category;
            TimingMeter meter;

            Init();
            if (instance.metersByName.TryGetValue(name, out meter))
            {
                return(meter);
            }
            else
            {
                BarfOnBadChars(title, "TimingMeter title");
                BarfOnBadChars(category, "TimingMeter category");
                short id = instance.timerIdCounter++;
                meter = new TimingMeter(title, category, id);
                instance.metersByName.Add(name, meter);
                instance.metersById.Add(id, meter);
                return(meter);
            }
        }
Ejemplo n.º 8
0
 private static void DebugAddEvent(TimingMeter meter, MeterEvent evt)
 {
     if (evt.eventKind == ekEnter)
     {
         debugMeterStack.Add(new MeterStackEntry(meter, 0));
     }
     else if (evt.eventKind == ekExit)
     {
         Debug.Assert(debugMeterStack.Count > 0, "Meter stack is empty during ekExit");
         MeterStackEntry s = debugMeterStack[debugMeterStack.Count - 1];
         Debug.Assert(s.meter == meter, "Entered " + s.meter.title + "; Exiting " + meter.title);
         debugMeterStack.RemoveAt(debugMeterStack.Count - 1);
     }
     else if (evt.eventKind == ekInfo)
     {
         // just ignore these
     }
     else
     {
         Debug.Assert(false);
     }
 }
Ejemplo n.º 9
0
		private static void DebugAddEvent( TimingMeter meter, MeterEvent evt )
		{
			if ( evt.eventKind == ekEnter )
			{
				debugMeterStack.Add( new MeterStackEntry( meter, 0 ) );
			}
			else if ( evt.eventKind == ekExit )
			{
				Debug.Assert( debugMeterStack.Count > 0, "Meter stack is empty during ekExit" );
				MeterStackEntry s = debugMeterStack[ debugMeterStack.Count - 1 ];
				Debug.Assert( s.meter == meter, "Entered " + s.meter.title + "; Exiting " + meter.title );
				debugMeterStack.RemoveAt( debugMeterStack.Count - 1 );
			}
			else if ( evt.eventKind == ekInfo )
			{
				// just ignore these
			}
			else
			{
				Debug.Assert( false );
			}
		}
Ejemplo n.º 10
0
		internal MeterStackEntry( TimingMeter meter, long eventTime )
		{
			this.meter = meter;
			this.eventTime = eventTime;
		}
Ejemplo n.º 11
0
		public static int AddEvent( TimingMeter meter, short eventKind, string info )
		{
			long time = CaptureCurrentTime();
			short meterId = ( meter == null ) ? (short)0 : meter.meterId;
			MeterEvent meterEvent = new MeterEvent( meterId, eventKind, time, info );
#if DEBUG
			DebugAddEvent( meter, meterEvent );
#endif
			instance.eventTrace.Add( meterEvent );
			return instance.eventTrace.Count;
		}
Ejemplo n.º 12
0
		// Look up the timing meter by title; if it doesn't exist
		// create one with the title and category
		public static TimingMeter GetMeter( string title, string category )
		{
			string name = title + "&" + category;
			TimingMeter meter;
			Init();
			if ( instance.metersByName.TryGetValue( name, out meter ) )
				return meter;
			else
			{
				BarfOnBadChars( title, "TimingMeter title" );
				BarfOnBadChars( category, "TimingMeter category" );
				short id = instance.timerIdCounter++;
				meter = new TimingMeter( title, category, id );
				instance.metersByName.Add( name, meter );
				instance.metersById.Add( id, meter );
				return meter;
			}
		}
Ejemplo n.º 13
0
 public void Dispose()
 {
     this.meter.Exit();
     this.meter = null;
 }
Ejemplo n.º 14
0
 public AutoTimer(TimingMeter meter)
 {
     this.meter = meter;
     meter.Enter();
 }
Ejemplo n.º 15
0
 internal MeterStackEntry(TimingMeter meter, long eventTime)
 {
     this.meter     = meter;
     this.eventTime = eventTime;
 }
Ejemplo n.º 16
0
		public AutoTimer( TimingMeter meter )
		{
			this.meter = meter;
			meter.Enter();
		}
Ejemplo n.º 17
0
        protected void GenerateReport(StreamWriter writer, int start, Dictionary <string, string> options)
        {
            // For now, ignore options and just print the event trace
            if (dumpEventLog)
            {
                DumpEventLog();
            }

            // Zero the stack depth and added time
            foreach (var pair in instance.metersById)
            {
                TimingMeter meter = pair.Value;
                meter.stackDepth = 0;
                meter.addedTime  = 0;
            }
            var  meterStack     = new List <MeterStackEntry>();
            int  indent         = 0;
            long firstEventTime = 0;

            for (int i = 0; i < this.eventTrace.Count; i++)
            {
                short kind = this.eventTrace[i].eventKind;
                long  t    = this.eventTrace[i].eventTime;
                if (i == 0)
                {
                    firstEventTime = t;
                }
                if (kind == ekInfo)
                {
                    writer.WriteLine(string.Format("{0,12:D} {1}{2} {3}{4}", ToMicroseconds(t - firstEventTime), IndentCount(indent), "Info ", " ", this.eventTrace[i].info));
                    continue;
                }
                TimingMeter meter = GetMeterById(this.eventTrace[i].meterId);
                if (kind == ekEnter)
                {
                    if (meter.accumulate && meter.stackDepth == 0)
                    {
                        meter.addedTime = 0;
                    }
                    if (i >= start && (!meter.accumulate || meter.stackDepth == 0))
                    {
                        // Don't display the enter and exit if the
                        // exit is the very next record, and the
                        // elapsed usecs is less than DontDisplayUsecs
                        if (this.eventTrace.Count > i + 1 && this.eventTrace[i + 1].meterId == this.eventTrace[i].meterId && this.eventTrace[i + 1].eventKind == ekExit && ToMicroseconds(this.eventTrace[i + 1].eventTime - t) < DontDisplayUsecs)
                        {
                            i++;
                            continue;
                        }
                        writer.WriteLine(string.Format("{0,12:D} {1}{2} {3}{4}.{5}", ToMicroseconds(t - firstEventTime), IndentCount(indent), "Enter", (meter.accumulate ? "*" : " "), meter.category, meter.title));
                        if (!meter.accumulate)
                        {
                            indent++;
                        }
                    }
                    meter.stackDepth++;
                    meterStack.Add(new MeterStackEntry(meter, t));
                }
                else if (kind == ekExit)
                {
                    Debug.Assert(meterStack.Count > 0, "Meter stack is empty during ekExit");
                    MeterStackEntry s = meterStack[meterStack.Count - 1];
                    meter.stackDepth--;
                    Debug.Assert(s.meter == meter);
                    if (meter.stackDepth > 0 && meter.accumulate)
                    {
                        meter.addedTime += t - s.eventTime;
                    }
                    else if (i >= start)
                    {
                        if (!meter.accumulate)
                        {
                            indent--;
                        }
                        writer.WriteLine(string.Format("{0,12:D} {1}{2} {3}{4}.{5}", ToMicroseconds(meter.accumulate ? meter.addedTime : t - s.eventTime), IndentCount(indent), "Exit ", (meter.accumulate ? "*" : " "), meter.category, meter.title));
                    }
                    meterStack.RemoveAt(meterStack.Count - 1);
                }
            }
        }
Ejemplo n.º 18
0
		public void Dispose()
		{
			meter.Exit();
			meter = null;
		}
Ejemplo n.º 19
0
		public void Dispose()
		{
			this.meter.Exit();
			this.meter = null;
		}