Subject: | I not getting counter and instance |
I'm running Win32::PerfMon v0.07 on ActiveState Perl, v5.8.8 built for
MSWin32-x86-multi-thread build 820 [274739] trying to get a ListCounter
() and ListInstances() as like link (http://www.perlmonks.org/?
node_id=439313) without success.
By GetErrorText() I got the message "A required argument is invalid or
a reserved argument is not NULL.".
To solve this problem I sugest to use theses patch attached.
Subject: | PerfMon.xs |
Message body is not shown because it is too large.
Subject: | PerfMon.pm |
Message body is not shown because it is too large.
Subject: | Perfmon.pm.patch |
32c32
< our $VERSION = '0.07';
---
> our $VERSION = '0.08';
276,277c276
< unless(scalar(@_) == 2)
< {
---
> unless(scalar(@_) == 2) {
282,284c281
< my ($self, $Object) = @_;
<
< my $Data = list_counters($self->{'MACHINENAME'}, $Object, $self->{'ERRORMSG'});
---
> my ($self, $object) = @_;
286c283
< my @Counters = split(/\|/, $Data);
---
> my @counters = list_counters($self->{'MACHINENAME'}, $object, $self->{'ERRORMSG'});
288,289c285
< if($Counters[0] eq -1)
< {
---
> if( $counters[0] eq -1 ) {
292,294c288,289
< else
< {
< return(\@Counters);
---
> else {
> return(\@counters);
303,304c298
< unless(scalar(@_) == 2)
< {
---
> unless(scalar(@_) == 2) {
311c305
< my $Data = list_instances($self->{'MACHINENAME'}, $Object, $self->{'ERRORMSG'});
---
> my @Instances = list_instances($self->{'MACHINENAME'}, $Object, $self->{'ERRORMSG'});
313,317c307,308
< my @Instances = split(/\|/, $Data);
<
< if($Instances[0] eq -1)
< {
< return(-1);
---
> if ( $Instances[0] eq -1 ) {
> return( -1 );
319,321c310,311
< else
< {
< return(\@Instances);
---
> else {
> return( \@Instances );
Subject: | PerfMon.xs.patch |
26,27c26,27
< #include "PDH.h"
< #include "PDHMSG.h"
---
> #include "pdh.h"
> #include "pdhmsg.h"
525c525
< SV* pBox
---
> SV* pBox
528c528
<
---
>
529a530,575
> DWORD dwCounterListSize;
> DWORD dwInstanceListSize;
> PDH_STATUS pdhStatus;
> char* szCounterListBuffer;
> char* szInstanceListBuffer;
> char* szThisInstance;
> char* szBox;
> char* szObject;
> STRLEN len;
>
> PPCODE:
> dwCounterListSize = 0;
> dwInstanceListSize = 0;
> szCounterListBuffer = NULL;
> szInstanceListBuffer = NULL;
> len = sv_len(pBox);
> szBox = SvPV(pBox, len);
> len = sv_len(pObject);
> szObject = SvPV(pObject, len);
>
> pdhStatus = PdhEnumObjectItems( NULL,
> szBox,
> szObject,
> szCounterListBuffer,
> &dwCounterListSize,
> szInstanceListBuffer,
> &dwInstanceListSize,
> PERF_DETAIL_EXPERT,
> 0 );
> if ( pdhStatus == PDH_MORE_DATA )
> {
> Newxz(szCounterListBuffer, (int) dwCounterListSize , char );
> Newxz(szInstanceListBuffer, (int) dwInstanceListSize, char );
>
> if (( szCounterListBuffer != NULL ) &&
> ( szInstanceListBuffer != NULL ))
> {
> pdhStatus = PdhEnumObjectItems( NULL,
> szBox,
> szObject,
> szCounterListBuffer,
> &dwCounterListSize,
> szInstanceListBuffer,
> &dwInstanceListSize,
> PERF_DETAIL_EXPERT,
> 0 );
531,571c577
< DWORD dwSize;
< DWORD dwSize1;
< PDH_STATUS stat;
< char* szBuffer;
< char* szBuffer2;
< char* szBox;
< char* szObject;
< char* c;
< STRLEN len;
< STRLEN len2;
< int index;
<
< PPCODE:
<
< dwSize = 0;
< dwSize1 = 0;
< szBuffer = NULL;
< szBuffer2 = NULL;
< len = sv_len(pBox);
< szBox = SvPV(pBox, len);
<
< len2 = sv_len(pObject);
< szObject = SvPV(pObject, len2);
<
< stat = PdhEnumObjects(NULL, szBox, NULL, &dwSize, PERF_DETAIL_EXPERT, 1);
<
< dwSize = 0;
<
< stat = PdhEnumObjectItems(NULL, szBox, szObject, szBuffer, &dwSize, szBuffer2, &dwSize1, PERF_DETAIL_EXPERT, 0);
<
< dwSize += 5;
<
< Newz(0, szBuffer, (int)dwSize, char);
<
< stat = PdhEnumObjectItems(NULL, szBox, szObject, szBuffer, &dwSize, szBuffer2, &dwSize1, PERF_DETAIL_EXPERT, 0);
<
< c = szBuffer;
<
< for(index=0; index<(int)dwSize; index++)
< {
< if(*c == 0x00)
---
> if ( pdhStatus == ERROR_SUCCESS )
573c579,584
< *c = '|';
---
> for ( szThisInstance = szCounterListBuffer;
> *szThisInstance != 0;
> szThisInstance += lstrlen(szThisInstance) + 1)
> {
> XPUSHs (sv_2mortal ( newSVpv(szThisInstance, 0) ) );
> }
575,576d585
<
< c++;
578,579c587
<
< switch(stat)
---
> else
581,606c589,591
< case ERROR_SUCCESS:
<
< XPUSHs(sv_2mortal(newSVpv(szBuffer, 0)));
<
< break;
<
< case PDH_MORE_DATA:
<
< printf("There are more entries available to return than there is room in the buffer\n");
< XPUSHs(sv_2mortal(newSViv(-1)));
<
< break;
<
< case PDH_MEMORY_ALLOCATION_FAILURE:
<
< sv_setpv(pError, "A required temporary buffer could not be allocated.\n");
< XPUSHs(sv_2mortal(newSViv(-1)));
<
< break;
<
< case PDH_INVALID_ARGUMENT:
<
< sv_setpv(pError, "A required argument is invalid or a reserved argument is not NULL.\n");
< XPUSHs(sv_2mortal(newSViv(-1)));
<
< break;
---
> pdhStatus = PDH_MEMORY_ALLOCATION_FAILURE;
> }
> }
608c593,596
< case PDH_CSTATUS_NO_MACHINE:
---
> switch( pdhStatus )
> {
> case ERROR_SUCCESS:
> break;
610,611c598,601
< sv_setpv(pError, "The specified computer is offline or unavailable.\n");
< XPUSHs(sv_2mortal(newSViv(-1)));
---
> case PDH_MEMORY_ALLOCATION_FAILURE:
> sv_setpv(pError, "A required temporary buffer could not be allocated.\n");
> XPUSHs(sv_2mortal(newSViv(-1)));
> break;
613c603,606
< break;
---
> case PDH_INVALID_ARGUMENT:
> sv_setpv(pError, "A required argument is invalid or a reserved argument is not NULL.\n");
> XPUSHs(sv_2mortal(newSViv(-1)));
> break;
615c608,611
< case PDH_CSTATUS_NO_OBJECT:
---
> case PDH_CSTATUS_NO_MACHINE:
> sv_setpv(pError, "The specified computer is offline or unavailable.\n");
> XPUSHs(sv_2mortal(newSViv(-1)));
> break;
617,618c613,616
< sv_setpv(pError, "The specified object could not be found on the specified computer.\n");
< XPUSHs(sv_2mortal(newSViv(-1)));
---
> case PDH_CSTATUS_NO_OBJECT:
> sv_setpv(pError, "The specified object could not be found on the specified computer.\n");
> XPUSHs(sv_2mortal(newSViv(-1)));
> break;
620c618,621
< break;
---
> default:
> sv_setpv(pError, "I have no idea what went wrong\n");
> XPUSHs(sv_2mortal(newSViv(-1)));
> }
622c623,624
< default:
---
> Safefree(szCounterListBuffer);
> Safefree(szInstanceListBuffer);
624,628d625
< sv_setpv(pError, "I have no idea what went wrong\n");
< XPUSHs(sv_2mortal(newSViv(-1)));
< }
<
< Safefree(szBuffer);
632c629
< SV* pBox
---
> SV* pBox
636a634,680
> DWORD dwCounterListSize;
> DWORD dwInstanceListSize;
> PDH_STATUS pdhStatus;
> char* szCounterListBuffer;
> char* szInstanceListBuffer;
> char* szThisInstance;
> char* szBox;
> char* szObject;
> STRLEN len;
>
> PPCODE:
> dwCounterListSize = 0;
> dwInstanceListSize = 0;
> szCounterListBuffer = NULL;
> szInstanceListBuffer = NULL;
> len = sv_len(pBox);
> szBox = SvPV(pBox, len);
> len = sv_len(pObject);
> szObject = SvPV(pObject, len);
>
> pdhStatus = PdhEnumObjectItems( NULL,
> szBox,
> szObject,
> szCounterListBuffer,
> &dwCounterListSize,
> szInstanceListBuffer,
> &dwInstanceListSize,
> PERF_DETAIL_EXPERT,
> 0 );
>
> if ( pdhStatus == PDH_MORE_DATA )
> {
> Newxz(szCounterListBuffer, (int) dwCounterListSize , char );
> Newxz(szInstanceListBuffer, (int) dwInstanceListSize, char );
>
> if (( szCounterListBuffer != NULL ) &&
> ( szInstanceListBuffer != NULL ))
> {
> pdhStatus = PdhEnumObjectItems( NULL,
> szBox,
> szObject,
> szCounterListBuffer,
> &dwCounterListSize,
> szInstanceListBuffer,
> &dwInstanceListSize,
> PERF_DETAIL_EXPERT,
> 0 );
638,678c682
< DWORD dwSize;
< DWORD dwSize1;
< PDH_STATUS stat;
< char* szBuffer;
< char* szBuffer2;
< char* szBox;
< char* szObject;
< char* c;
< STRLEN len;
< STRLEN len2;
< int index;
<
< PPCODE:
<
< dwSize = 0;
< dwSize1 = 0;
< szBuffer = NULL;
< szBuffer2 = NULL;
< len = sv_len(pBox);
< szBox = SvPV(pBox, len);
<
< len2 = sv_len(pObject);
< szObject = SvPV(pObject, len2);
<
< stat = PdhEnumObjects(NULL, szBox, NULL, &dwSize, PERF_DETAIL_EXPERT, 1);
<
< dwSize = 0;
<
< stat = PdhEnumObjectItems(NULL, szBox, szObject, szBuffer, &dwSize, szBuffer2, &dwSize1, PERF_DETAIL_EXPERT, 0);
<
< dwSize1 += 5;
<
< Newz(0, szBuffer2, (int)dwSize1, char);
<
< stat = PdhEnumObjectItems(NULL, szBox, szObject, szBuffer, &dwSize, szBuffer2, &dwSize1, PERF_DETAIL_EXPERT, 0);
<
< c = szBuffer2;
<
< for(index=0; index<(int)dwSize1; index++)
< {
< if(*c == 0x00)
---
> if ( pdhStatus == ERROR_SUCCESS )
680c684,689
< *c = '|';
---
> for ( szThisInstance = szInstanceListBuffer;
> *szThisInstance != 0;
> szThisInstance += lstrlen(szThisInstance) + 1)
> {
> XPUSHs (sv_2mortal ( newSVpv(szThisInstance, 0) ) );
> }
682,683d690
<
< c++;
685,686c692
<
< switch(stat)
---
> else
688,718c694,696
< case ERROR_SUCCESS:
<
< XPUSHs(sv_2mortal(newSVpv(szBuffer2, 0)));
<
< break;
<
< case PDH_MORE_DATA:
<
< printf("There are more entries available to return than there is room in the buffer\n");
< XPUSHs(sv_2mortal(newSViv(-1)));
<
< break;
<
< case PDH_MEMORY_ALLOCATION_FAILURE:
<
< sv_setpv(pError, "A required temporary buffer could not be allocated.\n");
< XPUSHs(sv_2mortal(newSViv(-1)));
<
< break;
<
< case PDH_INVALID_ARGUMENT:
<
< sv_setpv(pError, "A required argument is invalid or a reserved argument is not NULL.\n");
< XPUSHs(sv_2mortal(newSViv(-1)));
<
< break;
<
< case PDH_CSTATUS_NO_MACHINE:
<
< sv_setpv(pError, "The specified computer is offline or unavailable.\n");
< XPUSHs(sv_2mortal(newSViv(-1)));
---
> pdhStatus = PDH_MEMORY_ALLOCATION_FAILURE;
> }
> }
720c698,701
< break;
---
> switch( pdhStatus )
> {
> case ERROR_SUCCESS:
> break;
722c703,706
< case PDH_CSTATUS_NO_OBJECT:
---
> case PDH_MEMORY_ALLOCATION_FAILURE:
> sv_setpv(pError, "A required temporary buffer could not be allocated.\n");
> XPUSHs(sv_2mortal(newSViv(-1)));
> break;
724,725c708,711
< sv_setpv(pError, "The specified object could not be found on the specified computer.\n");
< XPUSHs(sv_2mortal(newSViv(-1)));
---
> case PDH_INVALID_ARGUMENT:
> sv_setpv(pError, "A required argument is invalid or a reserved argument is not NULL.\n");
> XPUSHs(sv_2mortal(newSViv(-1)));
> break;
727c713,716
< break;
---
> case PDH_CSTATUS_NO_MACHINE:
> sv_setpv(pError, "The specified computer is offline or unavailable.\n");
> XPUSHs(sv_2mortal(newSViv(-1)));
> break;
729c718,721
< default:
---
> case PDH_CSTATUS_NO_OBJECT:
> sv_setpv(pError, "The specified object could not be found on the specified computer.\n");
> XPUSHs(sv_2mortal(newSViv(-1)));
> break;
731,733c723,726
< sv_setpv(pError, "I have no idea what went wrong\n");
< XPUSHs(sv_2mortal(newSViv(-1)));
< }
---
> default:
> sv_setpv(pError, "I have no idea what went wrong\n");
> XPUSHs(sv_2mortal(newSViv(-1)));
> }
735c728,729
< Safefree(szBuffer2);
---
> Safefree(szCounterListBuffer);
> Safefree(szInstanceListBuffer);