Exemple #1
0
        public static void ProcessTrace()
        {
            lock (IsTraceProcessedLock)
            {
                if (!IsTraceProcessed)
                {
                    // Input data
                    string[] lttngData     = { @"..\..\..\..\TestData\LTTng\lttng-kernel-trace.ctf" };
                    var      lttngDataPath = new FileInfo(lttngData[0]);
                    Assert.IsTrue(lttngDataPath.Exists);

                    // Approach #1 - Engine - Doesn't test tables UI but tests processing
                    var runtime = Engine.Create();

                    runtime.AddFile(lttngDataPath.FullName);

                    // Enable our various types of data
                    var lttngGenericEventDataCooker = new LTTngGenericEventDataCooker();
                    LTTngGenericEventDataCookerPath = lttngGenericEventDataCooker.Path;
                    runtime.EnableCooker(LTTngGenericEventDataCookerPath);

                    var lttngSyscallDataCooker = new LTTngSyscallDataCooker();
                    LTTngSyscallDataCookerPath = lttngSyscallDataCooker.Path;
                    runtime.EnableCooker(LTTngSyscallDataCookerPath);

                    var lttngThreadDataCooker = new LTTngThreadDataCooker();
                    LTTngThreadDataCookerPath = lttngThreadDataCooker.Path;
                    runtime.EnableCooker(LTTngThreadDataCookerPath);

                    var lttngDmesgDataCooker = new LTTngDmesgDataCooker();
                    LTTngDmesgDataCookerPath = lttngDmesgDataCooker.Path;
                    runtime.EnableCooker(LTTngDmesgDataCookerPath);

                    var lttngModuleDataCooker = new LTTngModuleDataCooker();
                    LTTngModuleDataCookerPath = lttngModuleDataCooker.Path;
                    runtime.EnableCooker(LTTngModuleDataCookerPath);

                    var lttngDiskDataCooker = new LTTngDiskDataCooker();
                    LTTngDiskDataCookerPath = lttngDiskDataCooker.Path;
                    runtime.EnableCooker(LTTngDiskDataCookerPath);

                    //
                    // Process our data.
                    //

                    RuntimeExecutionResults = runtime.Process();

                    IsTraceProcessed = true;
                }
            }
        }
Exemple #2
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);
        }