internal void SetEnvironmentInfo(ProcessInfo processInfo) { if (processInfo.EnvironmentVariables != null) { processInfo.IsScmSite = SafeGetValue(() => ProcessExtensions.GetIsScmSite(processInfo.EnvironmentVariables), false); processInfo.IsWebJob = SafeGetValue(() => ProcessExtensions.GetIsWebJob(processInfo.EnvironmentVariables), false); processInfo.Description = SafeGetValue(() => ProcessExtensions.GetDescription(processInfo.EnvironmentVariables), null); } }
public void GetIsScmSite_ReturnsExpectedResult(string appPoolId, bool expectedValue) { Dictionary <string, string> environment = new Dictionary <string, string>(); if (appPoolId != null) { environment[WellKnownEnvironmentVariables.ApplicationPoolId] = appPoolId; } Assert.Equal(expectedValue, ProcessExtensions.GetIsScmSite(environment)); }
private ProcessInfo GetProcessInfo(Process process, string href, bool details = false) { href = href.TrimEnd('/'); if (href.EndsWith("/0", StringComparison.OrdinalIgnoreCase)) { href = href.Substring(0, href.Length - 1) + process.Id; } var selfLink = new Uri(href); var info = new ProcessInfo { Id = process.Id, Name = process.ProcessName, Href = selfLink }; if (details) { // this could fail access denied info.HandleCount = SafeGetValue(() => process.HandleCount, -1); info.ThreadCount = SafeGetValue(() => process.Threads.Count, -1); info.ModuleCount = SafeGetValue(() => process.Modules.Count, -1); info.FileName = SafeGetValue(() => process.MainModule.FileName, "N/A"); // always return empty //info.Arguments = SafeGetValue(() => process.StartInfo.Arguments, "N/A"); //info.UserName = SafeGetValue(() => process.StartInfo.UserName, "N/A"); info.StartTime = SafeGetValue(() => process.StartTime.ToUniversalTime(), DateTime.MinValue); info.TotalProcessorTime = SafeGetValue(() => process.TotalProcessorTime, TimeSpan.FromSeconds(-1)); info.UserProcessorTime = SafeGetValue(() => process.UserProcessorTime, TimeSpan.FromSeconds(-1)); info.PrivilegedProcessorTime = SafeGetValue(() => process.PrivilegedProcessorTime, TimeSpan.FromSeconds(-1)); info.PagedSystemMemorySize64 = SafeGetValue(() => process.PagedSystemMemorySize64, -1); info.NonpagedSystemMemorySize64 = SafeGetValue(() => process.NonpagedSystemMemorySize64, -1); info.PagedMemorySize64 = SafeGetValue(() => process.PagedMemorySize64, -1); info.PeakPagedMemorySize64 = SafeGetValue(() => process.PeakPagedMemorySize64, -1); info.WorkingSet64 = SafeGetValue(() => process.WorkingSet64, -1); info.PeakWorkingSet64 = SafeGetValue(() => process.PeakWorkingSet64, -1); info.VirtualMemorySize64 = SafeGetValue(() => process.VirtualMemorySize64, -1); info.PeakVirtualMemorySize64 = SafeGetValue(() => process.PeakVirtualMemorySize64, -1); info.PrivateMemorySize64 = SafeGetValue(() => process.PrivateMemorySize64, -1); info.MiniDump = new Uri(selfLink + "/dump"); if (ProcessExtensions.SupportGCDump) { info.GCDump = new Uri(selfLink + "/gcdump"); } info.OpenFileHandles = SafeGetValue(() => GetOpenFileHandles(process.Id), Enumerable.Empty <string>()); info.Parent = new Uri(selfLink, SafeGetValue(() => process.GetParentId(_tracer), 0).ToString()); info.Children = SafeGetValue(() => process.GetChildren(_tracer, recursive: false), Enumerable.Empty <Process>()).Select(c => new Uri(selfLink, c.Id.ToString())); info.Threads = SafeGetValue(() => GetThreads(process, selfLink.ToString()), Enumerable.Empty <ProcessThreadInfo>()); info.Modules = SafeGetValue(() => GetModules(process, selfLink.ToString().TrimEnd('/') + "/modules"), Enumerable.Empty <ProcessModuleInfo>()); info.TimeStamp = DateTime.UtcNow; info.EnvironmentVariables = SafeGetValue(process.GetEnvironmentVariables, null); info.CommandLine = SafeGetValue(process.GetCommandLine, null); info.IsScmSite = SafeGetValue(() => ProcessExtensions.GetIsScmSite(info.EnvironmentVariables), false); info.IsWebJob = SafeGetValue(() => ProcessExtensions.GetIsWebJob(info.EnvironmentVariables), false); info.Description = SafeGetValue(() => ProcessExtensions.GetDescription(info.EnvironmentVariables), null); } return(info); }