Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. %CPU and Memory footprint question

%CPU and Memory footprint question

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++toolsperformance
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    ben2
    wrote on last edited by
    #1

    In a multithreaded VC++ program, how can I find %of CPU/ thread from within the program and report it? Also how can I find the memory footprint of the process from within the program? Is it possible? (Not using any external tools like perfmon, just using C++ code from the program itself)

    M 1 Reply Last reply
    0
    • B ben2

      In a multithreaded VC++ program, how can I find %of CPU/ thread from within the program and report it? Also how can I find the memory footprint of the process from within the program? Is it possible? (Not using any external tools like perfmon, just using C++ code from the program itself)

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      For memory usage check out GetProcessMemoryInfo() (NT 4 or later) --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."   -- Buffy

      B 1 Reply Last reply
      0
      • M Michael Dunn

        For memory usage check out GetProcessMemoryInfo() (NT 4 or later) --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."   -- Buffy

        B Offline
        B Offline
        ben2
        wrote on last edited by
        #3

        Thanks. How to find the %CPU/thread? HANDLE hProcess; PROCESS_MEMORY_COUNTERS pmc; DWORD processID = GetCurrentProcessId (); hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); if (NULL == hProcess) return; if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) { printf( "\tPeakWorkingSetSize: 0x%08X\n", pmc.PeakWorkingSetSize ); }

        B 1 Reply Last reply
        0
        • B ben2

          Thanks. How to find the %CPU/thread? HANDLE hProcess; PROCESS_MEMORY_COUNTERS pmc; DWORD processID = GetCurrentProcessId (); hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); if (NULL == hProcess) return; if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) { printf( "\tPeakWorkingSetSize: 0x%08X\n", pmc.PeakWorkingSetSize ); }

          B Offline
          B Offline
          ben2
          wrote on last edited by
          #4

          I found that using PDH these can be done. Was wondering if this can be done for individual processes, from within the program. HQUERY m_hQuery; // the query to the PDH PdhOpenQuery(NULL, 1, &m_hQuery); PdhAddCounter(....) How to use above function for individual processes?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups