Exemple #1
0
        public static void Start(string itemId)
        {
            EnsureUpdatedState();

            //obtain a list of items to check in/add to
            List<ProfilerItem> lookupList = _currentlyMeasuringItem == null ? _currentState : _currentlyMeasuringItem.Children;

            //get an existing item
            ProfilerItem item = lookupList.Find(lookupItem => lookupItem.Id == itemId);

            //the collection does not yet contain this item -> create it
            if (item == null)
            {
                //create a new item
                item = new ProfilerItem(itemId, _stopwatch, _currentlyMeasuringItem);

                //add reference to newly created child to parent (or state)
                if (_currentlyMeasuringItem == null)
                    _currentState.Add(item);
                else
                    _currentlyMeasuringItem.Children.Add(item);
            }

            //start measurement on item
            item.Start();

            //set is at last started measurement
            _currentlyMeasuringItem = item;
        }
Exemple #2
0
        /// <summary>
        /// Stops the most recently initiated measurement.
        /// </summary>
        public static void Stop()
        {
            EnsureUpdatedState();

            //stop the currently measuring item and ascend it (or set to null if top)
            if (_currentlyMeasuringItem != null)
            {
                _currentlyMeasuringItem.Stop();
                _currentlyMeasuringItem = _currentlyMeasuringItem.Parent;
            }
        }
 internal ProfilerItem(string id, Stopwatch stopwatch, ProfilerItem parent = null)
 {
     Id = id;
     _stopwatch = stopwatch;
     Parent = parent;
 }