예제 #1
0
        private KernelSymbol FindSymbolForIp(ulong ip, SortedList <ulong, KernelSymbol> kernelSymbols)
        {
            KernelSymbol kernelSymbol;

            if (cachedIpSymList.TryGetValue(ip, out kernelSymbol))
            {
                return(kernelSymbol);
            }
            else
            {
                if (maxKernelSymbol == null)
                {
                    maxKernelSymbol = kernelSymbols.Values.LastOrDefault();
                }

                var sym = kernelSymbols.Where(f => (long)f.Key <= (long)ip).LastOrDefault(); // Redo implementation later for perf
                if (sym.Value != null)
                {
                    if (sym.Value != maxKernelSymbol)
                    {
                        cachedIpSymList.TryAdd(ip, sym.Value);
                    }
                    else
                    {
                        cachedIpSymList.TryAdd(ip, null);
                    }
                    return(sym.Value);
                }
                return(null);
            }
        }
        public override DataProcessingResult CookDataElement(PerfEvent data, PerfContext context, CancellationToken cancellationToken)
        {
            lock (symProcessLock)
            {
                if (!attemptedProcessSymbols)
                {
                    try
                    {
                        // TODO: This is hard-coded for now. We don't seem to have a good way to know/infer the trace path or choose this in the UI. CTF SDK change needed?

                        var kallsymsFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "kallsyms");
                        if (File.Exists(kallsymsFile))
                        {
                            using (StreamReader sr = new StreamReader(kallsymsFile))
                            {
                                string line;
                                while ((line = sr.ReadLine()) != null)
                                {
                                    var ks = new KernelSymbol(line);

                                    if (KernelSymbols.ContainsKey(ks.Address))
                                    {
                                        Console.Out.WriteLine($"Unable to add {line}. There is already an entry this address");
                                    }
                                    else
                                    {
                                        KernelSymbols.Add(ks.Address, ks);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Exception processing symbols: {e.Message}");
                    }
                    finally
                    {
                        attemptedProcessSymbols = true;
                    }
                }
            }

            try
            {
                if (data.Name == "cpu-clock")
                {
                    CpuClockEvents.Add(new CpuClockEvent(data, context, KernelSymbols));
                    return(DataProcessingResult.Processed);
                }
                else
                {
                    return(DataProcessingResult.Ignored);
                }
            }
            catch (CtfPlaybackException e)
            {
                Console.Error.WriteLine(e);
                return(DataProcessingResult.CorruptData);
            }
        }