示例#1
0
文件: Tracer.cs 项目: svetek/Profiler
 public static void Clear()
 {
     Hits.Clear();
     UnboundScriptBlocks.Clear();
     FileScriptBlocks.Clear();
     _index       = 0;
     _previousHit = default;
 }
示例#2
0
文件: Tracer.cs 项目: svetek/Profiler
        public static void Trace(IScriptExtent extent, ScriptBlock scriptBlock, int level)
        {
            var timestamp = Stopwatch.GetTimestamp() / _stopwatchDivider;

            // we are using structs so we need to insert the final struct to the
            // list instead of inserting it to the list, and keeping reference to modify it later
            // so when we are on second event (index 1) we modify the first (index 0) with the correct
            // SelfDuration (start of index 0 until start of index 1 = SelfDuration of index 0) and then add it to
            // the final list
            // We need to do the same when unpatching to get the last event
            if (_index > 0)
            {
                SetSelfDurationAndAddToHits(ref _previousHit, timestamp);
            }

            if (string.IsNullOrEmpty(scriptBlock.File))
            {
                if (!UnboundScriptBlocks.ContainsKey(scriptBlock.Id))
                {
                    UnboundScriptBlocks.Add(scriptBlock.Id, scriptBlock);
                }
            }
            else
            {
                if (!FileScriptBlocks.ContainsKey(scriptBlock.File))
                {
                    FileScriptBlocks.Add(scriptBlock.File, scriptBlock);
                }
            }

            // overwrite the previous event because we already scraped it
            Tracer._previousHit               = new ProfileEventRecord();
            Tracer._previousHit.StartTime     = TimeSpan.FromTicks(timestamp);
            Tracer._previousHit.Index         = _index;
            Tracer._previousHit.IsInFile      = !string.IsNullOrWhiteSpace(extent.File);
            Tracer._previousHit.ScriptBlockId = scriptBlock.Id;
            Tracer._previousHit.Extent        = new ScriptExtentEventData
            {
                File              = extent.File,
                StartLineNumber   = extent.StartLineNumber,
                StartColumnNumber = extent.StartColumnNumber,
                EndLineNumber     = extent.EndLineNumber,
                EndColumnNumber   = extent.EndColumnNumber,
                Text              = extent.Text,
                StartOffset       = extent.StartOffset,
                EndOffset         = extent.EndOffset,
            };
            Tracer._previousHit.Level = level;

            _index++;
        }
示例#3
0
文件: Tracer.cs 项目: svetek/Profiler
 private static void SetSelfDurationAndAddToHits(ref ProfileEventRecord eventRecord, long timestamp)
 {
     eventRecord.SelfDuration = TimeSpan.FromTicks(timestamp - eventRecord.Timestamp);
     Tracer.Hits.Add(eventRecord);
 }