VenMon - PC Monitoring Software

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
Ventural
User
User
Posts: 26
Joined: Mon Jul 17, 2017 3:51 am
Location: Cocoa Beach, FL
Contact:

Re: VenMon - PC Monitoring Software

Post by Ventural »

Lord wrote:Hm, nothing changed here. Still got CPU at 0%.
Wow! You must have an amazing cpu. For some reason, its not picking up Process / Handles / Threads on your computer. I loaded Windows 10 in a virtual computer, changed it to German (Deutschland) and ran the cpu code above and that is what I got: https://i.imgur.com/In89niK.png

Then I ran Venmon 2.16 in Purebasic and it works there too: https://i.imgur.com/Pe4wCQw.png

Will borrow a computer with Windows 7 Ultimate x64 so I change languages and to test some more in the next day or two.
Lord wrote:Another thought: I got one CPU with 4 cores, so tab "Processors" should display "Core x" instead of "CPU x".
Or do I have 4 CPU and I didn't realized 'til now? :wink:
That would maybe explain the low CPU load? :D
I wasn't sure if I should go with Cores or CPUs. I originally had "Cores", but I then started getting emails from AMD users that they didn't have a Intel "Core" chip, I couldn't tell if they were upset or just confused :D so I switched it to "CPU" for now.

Edit: I just noticed in Windows 10, they use "CPU 0", "CPU 1", "CPU 2", etc. in Task Manager when you mouse over each graph: https://i.imgur.com/Tu4flE0.png I guess I'll keep it the same as Windows.
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: VenMon - PC Monitoring Software

Post by Lord »

Ventural wrote: I wasn't sure if I should go with Cores or CPUs. I originally had "Cores", but I then started getting emails from AMD users that they didn't have a Intel "Core" chip, I couldn't tell if they were upset or just confused :D so I switched it to "CPU" for now.
...
:?: :?: :?:
Even AMD calls it "cores":
Image
Cores are internal parts of a CPU.

Win7 Task-Manager doesn't have label for each core:
Image
Image
Ventural
User
User
Posts: 26
Joined: Mon Jul 17, 2017 3:51 am
Location: Cocoa Beach, FL
Contact:

Re: VenMon - PC Monitoring Software

Post by Ventural »

Hmm, guess the next question would be... If you have a Core i7-7700 processor that has four cores + hyper-threading that shows up as eight threads in Task Manager. Would that be considered eight "Cores"?

Intel i7-7700 Product Page: https://ark.intel.com/products/97128/
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: VenMon - PC Monitoring Software

Post by Lord »

Ventural wrote:Hmm, guess the next question would be... If you have a Core i7-7700 processor that has four cores + hyper-threading that shows up as eight threads in Task Manager. Would that be considered eight "Cores"?

Intel i7-7700 Product Page: https://ark.intel.com/products/97128/
No, its one CPU with 4 cores, two threads on each core.
But remember: look at my signature. :wink:
Image
Ventural
User
User
Posts: 26
Joined: Mon Jul 17, 2017 3:51 am
Location: Cocoa Beach, FL
Contact:

Re: VenMon - PC Monitoring Software

Post by Ventural »

Lord wrote:Hm, nothing changed here. Still got CPU at 0%.
Customer brought in a computer today because it was running very slow with a Core i7 on Windows 7 Home. I noticed that Venmon was not reading the processor usage. I opened up the built-in Windows Performance Monitor tool and it had errors. Opened up registry and went to:

Code: Select all

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009
and noticed that "Counter" key was blank or had a ton of blank lines in it. Did some research on it and found that you can rebuild the Windows Performance Counters registry by opening Command Prompt with Administrative privileges and type:

Code: Select all

cd c:\windows\system32
lodctr /R
cd c:\windows\syswow64
lodctr /R
I rebooted after this, but not sure if that was necessary. Afterwards both Venmon and Windows Performance Monitor were able to recognize cpu % usage.
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: VenMon - PC Monitoring Software

Post by Lord »

Ventural wrote:
Lord wrote:Hm, nothing changed here. Still got CPU at 0%.
Customer brought in a computer today because it was running very slow with a Core i7 on Windows 7 Home. I noticed that Venmon was not reading the processor usage. I opened up the built-in Windows Performance Monitor tool and it had errors. ...
I'm sorry, but my system runs fine and the built-in Windows Performance Monitor shows correct data.
Image
Ventural
User
User
Posts: 26
Joined: Mon Jul 17, 2017 3:51 am
Location: Cocoa Beach, FL
Contact:

Re: VenMon - PC Monitoring Software

Post by Ventural »

ok, so you did those steps and it still doesn't work?

I've been working on a solution for you for awhile now. I just happened to run across a computer with the same symptoms that you mentioned and was hoping that would fix it.
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: VenMon - PC Monitoring Software

Post by Lord »

Sorry, but still doesn't work.
Image
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: VenMon - PC Monitoring Software

Post by Dude »

Ventural wrote:QueryPerformanceCounter_ and QueryPerformanceFrequency_ = Uptime
Do you mind (please) sharing your equation for this? Every uptime equation I've seen is either too slow, gives incorrect results, or doesn't work on all versions of Windows. Thanks!
Ventural
User
User
Posts: 26
Joined: Mon Jul 17, 2017 3:51 am
Location: Cocoa Beach, FL
Contact:

Re: VenMon - PC Monitoring Software

Post by Ventural »

The results of up time vary between PC to PC. The up time is suppose to match the one shown in the Windows Task Manager. Here's the computers I tested on just now:

Mini screenshots. VenMon program on top, task manger time below.

Image

I'm sure there are ways to get a more accurate time, but I went with the simple solution:

Code: Select all

QPC.q         ;QueryPerformanceCounter_ Output
QPF.q         ;QueryPerformanceFrequency_ Output
UP_Days.q     ;Uptime in Days
UP_Hour.q     ;Uptime in Hours
UP_Mins.q     ;Uptime in Minutes
UP_Secs.q     ;Uptime in Seconds
DisplayText.s ;Output to Debug / Screen

Repeat
  If QueryPerformanceCounter_(@QPC)   ;Run If OS supports it. Windows 2000+
    QueryPerformanceFrequency_(@QPF)
    UP_Secs = QPC / QPF               ;Returns seconds
    UP_Days = UP_Secs / 86400         ;Days Uptime
    UP_Secs - (UP_Days * 86400)       ;Subtract days
    UP_Hour = UP_Secs / 3600          ;Hours Uptime
    UP_Secs - (UP_Hour * 3600)        ;Subtract hours
    UP_Mins = UP_Secs / 60            ;Minutes Uptime
    UP_Secs - (UP_Mins * 60)          ;Seconds Uptime
    If UP_Days > 0 
      DisplayText = Str(UP_Days) + "d "
    Else
      DisplayText = ""
    EndIf
    If UP_Hour > 0 
      DisplayText + Str(UP_Hour) + "h "
    EndIf
    If UP_Mins > 0 
      DisplayText + Str(UP_Mins) + "m "
    EndIf
    Debug DisplayText + Str(UP_Secs) + "s"
  EndIf
  Delay(1000)  
ForEver
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: VenMon - PC Monitoring Software

Post by Dude »

Hmm, thanks, but I tried it but it doesn't match my Win 7 Task Manager at all:

Image

I did reboot my PC 4 days ago, not 11 like your code says. That's what I mean when I say that I can never find a fast working solution. :(
Ventural
User
User
Posts: 26
Joined: Mon Jul 17, 2017 3:51 am
Location: Cocoa Beach, FL
Contact:

Re: VenMon - PC Monitoring Software

Post by Ventural »

Hmm... I never seen it off by that much. Interesting. If you type in Command Prompt:

Code: Select all

systeminfo | find "Boot Time" 
Does it show boot up from 4 or 11 days ago?
Ventural
User
User
Posts: 26
Joined: Mon Jul 17, 2017 3:51 am
Location: Cocoa Beach, FL
Contact:

Re: VenMon - PC Monitoring Software

Post by Ventural »

Threw this together real quick. Getting up time from Performance Monitor. This may not be reliable on all computers.

Code: Select all

Prototype PdhLookupPerfNameByIndex(szMachineName.s, dwNameIndex.l, *szNameBuffer, *pcchNameBufferSize)
Global PdhLookupPerfNameByIndex.PdhLookupPerfNameByIndex, MemSize.l

UP_Days.q     ;Uptime in Days
UP_Hour.q     ;Uptime in Hours
UP_Mins.q     ;Uptime in Minutes
UP_Secs.q     ;Uptime in Seconds
DisplayText.s ;Output to Debug / Screen

Structure PDH_FMT_COUNTERVALUE
  CStatus.l; As Long
  ;'  case Cardinal of
  ;'    0: (longValue: Integer);
  ;'    1: (doubleValue: Double);
  ;'    2: (largeValue: Int64);
  ;'    3: (AnsiStringValue: PChar);
  ;'    4: (WideStringValue: PWideChar);
  padding.l; As Long
  ulValueLow.l; As Long
  ulValueHigh.l; As Long
EndStructure
  
#PerformanceLib = 8888 ;Temp #

If OpenLibrary(#PerformanceLib, "pdh.dll")
CompilerIf #PB_Compiler_Unicode
  PdhLookupPerfNameByIndex = GetFunction(#PerformanceLib, "PdhLookupPerfNameByIndexW")
CompilerElse
  PdhLookupPerfNameByIndex = GetFunction(#PerformanceLib, "PdhLookupPerfNameByIndexA")
CompilerEndIf
EndIf 

hQuery.l
hCounter.l

RESULT.q = PdhOpenQuery_( 0, 1, @hQuery )
RESULT = PdhAddCounter_(hQuery, "\2\674", 0, @hCounter)

retcode.d
lpValue.PDH_FMT_COUNTERVALUE

RESULT = PdhCollectQueryData_(hQuery) ;Init
Delay(250)
Debug "--- Begin ---"

Repeat
  RESULT = PdhCollectQueryData_(hQuery)
  PdhGetFormattedCounterValue_(hCounter, $200 | $8000, @dwType.l, @lpValue)
  CopyMemory(@lpValue\ulValueLow, @retcode, 8)
  UP_Secs = Retcode                 ;Returns seconds
  UP_Days = UP_Secs / 86400         ;Days Uptime
  UP_Secs - (UP_Days * 86400)       ;Subtract days
  UP_Hour = UP_Secs / 3600          ;Hours Uptime
  UP_Secs - (UP_Hour * 3600)        ;Subtract hours
  UP_Mins = UP_Secs / 60            ;Minutes Uptime
  UP_Secs - (UP_Mins * 60)          ;Seconds Uptime
  If UP_Days > 0 
    DisplayText = Str(UP_Days) + "d "
  Else
    DisplayText = ""
  EndIf
  If UP_Hour > 0 
    DisplayText + Str(UP_Hour) + "h "
  EndIf
  If UP_Mins > 0 
    DisplayText + Str(UP_Mins) + "m "
  EndIf
  Debug Str(Retcode) + " = " + DisplayText + Str(UP_Secs) + "s"    
  Delay(1000)
ForEver
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: VenMon - PC Monitoring Software

Post by Dude »

Ventural wrote:

Code: Select all

systeminfo | find "Boot Time" 
Does it show boot up from 4 or 11 days ago?
It shows from 4 days ago, which is correct:

Image
Ventural wrote:Threw this together real quick. Getting up time from Performance Monitor. This may not be reliable on all computers.
This works, and matches both Task Manager and "systeminfo". :D But in what way is it unreliable? I'm hesitant to use it in that case. :(

Is there really no 100% reliable solution for all PCs? Like I said, I've never seen one, and your Venmon uptime code will be wrong for me, unless you update it with your new code above... but then that new code will be unreliable on someone else's Windows. Getting the correct uptime on any given PC seems to be a real problem.

I could calc the time difference between now and the result of "boot time" from "systeminfo", but that brings the slowness that I mentioned in my post further back. Nobody wants to wait 10 seconds or more to see their uptime... it has to be realtime.
Ventural
User
User
Posts: 26
Joined: Mon Jul 17, 2017 3:51 am
Location: Cocoa Beach, FL
Contact:

Re: VenMon - PC Monitoring Software

Post by Ventural »

This works, and matches both Task Manager and "systeminfo". :D But in what way is it unreliable? I'm hesitant to use it in that case. :(
It's rare, but I've seen where a user's Performance Counters data has been corrupted in the registry or disabled. Sometimes its an easy fix by pointing them to websites such: Solarwinds Website or Microsoft Support and get them to reset it. Other times I can't figure out why their system won't retrieve the Performance Counters data. I've had some people say an first version of Windows 10 (build 1507?) didn't work right on old hardware, but once they updated Windows 10, all was good.

You can always add more code.

Code: Select all

RESULT.q = PdhOpenQuery_( 0, 1, @hQuery )

Debug Result
Debug hQuery

If result = #ERROR_SUCCESS
  Debug "Good!"
  ;Put rest of Performance Counter Code here?
  ;Put more code in to test results before displaying them
Else
  Debug "Uh oh!"
  ;https://docs.microsoft.com/en-us/windows/desktop/PerfCtrs/pdh-error-codes
  ;Insert Alternate Code?
EndIf
Post Reply