Delphi MemoryProcessCMD  
官方Delphi 学习QQ群: 682628230(三千人)
频道

Delphi MemoryProcessCMD


    program MemoryProcessCMD;


    {* Based in Gant(https://stackoverflow.com/users/12460/gant) code*}



    {$APPTYPE CONSOLE}



    uses

  System.SysUtils,

  psapi,

  Windows;


procedure PrintMemoryInfo(processID: DWORD);

    var

      hProcess: THandle;

      pmc: PROCESS_MEMORY_COUNTERS;

      total: DWORD;


    begin


      // Print the process identifier.

      Writeln(format('Process ID: %d', [processID]));


      // Print information about the memory usage of the process.

      hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, FALSE,

        processID);


      if (hProcess = 0) then

      begin

        exit;

      end;


      if (GetProcessMemoryInfo(hProcess, @pmc, SizeOf(pmc))) then

      begin

        Writeln(format(#09'PageFaultCount: 0x%.8X', [pmc.PageFaultCount]));

        Writeln(format(#09'PeakWorkingSetSize: 0x%.8X', [pmc.PeakWorkingSetSize]));

        Writeln(format(#09'WorkingSetSize: 0x%.8X', [pmc.WorkingSetSize]));

        Writeln(format(#09'QuotaPeakPagedPoolUsage: 0x%.8X',

          [pmc.QuotaPeakPagedPoolUsage]));

        Writeln(format(#09'QuotaPagedPoolUsage: 0x%.8X',

          [pmc.QuotaPagedPoolUsage]));

        Writeln(format(#09'QuotaPeakNonPagedPoolUsage: 0x%.8X',

          [pmc.QuotaPeakNonPagedPoolUsage]));

        Writeln(format(#09'QuotaNonPagedPoolUsage: 0x%.8X',

          [pmc.QuotaNonPagedPoolUsage]));

        Writeln(format(#09'PagefileUsage: 0x%.8X', [pmc.PagefileUsage]));

        Writeln(format(#09'PeakPagefileUsage: 0x%.8X', [pmc.PeakPagefileUsage]));

        Writeln(format(#09'PagefileUsage: 0x%.8X', [pmc.PagefileUsage]));

      end;


      CloseHandle(hProcess);

    end;


    var

      aProcesses: array [0 .. 1024] of DWORD;

      cbNeeded, cProcesses: DWORD;

      i: Integer;


    begin

      try

        // Get the list of process identifiers.

        if (not EnumProcesses(@aProcesses, SizeOf(aProcesses), &cbNeeded)) then

          halt(1);


        // Calculate how many process identifiers were returned.

        cProcesses := cbNeeded div SizeOf(DWORD);


        // Print the memory usage for each process

        for i := 0 to cProcesses - 1 do

        begin

          PrintMemoryInfo(aProcesses[i]);

        end;

        Readln;

      except

        on E: Exception do

          Writeln(E.ClassName, ': ', E.Message);

      end;


    end.



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.037063121795654 seconds