public void ProcessTraceAsFolder()
        {
            // Input data
            string[] lttngData = { @"..\..\..\..\TestData\LTTng\lttng-kernel-trace.ctf" };

            string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            using (var zipFile = ZipFile.OpenRead(lttngData[0]))
            {
                zipFile.ExtractToDirectory(tempDirectory);
            }

            using (var dataSourceSet = DataSourceSet.Create())
            {
                var ds = new DirectoryDataSource(tempDirectory);
                dataSourceSet.AddDataSource(ds);

                // Approach #1 - Engine - Doesn't test tables UI but tests processing
                using (var runtime = Engine.Create(new EngineCreateInfo(dataSourceSet.AsReadOnly())))
                {
                    //
                    // We do not assert that any cookers are enabled since we did not explicitly enable cookers here
                    //

                    Assert.IsTrue(ds.IsDirectory());
                    Assert.IsTrue(runtime.AvailableTables.Count() >= 1);
                }
            }


            Directory.Delete(tempDirectory, true);
        }
Exemplo n.º 2
0
        static QuicState[] ProcessTraceFiles(IEnumerable <string> filePaths)
        {
            var quicStates = new List <QuicState>();

            foreach (var filePath in filePaths)
            {
                //
                // Create our runtime environment, add file, enable cookers, and process.
                //
                PluginSet pluginSet;

                if (string.IsNullOrWhiteSpace(typeof(QuicEtwSource).Assembly.Location))
                {
                    // Single File EXE
                    pluginSet = PluginSet.Load(new[] { Environment.CurrentDirectory }, new SingleFileAssemblyLoader());
                }
                else
                {
                    pluginSet = PluginSet.Load();
                }

                using var dataSources = DataSourceSet.Create(pluginSet);
                dataSources.AddFile(filePath);
                var info = new EngineCreateInfo(dataSources.AsReadOnly());
                using var runtime = Engine.Create(info);
                runtime.EnableCooker(QuicEventCooker.CookerPath);
                //Console.Write("Processing {0}...", filePath);
                var results = runtime.Process();
                //Console.WriteLine("Done.\n");

                //
                // Return our 'cooked' data.
                //
                quicStates.Add(results.QueryOutput <QuicState>(new DataOutputPath(QuicEventCooker.CookerPath, "State")));
            }

            return(quicStates.ToArray());
        }
Exemplo n.º 3
0
        public static void LoadTrace(string traceFilename)
        {
            lock (IsTraceProcessedLock)
            {
                // Input data
                var perfettoDataPath = new FileInfo(traceFilename);
                Assert.IsTrue(perfettoDataPath.Exists);

                var dataSources = DataSourceSet.Create();
                dataSources.AddDataSource(new FileDataSource(perfettoDataPath.FullName));

                // Start the SDK engine
                var runtime = Engine.Create(
                    new EngineCreateInfo(dataSources.AsReadOnly())
                {
                    LoggerFactory = new System.Func <System.Type, ILogger>((type) =>
                    {
                        return(new ConsoleLogger(type));
                    }),
                });

                // Enable the source data cookers
                runtime.EnableCooker(PerfettoPluginConstants.SliceCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.ArgCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.ThreadTrackCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.ThreadCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.ProcessRawCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.SchedSliceCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.RawCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.CounterCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.CpuCounterTrackCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.GpuCounterTrackCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.ProcessCounterTrackCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.CounterTrackCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.PerfSampleCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.StackProfileCallSiteCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.StackProfileFrameCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.StackProfileMappingCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.StackProfileSymbolCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.ExpectedFrameCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.ActualFrameCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.PackageListCookerPath);

                // Enable the composite data cookers
                runtime.EnableCooker(PerfettoPluginConstants.GenericEventCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.ProcessEventCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.GpuCountersEventCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.CpuSchedEventCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.LogcatEventCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.FtraceEventCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.CpuFrequencyEventCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.CpuSamplingEventCookerPath);
                runtime.EnableCooker(PerfettoPluginConstants.FrameEventCookerPath);

                // Enable tables used by UI
                runtime.EnableTable(PerfettoCpuCountersTable.TableDescriptor);
                runtime.EnableTable(PerfettoCpuFrequencyTable.TableDescriptor);
                runtime.EnableTable(PerfettoCpuSamplingTable.TableDescriptor);
                runtime.EnableTable(PerfettoCpuSchedTable.TableDescriptor);
                runtime.EnableTable(PerfettoFrameTable.TableDescriptor);
                runtime.EnableTable(PerfettoFtraceEventTable.TableDescriptor);
                runtime.EnableTable(PerfettoGenericEventTable.TableDescriptor);
                runtime.EnableTable(PerfettoGpuCountersTable.TableDescriptor);
                runtime.EnableTable(PerfettoLogcatEventTable.TableDescriptor);
                runtime.EnableTable(PerfettoPackageTable.TableDescriptor);
                runtime.EnableTable(PerfettoProcessMemoryTable.TableDescriptor);
                runtime.EnableTable(PerfettoProcessTable.TableDescriptor);
                runtime.EnableTable(PerfettoSystemMemoryTable.TableDescriptor);

                // Process our data.
                RuntimeExecutionResults = runtime.Process();
            }
        }
Exemplo n.º 4
0
        public bool Run()
        {
            var parsed = Arguments.Parse(this.args);

            if (parsed is null ||
                parsed.ShowHelp)
            {
                Arguments.PrintUsage();
                return(false);
            }

            // Debug
            //Console.ReadLine();

            //
            // Create our runtime environment, enabling cookers and
            // adding inputs.
            //

            Console.WriteLine($"ExtensionDirectory:{parsed.ExtensionDirectory}");

            var dataSources = DataSourceSet.Create();

            Debug.Assert(parsed.CtfInput != null);
            Debug.Assert(parsed.CtfInput.Count > 0);

            foreach (var ctf in parsed.CtfInput.Distinct())
            {
                Console.WriteLine($"CTF Path:{ctf}");
                dataSources.AddDataSource(new FileDataSource(ctf));
            }

            var runtime = Engine.Create(
                new EngineCreateInfo(dataSources.AsReadOnly())
            {
            });


            var lttngGenericEventDataCooker = new LTTngGenericEventDataCooker();
            var cookerName = lttngGenericEventDataCooker.Path;

            runtime.EnableCooker(cookerName);

            //
            // Process our data.
            //

            var results = runtime.Process();

            //
            // Access our cooked data.
            //

            var eventData = results.QueryOutput <ProcessedEventData <LTTngGenericEvent> >(
                new DataOutputPath(
                    cookerName,
                    nameof(LTTngGenericEventDataCooker.Events)));

            TextWriter output = null;
            FileStream file   = null;

            try
            {
                if (!string.IsNullOrWhiteSpace(parsed.Outfile))
                {
                    if (parsed.Force)
                    {
                        file = File.Create(parsed.Outfile);
                    }
                    else
                    {
                        file = File.OpenWrite(parsed.Outfile);
                    }

                    Debug.Assert(file != null);
                    output = new StreamWriter(file);
                }
                else
                {
                    output = Console.Out;
                }

                Debug.Assert(output != null);
                EmitEvents(eventData, output);
            }
            finally
            {
                if (output != null)
                {
                    if (output != Console.Out)
                    {
                        //
                        // This will also dispose out file stream
                        // as the writer takes ownership.
                        //

                        output.Flush();
                        output.Dispose();
                    }
                }
                else if (file != null)
                {
                    //
                    // We opened for write, but never created our output
                    // writer, so just close and delete.
                    //

                    file.Flush();
                    file.Dispose();

                    File.Delete(parsed.Outfile);
                }
                else
                {
                    //
                    // both are null, so there is nothing to clean up
                    //
                }
            }

            return(true);
        }