|
|
1.1 ! root 1: ! 2: /******************************************************************************\ ! 3: * This is a part of the Microsoft Source Code Samples. ! 4: * Copyright (C) 1993 Microsoft Corporation. ! 5: * All rights reserved. ! 6: * This source code is only intended as a supplement to ! 7: * Microsoft Development Tools and/or WinHelp documentation. ! 8: * See these sources for detailed information regarding the ! 9: * Microsoft samples programs. ! 10: \******************************************************************************/ ! 11: ! 12: ! 13: /****************************************************************************** ! 14: ! 15: C O U N T E R D A T A ! 16: ! 17: Name: cntrdata.c ! 18: ! 19: Description: ! 20: This module contains functions that access counters of an instance ! 21: of object in performance data. ! 22: ! 23: Functions: ! 24: FirstCounter ! 25: NextCounter ! 26: FindCounter ! 27: CounterData ! 28: ! 29: ******************************************************************************/ ! 30: ! 31: #include <windows.h> ! 32: #include <winperf.h> ! 33: #include "perfdata.h" ! 34: ! 35: ! 36: ! 37: ! 38: //********************************************************************* ! 39: // ! 40: // FirstCounter ! 41: // ! 42: // Find the first counter in pObject. ! 43: // ! 44: // Returns a pointer to the first counter. If pObject is NULL ! 45: // then NULL is returned. ! 46: // ! 47: PPERF_COUNTER FirstCounter (PPERF_OBJECT pObject) ! 48: { ! 49: if (pObject) ! 50: return (PPERF_COUNTER)((PCHAR) pObject + pObject->HeaderLength); ! 51: else ! 52: return NULL; ! 53: } ! 54: ! 55: ! 56: ! 57: ! 58: //********************************************************************* ! 59: // ! 60: // NextCounter ! 61: // ! 62: // Find the next counter of pCounter. ! 63: // ! 64: // If pCounter is the last counter of an object type, bogus data ! 65: // maybe returned. The caller should do the checking. ! 66: // ! 67: // Returns a pointer to a counter. If pCounter is NULL then ! 68: // NULL is returned. ! 69: // ! 70: PPERF_COUNTER NextCounter (PPERF_COUNTER pCounter) ! 71: { ! 72: if (pCounter) ! 73: return (PPERF_COUNTER)((PCHAR) pCounter + pCounter->ByteLength); ! 74: else ! 75: return NULL; ! 76: } ! 77: ! 78: ! 79: ! 80: ! 81: //********************************************************************* ! 82: // ! 83: // FindCounter ! 84: // ! 85: // Find a counter specified by TitleIndex. ! 86: // ! 87: // Returns a pointer to the counter. If counter is not found ! 88: // then NULL is returned. ! 89: // ! 90: PPERF_COUNTER FindCounter (PPERF_OBJECT pObject, DWORD TitleIndex) ! 91: { ! 92: PPERF_COUNTER pCounter; ! 93: DWORD i = 0; ! 94: ! 95: if (pCounter = FirstCounter (pObject)) ! 96: while (i < pObject->NumCounters) ! 97: { ! 98: if (pCounter->CounterNameTitleIndex == TitleIndex) ! 99: return pCounter; ! 100: ! 101: pCounter = NextCounter (pCounter); ! 102: i++; ! 103: } ! 104: ! 105: return NULL; ! 106: ! 107: } ! 108: ! 109: ! 110: ! 111: ! 112: //********************************************************************* ! 113: // ! 114: // CounterData ! 115: // ! 116: // Returns counter data for an object instance. If pInst or pCount ! 117: // is NULL then NULL is returne. ! 118: // ! 119: PVOID CounterData (PPERF_INSTANCE pInst, PPERF_COUNTER pCount) ! 120: { ! 121: PPERF_COUNTER_BLOCK pCounterBlock; ! 122: ! 123: if (pCount && pInst) ! 124: { ! 125: pCounterBlock = (PPERF_COUNTER_BLOCK)((PCHAR)pInst + pInst->ByteLength); ! 126: return (PVOID)((PCHAR)pCounterBlock + pCount->CounterOffset); ! 127: } ! 128: else ! 129: return NULL; ! 130: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.