From c8b68430f01c0750ec5e2f281c82c1dd059b5b4b Mon Sep 17 00:00:00 2001 From: Vlasta Hajek Date: Tue, 29 May 2018 20:34:00 +0200 Subject: [PATCH] Fix struct alignment in win_perf_counters for 32-bit 386 arch (#4206) --- plugins/inputs/win_perf_counters/pdh.go | 82 ------------ plugins/inputs/win_perf_counters/pdh_386.go | 121 ++++++++++++++++++ plugins/inputs/win_perf_counters/pdh_amd64.go | 114 +++++++++++++++++ 3 files changed, 235 insertions(+), 82 deletions(-) create mode 100644 plugins/inputs/win_perf_counters/pdh_386.go create mode 100644 plugins/inputs/win_perf_counters/pdh_amd64.go diff --git a/plugins/inputs/win_perf_counters/pdh.go b/plugins/inputs/win_perf_counters/pdh.go index edf6d0651..f637eb256 100644 --- a/plugins/inputs/win_perf_counters/pdh.go +++ b/plugins/inputs/win_perf_counters/pdh.go @@ -161,88 +161,6 @@ type ( PDH_HCOUNTER HANDLE // counter handle ) -// Union specialization for double values -type PDH_FMT_COUNTERVALUE_DOUBLE struct { - CStatus uint32 - DoubleValue float64 -} - -// Union specialization for 64 bit integer values -type PDH_FMT_COUNTERVALUE_LARGE struct { - CStatus uint32 - LargeValue int64 -} - -// Union specialization for long values -type PDH_FMT_COUNTERVALUE_LONG struct { - CStatus uint32 - LongValue int32 - padding [4]byte -} - -// Union specialization for double values, used by PdhGetFormattedCounterArrayDouble() -type PDH_FMT_COUNTERVALUE_ITEM_DOUBLE struct { - SzName *uint16 // pointer to a string - FmtValue PDH_FMT_COUNTERVALUE_DOUBLE -} - -// Union specialization for 'large' values, used by PdhGetFormattedCounterArrayLarge() -type PDH_FMT_COUNTERVALUE_ITEM_LARGE struct { - SzName *uint16 // pointer to a string - FmtValue PDH_FMT_COUNTERVALUE_LARGE -} - -// Union specialization for long values, used by PdhGetFormattedCounterArrayLong() -type PDH_FMT_COUNTERVALUE_ITEM_LONG struct { - SzName *uint16 // pointer to a string - FmtValue PDH_FMT_COUNTERVALUE_LONG -} - -//PDH_COUNTER_INFO structure contains information describing the properties of a counter. This information also includes the counter path. -type PDH_COUNTER_INFO struct { - //Size of the structure, including the appended strings, in bytes. - DwLength uint32 - //Counter type. For a list of counter types, see the Counter Types section of the Windows Server 2003 Deployment Kit. - //The counter type constants are defined in Winperf.h. - DwType uint32 - //Counter version information. Not used. - CVersion uint32 - //Counter status that indicates if the counter value is valid. For a list of possible values, - //see Checking PDH Interface Return Values. - CStatus uint32 - //Scale factor to use when computing the displayable value of the counter. The scale factor is a power of ten. - //The valid range of this parameter is PDH_MIN_SCALE (–7) (the returned value is the actual value times 10–⁷) to - //PDH_MAX_SCALE (+7) (the returned value is the actual value times 10⁺⁷). A value of zero will set the scale to one, so that the actual value is returned - LScale int32 - //Default scale factor as suggested by the counter's provider. - LDefaultScale int32 - //The value passed in the dwUserData parameter when calling PdhAddCounter. - DwUserData *uint32 - //The value passed in the dwUserData parameter when calling PdhOpenQuery. - DwQueryUserData *uint32 - //Null-terminated string that specifies the full counter path. The string follows this structure in memory. - SzFullPath *uint16 // pointer to a string - //Null-terminated string that contains the name of the computer specified in the counter path. Is NULL, if the path does not specify a computer. - //The string follows this structure in memory. - SzMachineName *uint16 // pointer to a string - //Null-terminated string that contains the name of the performance object specified in the counter path. The string follows this structure in memory. - SzObjectName *uint16 // pointer to a string - //Null-terminated string that contains the name of the object instance specified in the counter path. Is NULL, if the path does not specify an instance. - //The string follows this structure in memory. - SzInstanceName *uint16 // pointer to a string - //Null-terminated string that contains the name of the parent instance specified in the counter path. Is NULL, if the path does not specify a parent instance. - //The string follows this structure in memory. - SzParentInstance *uint16 // pointer to a string - //Instance index specified in the counter path. Is 0, if the path does not specify an instance index. - DwInstanceIndex uint32 // pointer to a string - //Null-terminated string that contains the counter name. The string follows this structure in memory. - SzCounterName *uint16 // pointer to a string - //Help text that describes the counter. Is NULL if the source is a log file. - SzExplainText *uint16 // pointer to a string - //Start of the string data that is appended to the structure. - DataBuffer *uint32 // pointer to an extra space -} - var ( // Library libpdhDll *syscall.DLL diff --git a/plugins/inputs/win_perf_counters/pdh_386.go b/plugins/inputs/win_perf_counters/pdh_386.go new file mode 100644 index 000000000..134d15c8d --- /dev/null +++ b/plugins/inputs/win_perf_counters/pdh_386.go @@ -0,0 +1,121 @@ +// Copyright (c) 2010 The win Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// This is the official list of 'win' authors for copyright purposes. +// +// Alexander Neumann +// Joseph Watson +// Kevin Pors + +// +build windows + +package win_perf_counters + +// Union specialization for double values +type PDH_FMT_COUNTERVALUE_DOUBLE struct { + CStatus uint32 + padding [4]byte + DoubleValue float64 +} + +// Union specialization for 64 bit integer values +type PDH_FMT_COUNTERVALUE_LARGE struct { + CStatus uint32 + padding [4]byte + LargeValue int64 +} + +// Union specialization for long values +type PDH_FMT_COUNTERVALUE_LONG struct { + CStatus uint32 + LongValue int32 + padding [4]byte +} + +type PDH_FMT_COUNTERVALUE_ITEM_DOUBLE struct { + SzName *uint16 + padding [4]byte + FmtValue PDH_FMT_COUNTERVALUE_DOUBLE +} + +// Union specialization for 'large' values, used by PdhGetFormattedCounterArrayLarge() +type PDH_FMT_COUNTERVALUE_ITEM_LARGE struct { + SzName *uint16 // pointer to a string + padding [4]byte + FmtValue PDH_FMT_COUNTERVALUE_LARGE +} + +// Union specialization for long values, used by PdhGetFormattedCounterArrayLong() +type PDH_FMT_COUNTERVALUE_ITEM_LONG struct { + SzName *uint16 // pointer to a string + padding [4]byte + FmtValue PDH_FMT_COUNTERVALUE_LONG +} + +//PDH_COUNTER_INFO structure contains information describing the properties of a counter. This information also includes the counter path. +type PDH_COUNTER_INFO struct { + //Size of the structure, including the appended strings, in bytes. + DwLength uint32 + //Counter type. For a list of counter types, see the Counter Types section of the Windows Server 2003 Deployment Kit. + //The counter type constants are defined in Winperf.h. + DwType uint32 + //Counter version information. Not used. + CVersion uint32 + //Counter status that indicates if the counter value is valid. For a list of possible values, + //see Checking PDH Interface Return Values. + CStatus uint32 + //Scale factor to use when computing the displayable value of the counter. The scale factor is a power of ten. + //The valid range of this parameter is PDH_MIN_SCALE (–7) (the returned value is the actual value times 10–⁷) to + //PDH_MAX_SCALE (+7) (the returned value is the actual value times 10⁺⁷). A value of zero will set the scale to one, so that the actual value is returned + LScale int32 + //Default scale factor as suggested by the counter's provider. + LDefaultScale int32 + //The value passed in the dwUserData parameter when calling PdhAddCounter. + DwUserData *uint32 + //The value passed in the dwUserData parameter when calling PdhOpenQuery. + DwQueryUserData *uint32 + //Null-terminated string that specifies the full counter path. The string follows this structure in memory. + SzFullPath *uint16 // pointer to a string + //Null-terminated string that contains the name of the computer specified in the counter path. Is NULL, if the path does not specify a computer. + //The string follows this structure in memory. + SzMachineName *uint16 // pointer to a string + //Null-terminated string that contains the name of the performance object specified in the counter path. The string follows this structure in memory. + SzObjectName *uint16 // pointer to a string + //Null-terminated string that contains the name of the object instance specified in the counter path. Is NULL, if the path does not specify an instance. + //The string follows this structure in memory. + SzInstanceName *uint16 // pointer to a string + //Null-terminated string that contains the name of the parent instance specified in the counter path. Is NULL, if the path does not specify a parent instance. + //The string follows this structure in memory. + SzParentInstance *uint16 // pointer to a string + //Instance index specified in the counter path. Is 0, if the path does not specify an instance index. + DwInstanceIndex uint32 // pointer to a string + //Null-terminated string that contains the counter name. The string follows this structure in memory. + SzCounterName *uint16 // pointer to a string + //padding + Padding [4]byte + //Help text that describes the counter. Is NULL if the source is a log file. + SzExplainText *uint16 // pointer to a string + //Start of the string data that is appended to the structure. + DataBuffer [1]uint32 // pointer to an extra space +} diff --git a/plugins/inputs/win_perf_counters/pdh_amd64.go b/plugins/inputs/win_perf_counters/pdh_amd64.go new file mode 100644 index 000000000..ff3b39335 --- /dev/null +++ b/plugins/inputs/win_perf_counters/pdh_amd64.go @@ -0,0 +1,114 @@ +// Copyright (c) 2010 The win Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The names of the authors may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// This is the official list of 'win' authors for copyright purposes. +// +// Alexander Neumann +// Joseph Watson +// Kevin Pors + +// +build windows + +package win_perf_counters + +// Union specialization for double values +type PDH_FMT_COUNTERVALUE_DOUBLE struct { + CStatus uint32 + DoubleValue float64 +} + +// Union specialization for 64 bit integer values +type PDH_FMT_COUNTERVALUE_LARGE struct { + CStatus uint32 + LargeValue int64 +} + +// Union specialization for long values +type PDH_FMT_COUNTERVALUE_LONG struct { + CStatus uint32 + LongValue int32 + padding [4]byte +} + +type PDH_FMT_COUNTERVALUE_ITEM_DOUBLE struct { + SzName *uint16 + FmtValue PDH_FMT_COUNTERVALUE_DOUBLE +} + +// Union specialization for 'large' values, used by PdhGetFormattedCounterArrayLarge() +type PDH_FMT_COUNTERVALUE_ITEM_LARGE struct { + SzName *uint16 // pointer to a string + FmtValue PDH_FMT_COUNTERVALUE_LARGE +} + +// Union specialization for long values, used by PdhGetFormattedCounterArrayLong() +type PDH_FMT_COUNTERVALUE_ITEM_LONG struct { + SzName *uint16 // pointer to a string + FmtValue PDH_FMT_COUNTERVALUE_LONG +} + +//PDH_COUNTER_INFO structure contains information describing the properties of a counter. This information also includes the counter path. +type PDH_COUNTER_INFO struct { + //Size of the structure, including the appended strings, in bytes. + DwLength uint32 + //Counter type. For a list of counter types, see the Counter Types section of the Windows Server 2003 Deployment Kit. + //The counter type constants are defined in Winperf.h. + DwType uint32 + //Counter version information. Not used. + CVersion uint32 + //Counter status that indicates if the counter value is valid. For a list of possible values, + //see Checking PDH Interface Return Values. + CStatus uint32 + //Scale factor to use when computing the displayable value of the counter. The scale factor is a power of ten. + //The valid range of this parameter is PDH_MIN_SCALE (–7) (the returned value is the actual value times 10–⁷) to + //PDH_MAX_SCALE (+7) (the returned value is the actual value times 10⁺⁷). A value of zero will set the scale to one, so that the actual value is returned + LScale int32 + //Default scale factor as suggested by the counter's provider. + LDefaultScale int32 + //The value passed in the dwUserData parameter when calling PdhAddCounter. + DwUserData *uint32 + //The value passed in the dwUserData parameter when calling PdhOpenQuery. + DwQueryUserData *uint32 + //Null-terminated string that specifies the full counter path. The string follows this structure in memory. + SzFullPath *uint16 // pointer to a string + //Null-terminated string that contains the name of the computer specified in the counter path. Is NULL, if the path does not specify a computer. + //The string follows this structure in memory. + SzMachineName *uint16 // pointer to a string + //Null-terminated string that contains the name of the performance object specified in the counter path. The string follows this structure in memory. + SzObjectName *uint16 // pointer to a string + //Null-terminated string that contains the name of the object instance specified in the counter path. Is NULL, if the path does not specify an instance. + //The string follows this structure in memory. + SzInstanceName *uint16 // pointer to a string + //Null-terminated string that contains the name of the parent instance specified in the counter path. Is NULL, if the path does not specify a parent instance. + //The string follows this structure in memory. + SzParentInstance *uint16 // pointer to a string + //Instance index specified in the counter path. Is 0, if the path does not specify an instance index. + DwInstanceIndex uint32 // pointer to a string + //Null-terminated string that contains the counter name. The string follows this structure in memory. + SzCounterName *uint16 // pointer to a string + //Help text that describes the counter. Is NULL if the source is a log file. + SzExplainText *uint16 // pointer to a string + //Start of the string data that is appended to the structure. + DataBuffer [1]uint32 // pointer to an extra space +}