start() public method

Begins the timer.
public start ( ) : void
return void
Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of the class and starts the watch immediately.
        /// </summary>
        /// <returns>An instance of Stopwatch, running.</returns>
        public static Stopwatch StartNew()
        {
            Stopwatch sw = new Stopwatch();

            sw.start();
            return(sw);
        }
Exemplo n.º 2
0
        public void startFrame()
        {
            lock (this)
            {
                // We skip reset frame when this method gets called multiple times.
                var count = Interlocked.Increment(ref updateCount);
                if (enabled && (1 < count && count < maxSampleFrames))
                {
                    return;
                }

                // Update current frame log.
                prevLog = logs[frameCount++ & 0x1];
                curLog  = logs[frameCount & 0x1];

                var endFrameTime = (float)stopwatch.elapsed.TotalMilliseconds;

                // Update marker and create a log.
                for (var barIdx = 0; barIdx < prevLog.bars.Length; ++barIdx)
                {
                    var prevBar = prevLog.bars[barIdx];
                    var nextBar = curLog.bars[barIdx];

                    // Re-open marker that didn't get called EndMark in previous frame.
                    for (var nest = 0; nest < prevBar.nestCount; ++nest)
                    {
                        var markerIdx = prevBar.markerNests[nest];

                        prevBar.markers[markerIdx].endTime = endFrameTime;

                        nextBar.markerNests[nest]      = nest;
                        nextBar.markers[nest].markerId =
                            prevBar.markers[markerIdx].markerId;
                        nextBar.markers[nest].beginTime = 0;
                        nextBar.markers[nest].endTime   = -1;
                        nextBar.markers[nest].color     = prevBar.markers[markerIdx].color;
                    }

                    // Update marker log.
                    for (var markerIdx = 0; markerIdx < prevBar.markCount; ++markerIdx)
                    {
                        var duration = prevBar.markers[markerIdx].endTime -
                                       prevBar.markers[markerIdx].beginTime;

                        int        markerId = prevBar.markers[markerIdx].markerId;
                        MarkerInfo m        = markers[markerId];

                        m.logs[barIdx].color = prevBar.markers[markerIdx].color;

                        if (!m.logs[barIdx].initialized)
                        {
                            // First frame process.
                            m.logs[barIdx].min = duration;
                            m.logs[barIdx].max = duration;
                            m.logs[barIdx].avg = duration;

                            m.logs[barIdx].initialized = true;
                        }
                        else
                        {
                            // Process after first frame.
                            m.logs[barIdx].min  = Math.Min(m.logs[barIdx].min, duration);
                            m.logs[barIdx].max  = Math.Min(m.logs[barIdx].max, duration);
                            m.logs[barIdx].avg += duration;
                            m.logs[barIdx].avg *= 0.5f;

                            if (m.logs[barIdx].samples++ >= logSnapDuration)
                            {
                                m.logs[barIdx].snapMin = m.logs[barIdx].min;
                                m.logs[barIdx].snapMax = m.logs[barIdx].max;
                                m.logs[barIdx].snapAvg = m.logs[barIdx].avg;
                                m.logs[barIdx].samples = 0;
                            }
                        }
                    }

                    nextBar.markCount = prevBar.nestCount;
                    nextBar.nestCount = prevBar.nestCount;
                }

                // Start measuring.
                stopwatch.reset();
                stopwatch.start();
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a new instance of the class and starts the watch immediately.
 /// </summary>
 /// <returns>An instance of Stopwatch, running.</returns>
 public static Stopwatch StartNew()
 {
     Stopwatch sw = new Stopwatch();
     sw.start();
     return sw;
 }