internal void LogStartUpInformation(PerformanceLogStartupInformation startupInfo) { if (!IsEnabled()) { return; } DotnetVersionFile versionFile = DotnetFiles.VersionFileObject; string commitSha = versionFile.CommitSha ?? "N/A"; LogMachineConfiguration(); OSInfo(RuntimeEnvironment.OperatingSystem, RuntimeEnvironment.OperatingSystemVersion, RuntimeEnvironment.OperatingSystemPlatform.ToString()); SDKInfo(Product.Version, commitSha, RuntimeInformation.RuntimeIdentifier, versionFile.BuildRid, AppContext.BaseDirectory); EnvironmentInfo(Environment.CommandLine); LogMemoryConfiguration(); LogDrives(); // It's possible that IsEnabled returns true if an out-of-process collector such as ETW is enabled. // If the perf log hasn't been enabled, then startupInfo will be null, so protect against nullref here. if (startupInfo != null) { if (startupInfo.TimedAssembly != null) { AssemblyLoad(startupInfo.TimedAssembly.GetName().Name, startupInfo.AssemblyLoadTime.TotalMilliseconds); } Process currentProcess = Process.GetCurrentProcess(); TimeSpan latency = startupInfo.MainTimeStamp - currentProcess.StartTime; HostLatency(latency.TotalMilliseconds); } }
public static int Main(string[] args) { //setting output encoding is not available on those platforms if (!OperatingSystem.IsIOS() && !OperatingSystem.IsAndroid() && !OperatingSystem.IsTvOS()) { //if output is redirected, force encoding to utf-8; //otherwise the caller may not decode it correctly if (Console.IsOutputRedirected) { Console.OutputEncoding = Encoding.UTF8; } } DebugHelper.HandleDebugSwitch(ref args); // Capture the current timestamp to calculate the host overhead. DateTime mainTimeStamp = DateTime.Now; TimeSpan startupTime = mainTimeStamp - Process.GetCurrentProcess().StartTime; bool perfLogEnabled = Env.GetEnvironmentVariableAsBool("DOTNET_CLI_PERF_LOG", false); // Avoid create temp directory with root permission and later prevent access in non sudo if (SudoEnvironmentDirectoryOverride.IsRunningUnderSudo()) { perfLogEnabled = false; } PerformanceLogStartupInformation startupInfo = null; if (perfLogEnabled) { startupInfo = new PerformanceLogStartupInformation(mainTimeStamp); PerformanceLogManager.InitializeAndStartCleanup(FileSystemWrapper.Default); } PerformanceLogEventListener perLogEventListener = null; try { if (perfLogEnabled) { perLogEventListener = PerformanceLogEventListener.Create(FileSystemWrapper.Default, PerformanceLogManager.Instance.CurrentLogDirectory); } PerformanceLogEventSource.Log.LogStartUpInformation(startupInfo); PerformanceLogEventSource.Log.CLIStart(); InitializeProcess(); try { return(ProcessArgs(args, startupTime)); } catch (HelpException e) { Reporter.Output.WriteLine(e.Message); return(0); } catch (Exception e) when(e.ShouldBeDisplayedAsError()) { Reporter.Error.WriteLine(CommandContext.IsVerbose() ? e.ToString().Red().Bold() : e.Message.Red().Bold()); var commandParsingException = e as CommandParsingException; if (commandParsingException != null && commandParsingException.ParseResult != null) { commandParsingException.ParseResult.ShowHelp(); } return(1); } catch (Exception e) when(!e.ShouldBeDisplayedAsError()) { // If telemetry object has not been initialized yet. It cannot be collected TelemetryEventEntry.SendFiltered(e); Reporter.Error.WriteLine(e.ToString().Red().Bold()); return(1); } finally { PerformanceLogEventSource.Log.CLIStop(); } } finally { if (perLogEventListener != null) { perLogEventListener.Dispose(); } } }
public static int Main(string[] args) { DebugHelper.HandleDebugSwitch(ref args); // Capture the current timestamp to calculate the host overhead. DateTime mainTimeStamp = DateTime.Now; TimeSpan startupTime = mainTimeStamp - Process.GetCurrentProcess().StartTime; bool perfLogEnabled = Env.GetEnvironmentVariableAsBool("DOTNET_CLI_PERF_LOG", false); PerformanceLogStartupInformation startupInfo = null; if (perfLogEnabled) { startupInfo = new PerformanceLogStartupInformation(mainTimeStamp); PerformanceLogManager.InitializeAndStartCleanup(FileSystemWrapper.Default); } PerformanceLogEventListener perLogEventListener = null; try { if (perfLogEnabled) { perLogEventListener = PerformanceLogEventListener.Create(FileSystemWrapper.Default, PerformanceLogManager.Instance.CurrentLogDirectory); } PerformanceLogEventSource.Log.LogStartUpInformation(startupInfo); PerformanceLogEventSource.Log.CLIStart(); InitializeProcess(); try { return(ProcessArgs(args, startupTime)); } catch (HelpException e) { Reporter.Output.WriteLine(e.Message); return(0); } catch (Exception e) when(e.ShouldBeDisplayedAsError()) { Reporter.Error.WriteLine(CommandContext.IsVerbose() ? e.ToString().Red().Bold() : e.Message.Red().Bold()); var commandParsingException = e as CommandParsingException; if (commandParsingException != null) { Reporter.Output.WriteLine(commandParsingException.HelpText); } return(1); } catch (Exception e) when(!e.ShouldBeDisplayedAsError()) { // If telemetry object has not been initialized yet. It cannot be collected TelemetryEventEntry.SendFiltered(e); Reporter.Error.WriteLine(e.ToString().Red().Bold()); return(1); } finally { PerformanceLogEventSource.Log.CLIStop(); } } finally { if (perLogEventListener != null) { perLogEventListener.Dispose(); } } }