Ejemplo n.º 1
0
            public Native(ExtendedLimitInformation managed)
            {
                basic = new BasicLimitInformation.Native(managed);

                IOCounters            = new IOCounters(0);
                ProcessMemoryLimit    = managed.ProcessMemoryLimit;
                JobMemoryLimit        = managed.JobMemoryLimit;
                PeakProcessMemoryUsed = managed.PeakProcessMemoryUsed;
                PeakJobMemoryUsed     = managed.PeakJobMemoryUsed;
            }
Ejemplo n.º 2
0
 /// <nodoc />
 public static AccountingInformation Deserialize(BuildXLReader reader)
 {
     return(new AccountingInformation()
     {
         IO = IOCounters.Deserialize(reader),
         UserTime = reader.ReadTimeSpan(),
         KernelTime = reader.ReadTimeSpan(),
         MemoryCounters = ProcessMemoryCounters.Deserialize(reader),
         NumberOfProcesses = reader.ReadUInt32()
     });
 }
Ejemplo n.º 3
0
        // <inheritdoc />
        internal override JobObject.AccountingInformation GetJobAccountingInfo()
        {
            if (m_processResourceUsage is null)
            {
                return(base.GetJobAccountingInfo());
            }
            else
            {
                IOCounters            ioCounters;
                ProcessMemoryCounters memoryCounters;
                uint childProcesses = 0;

                try
                {
                    ioCounters = new IOCounters(new IO_COUNTERS()
                    {
                        ReadOperationCount  = m_processResourceUsage.Aggregate(0UL, (acc, usage) => acc + usage.Value.DiskReadOps),
                        ReadTransferCount   = m_processResourceUsage.Aggregate(0UL, (acc, usage) => acc + usage.Value.DiskBytesRead),
                        WriteOperationCount = m_processResourceUsage.Aggregate(0UL, (acc, usage) => acc + usage.Value.DiskWriteOps),
                        WriteTransferCount  = m_processResourceUsage.Aggregate(0UL, (acc, usage) => acc + usage.Value.DiskBytesWritten),
                    });

                    memoryCounters = ProcessMemoryCounters.CreateFromBytes(
                        m_processResourceUsage.Aggregate(0UL, (acc, usage) => acc + usage.Value.PeakWorkingSetSize),
                        m_processResourceUsage.Aggregate(0UL, (acc, usage) => acc + usage.Value.WorkingSetSize),
                        0, 0);

                    childProcesses = m_processResourceUsage.Keys.Count > 0 ? (uint)(m_processResourceUsage.Keys.Count - 1) : 0; // Exclude the root process from the child count
                }
                catch (OverflowException ex)
                {
                    LogProcessState($"Overflow exception caught while calculating AccountingInformation:{Environment.NewLine}{ex.ToString()}");

                    ioCounters = new IOCounters(new IO_COUNTERS()
                    {
                        ReadOperationCount  = 0,
                        WriteOperationCount = 0,
                        ReadTransferCount   = 0,
                        WriteTransferCount  = 0
                    });

                    memoryCounters = ProcessMemoryCounters.CreateFromBytes(0, 0, 0, 0);
                }

                return(new JobObject.AccountingInformation
                {
                    IO = ioCounters,
                    MemoryCounters = memoryCounters,
                    KernelTime = TimeSpan.FromMilliseconds(m_processResourceUsage.Aggregate(0.0, (acc, usage) => acc + usage.Value.SystemTimeNs) / NanosecondsToMillisecondsFactor),
                    UserTime = TimeSpan.FromMilliseconds(m_processResourceUsage.Aggregate(0.0, (acc, usage) => acc + usage.Value.UserTimeNs) / NanosecondsToMillisecondsFactor),
                    NumberOfProcesses = childProcesses,
                });
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Internal constructor
 /// </summary>
 /// <param name="processId">The process id of the process</param>
 /// <param name="processExecutable">The name of the executable that runs the process</param>
 /// <param name="processArgs">Process arguments</param>
 /// <param name="kernelTime">The amount of time the process spent executing kernel mode code</param>
 /// <param name="userTime">The amount of time the process spent executing user mode code</param>
 /// <param name="ioCounters">Input Output counters and byte transfer count for read, write and other</param>
 /// <param name="creationTime">The time (in UTC) that the process was created</param>
 /// <param name="exitTime">The time (in UTC) that the process exited</param>
 internal ProcessInstanceDescriptor(
     uint processId,
     string processExecutable,
     string processArgs,
     TimeSpan kernelTime,
     TimeSpan userTime,
     IOCounters ioCounters,
     DateTime creationTime,
     DateTime exitTime,
     uint exitCode,
     uint parentProcessId)
 {
     ProcessId         = processId;
     ProcessExecutable = processExecutable;
     ProcessArgs       = processArgs;
     KernelTime        = kernelTime;
     UserTime          = userTime;
     IO              = ioCounters;
     CreationTime    = creationTime;
     ExitTime        = exitTime;
     ExitCode        = exitCode;
     ParentProcessId = parentProcessId;
 }
Ejemplo n.º 5
0
            public static bool TryParse(
                string line,
                out uint processId,
                out string processName,
                out IOCounters ioCounters,
                out DateTime creationDateTime,
                out DateTime exitDateTime,
                out TimeSpan kernelTime,
                out TimeSpan userTime,
                out uint exitCode,
                out uint parentProcessId,
                out ulong detoursMaxHeapSizeInBytes,
                out uint manifestSizeInBytes,
                out ulong finalDetoursHeapSizeInBytes,
                out uint allocatedPoolEntries,
                out ulong maxHandleMapEntries,
                out ulong handleMapEntries,
                out string errorMessage)
            {
                processName               = default;
                parentProcessId           = 0;
                processId                 = 0;
                ioCounters                = default;
                creationDateTime          = default;
                exitDateTime              = default;
                kernelTime                = default;
                userTime                  = default;
                exitCode                  = ExitCodes.UninitializedProcessExitCode;
                detoursMaxHeapSizeInBytes = 0;
                errorMessage              = string.Empty;

                manifestSizeInBytes         = 0;
                finalDetoursHeapSizeInBytes = 0L;
                allocatedPoolEntries        = 0;
                maxHandleMapEntries         = 0L;
                handleMapEntries            = 0L;

                const int NumberOfEntriesInMessage = 24;

                var items = line.Split('|');

                // A "process data" report is expected to have exactly 15 items. 1 for the process id,
                // 1 for the command line (last item) and 12 numbers indicating the various counters and
                // execution times and 1 number for the parent process Id.
                // If this assert fires, it indicates that we could not successfully parse (split) the data being
                // sent from the detour (SendReport.cpp).
                // Make sure the strings are formatted only when the condition is false.
                if (items.Length != NumberOfEntriesInMessage)
                {
                    errorMessage = I($"Unexpected message items. Message'{line}'. Expected {NumberOfEntriesInMessage} items, Received {items.Length} items");
                    return(false);
                }

                processName = items[15];

                if (uint.TryParse(items[0], NumberStyles.None, CultureInfo.InvariantCulture, out processId) &&
                    ulong.TryParse(items[1], NumberStyles.None, CultureInfo.InvariantCulture, out var readOperationCount) &&
                    ulong.TryParse(items[2], NumberStyles.None, CultureInfo.InvariantCulture, out var writeOperationCount) &&
                    ulong.TryParse(items[3], NumberStyles.None, CultureInfo.InvariantCulture, out var otherOperationCount) &&
                    ulong.TryParse(items[4], NumberStyles.None, CultureInfo.InvariantCulture, out var readTransferCount) &&
                    ulong.TryParse(items[5], NumberStyles.None, CultureInfo.InvariantCulture, out var writeTransferCount) &&
                    ulong.TryParse(items[6], NumberStyles.None, CultureInfo.InvariantCulture, out var otherTransferCount) &&
                    uint.TryParse(items[7], NumberStyles.None, CultureInfo.InvariantCulture, out var creationHighDateTime) &&
                    uint.TryParse(items[8], NumberStyles.None, CultureInfo.InvariantCulture, out var creationLowDateTime) &&
                    uint.TryParse(items[9], NumberStyles.None, CultureInfo.InvariantCulture, out var exitHighDateTime) &&
                    uint.TryParse(items[10], NumberStyles.None, CultureInfo.InvariantCulture, out var exitLowDateTime) &&
                    uint.TryParse(items[11], NumberStyles.None, CultureInfo.InvariantCulture, out var kernelHighDateTime) &&
                    uint.TryParse(items[12], NumberStyles.None, CultureInfo.InvariantCulture, out var kernelLowDateTime) &&
                    uint.TryParse(items[13], NumberStyles.None, CultureInfo.InvariantCulture, out var userHighDateTime) &&
                    uint.TryParse(items[14], NumberStyles.None, CultureInfo.InvariantCulture, out var userLowDateTime) &&
                    uint.TryParse(items[16], NumberStyles.None, CultureInfo.InvariantCulture, out exitCode) &&
                    uint.TryParse(items[17], NumberStyles.None, CultureInfo.InvariantCulture, out parentProcessId) &&
                    ulong.TryParse(items[18], NumberStyles.None, CultureInfo.InvariantCulture, out detoursMaxHeapSizeInBytes) &&
                    uint.TryParse(items[19], NumberStyles.None, CultureInfo.InvariantCulture, out manifestSizeInBytes) &&
                    ulong.TryParse(items[20], NumberStyles.None, CultureInfo.InvariantCulture, out finalDetoursHeapSizeInBytes) &&
                    uint.TryParse(items[21], NumberStyles.None, CultureInfo.InvariantCulture, out allocatedPoolEntries) &&
                    ulong.TryParse(items[22], NumberStyles.None, CultureInfo.InvariantCulture, out maxHandleMapEntries) &&
                    ulong.TryParse(items[23], NumberStyles.None, CultureInfo.InvariantCulture, out handleMapEntries))
                {
                    long fileTime = creationHighDateTime;
                    fileTime         = fileTime << 32;
                    creationDateTime = DateTime.FromFileTimeUtc(fileTime + creationLowDateTime);

                    fileTime     = exitHighDateTime;
                    fileTime     = fileTime << 32;
                    exitDateTime = DateTime.FromFileTimeUtc(fileTime + exitLowDateTime);

                    fileTime   = kernelHighDateTime;
                    fileTime   = fileTime << 32;
                    fileTime  += kernelLowDateTime;
                    kernelTime = TimeSpan.FromTicks(fileTime);

                    fileTime  = userHighDateTime;
                    fileTime  = fileTime << 32;
                    fileTime += userLowDateTime;
                    userTime  = TimeSpan.FromTicks(fileTime);

                    ioCounters = new IOCounters(
                        new IOTypeCounters(readOperationCount, readTransferCount),
                        new IOTypeCounters(writeOperationCount, writeTransferCount),
                        new IOTypeCounters(otherOperationCount, otherTransferCount));
                    return(true);
                }

                return(false);
            }
Ejemplo n.º 6
0
 /// <inheritdoc/>
 public override void HandleProcessData(long pipId, string pipDescription, string processName, uint processId, DateTime creationDateTime, DateTime exitDateTime, TimeSpan kernelTime, TimeSpan userTime, uint exitCode, IOCounters ioCounters, uint parentProcessId)
 {
 }
Ejemplo n.º 7
0
        internal void AddPip(PipDescriptor pip, uint processId, string processArgs, TimeSpan kernelTime, TimeSpan userTime, IOCounters ioCounters, DateTime creationTime, DateTime exiTime, uint exitCode, uint parentProcessId)
        {
            ProcessInstanceDescriptor processInstance             = new ProcessInstanceDescriptor(processId, ProcessExecutable, processArgs, kernelTime, userTime, ioCounters, creationTime, exiTime, exitCode, parentProcessId);
            IReadOnlyCollection <ProcessInstanceDescriptor> items = PipsThatExecuteTheProcessDictionary.GetOrAdd(pip, (key) => new ConcurrentHashSet <ProcessInstanceDescriptor>());

            // This is pretty ugly: Doing down casting here so we can add elements to our read only collection
            // The collection is read only because we do no want to allow the Users of the SDK to change it. Unfortunately the only way .NET allows me to define such dictionary
            // is to specify its elements as a IReadOnlyCollection and down cast every time I need to modify it
            // Down casting here is pretty safe though. The collection is only created in this method and we know that it is always a ConcurrentDictionary.
            (items as ConcurrentHashSet <ProcessInstanceDescriptor>).Add(processInstance);
            pip.ReportedProcessesHashset.Add(processInstance);
        }
Ejemplo n.º 8
0
 internal static extern bool GetProcessIoCounters(SafeProcessHandle handle, out IOCounters counters);