Exemplo n.º 1
0
        private static Session RunConsole(string command, Config config)
        {
            Trace.Verbose("DotMemory.RunConsole: Looking for runner...");

            var runnerPath = ConsoleRunnerPackage.GetRunnerPath();

            var workspaceFile = GetSaveToFilePath(config);

            var commandLine = new StringBuilder();

            if (config.LogLevel != null)
            {
                commandLine.Append($"--log-level={config.LogLevel} ");
            }

            if (config.LogFile != null)
            {
                commandLine.Append($"\"--log-file={config.LogFile}\" ");
            }

            commandLine.Append($"{command} {Process.GetCurrentProcess().Id} \"-f={workspaceFile}\"");

            if (config.IsOverwriteWorkspace)
            {
                commandLine.Append(" --overwrite");
            }

            if (config.IsOpenDotMemory)
            {
                commandLine.Append(" --open-dotmemory");
            }

            if (command != "get-snapshot")
            {
                commandLine.Append(" --use-api");
            }

            if (config.OtherArguments != null)
            {
                commandLine.Append(' ').Append(config.OtherArguments);
            }

            Trace.Info("DotMemory.RunConsole:\n  runner = `{0}`\n  arguments = `{1}`", runnerPath, commandLine);

            var consoleProfiler = new ConsoleProfiler(
                runnerPath,
                commandLine.ToString(),
                MessageServicePrefix,
                CltPresentableName,
                () => (MemoryProfiler.GetFeatures() & MemoryFeatures.Ready) == MemoryFeatures.Ready
                );

            Trace.Verbose("DotMemory.RunConsole: Runner started.");

            return(new Session(consoleProfiler, workspaceFile));
        }