208 return OS_OK;
209 }
210
211 static int allocate_counters(MultiCounterQuerySetP query_set, size_t nofCounters) {
212 assert(query_set != NULL, "invariant");
213 assert(!query_set->initialized, "invariant");
214 for (int i = 0; i < query_set->size; ++i) {
215 if (allocate_counters(&query_set->queries[i], nofCounters) != OS_OK) {
216 return OS_ERR;
217 }
218 }
219 return OS_OK;
220 }
221
222 static int allocate_counters(ProcessQueryP process_query, size_t nofCounters) {
223 assert(process_query != NULL, "invariant");
224 return allocate_counters(&process_query->set, nofCounters);
225 }
226
227 static void deallocate_counters(MultiCounterQueryP query) {
228 FREE_C_HEAP_ARRAY(char, query->counters);
229 query->counters = NULL;
230 query->noOfCounters = 0;
231 }
232
233 static OSReturn add_counter(UpdateQueryP query, HCOUNTER* counter, const char* path, bool first_sample_on_init) {
234 assert(query != NULL, "invariant");
235 assert(counter != NULL, "invariant");
236 assert(path != NULL, "invariant");
237 if (query->query == NULL) {
238 if (open_query(query) != ERROR_SUCCESS) {
239 return OS_ERR;
240 }
241 }
242 assert(query->query != NULL, "invariant");
243 PDH_STATUS status = PdhDll::PdhAddCounter(query->query, path, 0, counter);
244 if (PDH_CSTATUS_NO_OBJECT == status || PDH_CSTATUS_NO_COUNTER == status) {
245 return OS_ERR;
246 }
247 /*
248 * According to the MSDN documentation, rate counters must be read twice:
249 *
250 * "Obtaining the value of rate counters such as Page faults/sec requires that
|
208 return OS_OK;
209 }
210
211 static int allocate_counters(MultiCounterQuerySetP query_set, size_t nofCounters) {
212 assert(query_set != NULL, "invariant");
213 assert(!query_set->initialized, "invariant");
214 for (int i = 0; i < query_set->size; ++i) {
215 if (allocate_counters(&query_set->queries[i], nofCounters) != OS_OK) {
216 return OS_ERR;
217 }
218 }
219 return OS_OK;
220 }
221
222 static int allocate_counters(ProcessQueryP process_query, size_t nofCounters) {
223 assert(process_query != NULL, "invariant");
224 return allocate_counters(&process_query->set, nofCounters);
225 }
226
227 static void deallocate_counters(MultiCounterQueryP query) {
228 FREE_C_HEAP_ARRAY(char, query->counters);
229 query->counters = NULL;
230 query->noOfCounters = 0;
231 }
232
233 static OSReturn add_counter(UpdateQueryP query, HCOUNTER* counter, const char* path, bool first_sample_on_init) {
234 assert(query != NULL, "invariant");
235 assert(counter != NULL, "invariant");
236 assert(path != NULL, "invariant");
237 if (query->query == NULL) {
238 if (open_query(query) != ERROR_SUCCESS) {
239 return OS_ERR;
240 }
241 }
242 assert(query->query != NULL, "invariant");
243 PDH_STATUS status = PdhDll::PdhAddCounter(query->query, path, 0, counter);
244 if (PDH_CSTATUS_NO_OBJECT == status || PDH_CSTATUS_NO_COUNTER == status) {
245 return OS_ERR;
246 }
247 /*
248 * According to the MSDN documentation, rate counters must be read twice:
249 *
250 * "Obtaining the value of rate counters such as Page faults/sec requires that
|