Sign in to follow this  
Followers 0
Wanery

Read single Performance Counter

4 posts in this topic

Hello All,

I am new to the forum and AutoIt. I have a bit of computer exp., and, long before Object Oriented Programming some coding experience. (minimal help, these days)

I came upon AutoIt during a search for the solution to a problem with my internet camera server software, IPView Pro. While IPView uses an init file, and writes to it successfully, it ignores the setting to "resume previous recording state" on restart. Additionally, if there are any "burps" in the data stream from the camera, the software stops recording to disk. Of course, now that the Co. has my $300+, there is no tech support of any value. (suspect they have no clue)

To fix these problems, I thought I'd give AutoIt a go. I was able to schedule system tasks to run .au3 scripts, to both shut the application down in an orderly fashion (allowing it to write out any data to disk as opposed to tskill, taskkill , or whatever) and start it up and set the record function via the mouse control of AutoIt. (the IPView sftwr runs only full screen or minimized with only a GUI interface)

This worked out well, and it didn't really take that long to figure out how to do these basic tasks w/AutoIt. Kudos amd thanks to the author(s).

While I intially thought that the sofware was just hanging on the record function and a daily shutdown/restart would fix it, I was wrong. As I mentioned above, any glitch in the video stream stops the record function. I determined this by simultaneously recording on two PCs. They both cease to record at the same time.

So I decided I'd try write a script to monitor the data bytes written when recording (perfmon shows a significant drop, of course) and if the counter average dropped bigtime, I'd invoke my IPViewStart/Stop scripts. Searching the board, I found Ascend4nt's "_PDH_PerformanceCounters.au3". (pretty nice, must've been a TON of work!!) I've been working with it, cutting and pasting, and have gotten to the point where (using Ascend4nt's code) I can initialize PDH, get a query handle, set the query path to "\Process(IPView Pro)\IO Data Bytes/sec" (I think) but after that I'm lost. I looked at some of Ascend4nt's reference pages, but they're beyond my skill level. I've also been all over the AutoIt references & help file, and comparing to the C++ snipets given on technet, but I havn't been able to figure it out.

So can anyone help me learm to read a single performance counter or point me in the right direction? I can likely do the rest myself.

I tried this :

$aCntrVal=DllCall($_INT_PDH_hDLLHandle,"dword*","PdhGetFormattedCounterValue",$hPDHQueryHandle,"dword*")

Of course it returns"0". (don't laugh, at least it doesn't crash AutoIt.exe like many earlier attempts!)

Sorry for the long post, but at least I know what I'm trying to do and would appreciate any and all assistance.

Thanks to any and all,

Wanery

Share this post


Link to post
Share on other sites



If you look at the documentation for PdhGetFormattedCounterValue you'll see that the fourth parameter should be a pointer to a PDH_FMT_COUNTERVALUE struct that will recieve the data you want.

Therefore your DllCall should look something like:

Global Const $PDH_FMT_LARGE = 0x00000400
$s=DllStructCreate("dword CStatus;int64 union")
$call=DllCall("Pdh.dll","dword","PdhGetFormattedCounterValue","ptr",$_INT_PDH_hDLLHandle,"dword",$PDH_FMT_LARGE,"ptr",0,"ptr",DllStructGetPtr($s))

MsgBox(0,"",DllStructGetData($s,"union"))

I couldn't test it myself so it could be wrong.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Monoceres,

Thank you for the help. I've found a couple of articles in the MSDN 'Under the hood' series which I hope will make things clearer for me. My biggest prob is probably that I'm not a programmer, and looking at VB, VBS, JS, C, C++ etc. code is like reading Spanish to me. I get some but not all of it.

I was (I guess) trying to call the pdh.dll by handle, and I see your script calls it by name - much easier to comprehend. I also see that the data types preceed the variables, which I wasn't sure of. Must learn more data tyoes, MS has a LOT of them.

In your example, there's an item or two (ie., the 'union' part) I don't understand, but will research it and play with what you've suggested. Will let you know how it goes.

Thanks again,

Wanery

Share this post


Link to post
Share on other sites

It's better to call it with a handle, that way the dll doesn't get loaded/unloaded between the calls.

I made a small tutorial on working with dll's and dllstruct's in autoit a while ago. You can find it here.

Unions are a special case that's a bit hard to grasp if you're new to this.

Basically it's a regular struct but the memory is shared between the members, the total size of the unions is decided by the largest member.

So let's say we have this union:

union u
{
    char a; // char is 1 byte
    short b; // short is 2 bytes
    int c; // int is 4 bytes
    __int64 d; // __int64 is 8 bytes
};

The total size of the union would be 8 bytes since __int64 is the largest member in the struct.

If we want to use this union in autoit we will need to do it like this:

#cs
union u
{
    char a; // char is 1 byte
    short b; // short is 2 bytes
    int c; // int is 4 bytes
    __int64 d; // __int64 is 8 bytes
};
#ce
$struct=DllStructCreate("int64")

;Accessing the char (a)
$a=DllStructGetData(DllStructCreate("char",DllStructGetPtr($struct)),1)

; Accesing the short (b)
$b=DllStructGetData(DllStructCreate("short",DllStructGetPtr($struct)),1)

; Accessing the int (c)
$c=DllStructGetData(DllStructCreate("int",DllStructGetPtr($struct)),1)

; Accesing the __int64 (d)
$d=DllStructGetData($struct,1)

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0