/// <summary>
        /// Cache/split IP Module/Frame
        /// </summary>
        /// <param name="sample"></param>
        /// <param name="stackSource"></param>
        /// <returns></returns>
        private StackFrame GetIpStackFrame(StackSourceSample sample, ParallelLinuxPerfScriptStackSource stackSource)
        {
            if (sample.SampleIndex == StackSourceSampleIndex.Invalid)
            {
                return(new StackFrame(String.Empty, String.Empty));
            }

            var        si = sample.StackIndex;
            StackFrame sf;

            if (IpStackFrames.TryGetValue((int)si, out sf))
            {
                return(sf);
            }
            else
            {
                var frame     = stackSource.GetFrameIndex(si);
                var frameName = stackSource.Interner.GetFrameName(frame, false);

                var frameNameSplit = frameName.Split('!');
                if (frameNameSplit.Length == 2)
                {
                    sf = new StackFrame(frameNameSplit[0], frameNameSplit[1]);
                    IpStackFrames.TryAdd((int)si, sf);
                    return(sf);
                }
                return(null);
            }
        }
Ejemplo n.º 2
0
        private static void Write(string source)
        {
            var stackSource = new ParallelLinuxPerfScriptStackSource(source);

            XmlStackSourceWriter.WriteStackViewAsZippedXml(stackSource,
                                                           Constants.GetOutputPath(Path.GetFileNameWithoutExtension(source) + ".perfView.xml.zip"));
        }
Ejemplo n.º 3
0
        private void InterningStackCountTest(string source, int expectedStackCount)
        {
            Constants.WaitUntilFileIsReady(source);

            ParallelLinuxPerfScriptStackSource stackSource = new ParallelLinuxPerfScriptStackSource(source);

            Assert.Equal(expectedStackCount, stackSource.Interner.CallStackCount);
        }
Ejemplo n.º 4
0
        public void ConcurrentBlockedTime()
        {
            string path = Constants.GetTestingFilePath(@"C:\Users\t-lufern\Desktop\Luca\dev\helloworld.trace.zip");
            var    linearStackSource = new LinuxPerfScriptStackSource(path, true);

            Constants.WaitUntilFileIsReady(path);
            var parallelStackSource = new ParallelLinuxPerfScriptStackSource(path, true);

            Assert.Equal(linearStackSource.TotalBlockedTime, parallelStackSource.TotalBlockedTime);
        }
        private string GetProcess(StackSourceSample sample, ParallelLinuxPerfScriptStackSource stackSource)
        {
            if (sample.SampleIndex == StackSourceSampleIndex.Invalid)
            {
                return(String.Empty);
            }

            string process;

            SampleProcessDict.TryGetValue((long)sample.SampleIndex, out process);
            return(process);
        }
        private int GetThreadId(StackSourceSample sample, ParallelLinuxPerfScriptStackSource stackSource)
        {
            if (sample.SampleIndex == StackSourceSampleIndex.Invalid)
            {
                return(-1);
            }

            int tid;

            SampleThreadDict.TryGetValue((long)sample.SampleIndex, out tid);
            return(tid);
        }
Ejemplo n.º 7
0
        private void TotalBlockedTimeTest(string source, double expectedTotalBlockedPeriod, bool concurrentTest = false)
        {
            if (concurrentTest)
            {
                StartLook = 10;
            }

            ParallelLinuxPerfScriptStackSource stackSource = new ParallelLinuxPerfScriptStackSource(source, doThreadTime: true);

            StartLook = null;

            Assert.Equal(expectedTotalBlockedPeriod, stackSource.TotalBlockedTime);
        }
Ejemplo n.º 8
0
        protected override Task ProcessAsyncCore(
            IProgress <int> progress,
            CancellationToken cancellationToken)
        {
            var contentDictionary = new Dictionary <string, ParallelLinuxPerfScriptStackSource>();

            foreach (var path in this.filePaths)
            {
                // Hack because perf.data.txt and parsing only includes relative offsets, not absolute time
                // Look for timestamp.txt in the path of the trace and use that as trace start UTC time
                // If it doesn't exist, just use today
                var traceStartTime          = DateTime.UtcNow.Date;
                var traceTimeStampStartFile = Path.Combine(Path.GetDirectoryName(path), "timestamp.txt");
                if (File.Exists(traceTimeStampStartFile))
                {
                    string time = File.ReadAllText(traceTimeStampStartFile).Trim();

                    if (!DateTime.TryParse(time, out traceStartTime))
                    {
                        traceStartTime = DateTime.UtcNow.Date; // traceStartTime got overwritten

                        try
                        {
                            traceStartTime = DateTime.ParseExact(time, "ddd MMM d HH:mm:ss yyyy", CultureInfo.InvariantCulture); // "Thu Oct 17 15:37:51 2019" See if this "captured on" date format from "sudo perf report --header-only -i perf.data.merged"
                        }
                        catch (FormatException)
                        {
                            Logger.Error("Could not parse time {0} in file {1}. Format expected is: ddd MMM d HH:mm:ss yyyy", time, traceTimeStampStartFile);
                        }
                    }
                    traceStartTime = DateTime.FromFileTimeUtc(traceStartTime.ToFileTimeUtc());
                }

                var stackSource = new ParallelLinuxPerfScriptStackSource(path);

                var lastSample = stackSource.GetLinuxPerfScriptSampleByIndex((StackSourceSampleIndex)stackSource.SampleIndexLimit - 1);

                contentDictionary[path] = stackSource;
                this.dataSourceInfo     = new DataSourceInfo(0, (long)lastSample.TimeRelativeMSec * 1000000, traceStartTime);
            }

            this.fileContent = new ReadOnlyDictionary <string, ParallelLinuxPerfScriptStackSource>(contentDictionary);

            return(Task.CompletedTask);
        }
Ejemplo n.º 9
0
        private void DoStackTraceTest(string path, bool doBlockedTime, List <List <string> > callerStacks)
        {
            ParallelLinuxPerfScriptStackSource stackSource = new ParallelLinuxPerfScriptStackSource(path, doBlockedTime);

            for (int i = 0; i < stackSource.SampleIndexLimit; i++)
            {
                var sample = stackSource.GetSampleByIndex((StackSourceSampleIndex)i);

                var stackIndex = sample.StackIndex;
                for (int j = 0; (int)stackIndex != -1; j++)
                {
                    var frameIndex = stackSource.GetFrameIndex(stackIndex);
                    Assert.Equal(callerStacks[i][j], stackSource.GetFrameName(frameIndex, false));
                    stackIndex = stackSource.GetCallerIndex(stackIndex);
                }

                Assert.Equal(-1, (int)stackIndex);
            }
        }
        private Dictionary <int, double> CalculateSampleWeights(ParallelLinuxPerfScriptStackSource stackSource)
        {
            var sampleWeights = new Dictionary <int, double>();

            const int MaxCpus = 256;
            var       lastPerCpuSampleWeight = new Tuple <int, double> [MaxCpus]; // Per CPU - Last sample #, TimeRelativeMSec

            for (var i = 0; i < stackSource.SampleIndexLimit; i++)
            {
                var sample = stackSource.GetLinuxPerfScriptSampleByIndex((StackSourceSampleIndex)i);
                var prevSampleTimeRelativeMSec = lastPerCpuSampleWeight[sample.CpuNumber];

                if (prevSampleTimeRelativeMSec != null)
                {
                    var weightOfLastSampleOnCpu = sample.TimeRelativeMSec - prevSampleTimeRelativeMSec.Item2;
                    sampleWeights.Add(prevSampleTimeRelativeMSec.Item1, weightOfLastSampleOnCpu);    // Weight is duration for the prev samp
                }
                lastPerCpuSampleWeight[sample.CpuNumber] = new Tuple <int, double>(i, sample.TimeRelativeMSec);
            }


            var medSampleWeight = Median(sampleWeights);

            // Now there will be samples at the end that don't have a weight
            for (var i = 0; i < stackSource.SampleIndexLimit; i++)
            {
                if (!sampleWeights.ContainsKey(i))
                {
                    sampleWeights.Add(i, medSampleWeight);
                }
            }

            // Now the first samples weights won't be correct since there was no previous sample to compare to. Fix them up
            // Find samples that are 1/2 big as median OR 1.3x as big (being in a VM) and set to median
            var unusualSamples = sampleWeights.Where(f => f.Value <= medSampleWeight / 2 || f.Value >= medSampleWeight * 1.3).ToList();

            for (int i = 0; i < unusualSamples.Count(); i++)
            {
                sampleWeights[unusualSamples[i].Key] = medSampleWeight;
            }

            return(sampleWeights);
        }
Ejemplo n.º 11
0
        private void InterningStackCountTest(string source, int expectedStackCount)
        {
            ParallelLinuxPerfScriptStackSource stackSource = new ParallelLinuxPerfScriptStackSource(source);

            Assert.Equal(expectedStackCount, stackSource.Interner.CallStackCount);
        }
        private string[] GetCallStack(StackSourceSample sample, ParallelLinuxPerfScriptStackSource stackSource)
        {
            if (sample.SampleIndex == StackSourceSampleIndex.Invalid)
            {
                return(new string[0]);
            }

            var callStack = new List <string>();

            // IP
            var ip = GetIpStackFrame(sample, stackSource);

            String ipFrame;

            if (ip != null)
            {
                ipFrame = $"{ip.Module}!{ip.Frame}";
            }
            else
            {
                ipFrame = "Unknown!Unknown";
            }
            callStack.Add(ipFrame);

            // Callstack
            StackSourceFrameIndex currentCallStackFrame;
            String currentCallStackFrameStr;

            var callerIndex = stackSource.GetCallerIndex(sample.StackIndex);

            while (callerIndex != StackSourceCallStackIndex.Invalid &&
                   callerIndex != StackSourceCallStackIndex.Start)
            {
                currentCallStackFrame    = stackSource.GetFrameIndex(callerIndex);
                currentCallStackFrameStr = stackSource.Interner.GetFrameName(currentCallStackFrame, false);

                // Get next caller
                callerIndex = stackSource.GetCallerIndex(callerIndex);

                // Before start is the thread which we don't want as part of callstack
                if (callerIndex == StackSourceCallStackIndex.Invalid)
                {
                    // Process
                    SampleProcessDict.TryAdd((long)sample.SampleIndex, currentCallStackFrameStr);
                    //callStack.Add(currentCallStackFrameStr); // just for testing
                }
                else
                {
                    if (currentCallStackFrameStr.StartsWith("Thread ("))
                    {
                        int tid;
                        if (Int32.TryParse(currentCallStackFrameStr.Replace("Thread (", String.Empty).Replace(")", String.Empty), out tid))
                        {
                            SampleThreadDict.TryAdd((long)sample.SampleIndex, tid);
                        }
                    }
                    else
                    {
                        callStack.Add(currentCallStackFrameStr);
                    }
                }
            }

            return(callStack.Reverse <string>().ToArray());
        }