source: trunk-3.0/source/registry/reg_perfcount.c@ 101

Last change on this file since 101 was 1, checked in by Paul Smedley, 18 years ago

Initial code import

File size: 39.8 KB
Line 
1/*
2 * Unix SMB/CIFS implementation.
3 * Virtual Windows Registry Layer
4 *
5 * Copyright (C) Marcin Krzysztof Porwit 2005,
6 * Copyright (C) Gerald (Jerry) Carter 2005.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include "includes.h"
24
25#undef DBGC_CLASS
26#define DBGC_CLASS DBGC_RPC_SRV
27
28#define PERFCOUNT_MAX_LEN 256
29
30#define PERFCOUNTDIR "perfmon"
31#define NAMES_DB "names.tdb"
32#define DATA_DB "data.tdb"
33
34PERF_OBJECT_TYPE *_reg_perfcount_find_obj(PERF_DATA_BLOCK *block, int objind);
35
36/*********************************************************************
37*********************************************************************/
38
39static char* counters_directory( const char *dbname )
40{
41 static pstring fname;
42 fstring path;
43
44 if ( !dbname )
45 return NULL;
46
47 fstr_sprintf( path, "%s/%s", PERFCOUNTDIR, dbname );
48
49 pstrcpy( fname, lock_path( path ) );
50
51 return fname;
52}
53
54/*********************************************************************
55*********************************************************************/
56
57void perfcount_init_keys( void )
58{
59 char *p = lock_path(PERFCOUNTDIR);
60
61 /* no registry keys; just create the perfmon directory */
62
63 if ( !directory_exist( p, NULL ) )
64 mkdir( p, 0755 );
65
66 return;
67}
68
69/*********************************************************************
70*********************************************************************/
71
72uint32 reg_perfcount_get_base_index(void)
73{
74 const char *fname = counters_directory( NAMES_DB );
75 TDB_CONTEXT *names;
76 TDB_DATA kbuf, dbuf;
77 char key[] = "1";
78 uint32 retval = 0;
79 char buf[PERFCOUNT_MAX_LEN];
80
81 names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
82
83 if ( !names ) {
84 DEBUG(1, ("reg_perfcount_get_base_index: unable to open [%s].\n", fname));
85 return 0;
86 }
87 /* needs to read the value of key "1" from the counter_names.tdb file, as that is
88 where the total number of counters is stored. We're assuming no holes in the
89 enumeration.
90 The format for the counter_names.tdb file is:
91 key value
92 1 num_counters
93 2 perf_counter1
94 3 perf_counter1_help
95 4 perf_counter2
96 5 perf_counter2_help
97 even_num perf_counter<even_num>
98 even_num+1 perf_counter<even_num>_help
99 and so on.
100 So last_counter becomes num_counters*2, and last_help will be last_counter+1 */
101 kbuf.dptr = key;
102 kbuf.dsize = strlen(key);
103 dbuf = tdb_fetch(names, kbuf);
104 if(dbuf.dptr == NULL)
105 {
106 DEBUG(1, ("reg_perfcount_get_base_index: failed to find key \'1\' in [%s].\n", fname));
107 tdb_close(names);
108 return 0;
109 }
110 else
111 {
112 tdb_close(names);
113 memset(buf, 0, PERFCOUNT_MAX_LEN);
114 memcpy(buf, dbuf.dptr, dbuf.dsize);
115 retval = (uint32)atoi(buf);
116 SAFE_FREE(dbuf.dptr);
117 return retval;
118 }
119 return 0;
120}
121
122/*********************************************************************
123*********************************************************************/
124
125uint32 reg_perfcount_get_last_counter(uint32 base_index)
126{
127 uint32 retval;
128
129 if(base_index == 0)
130 retval = 0;
131 else
132 retval = base_index * 2;
133
134 return retval;
135}
136
137/*********************************************************************
138*********************************************************************/
139
140uint32 reg_perfcount_get_last_help(uint32 last_counter)
141{
142 uint32 retval;
143
144 if(last_counter == 0)
145 retval = 0;
146 else
147 retval = last_counter + 1;
148
149 return retval;
150}
151
152
153/*********************************************************************
154*********************************************************************/
155
156static uint32 _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb,
157 int keyval,
158 char **retbuf,
159 uint32 buffer_size)
160{
161 TDB_DATA kbuf, dbuf;
162 char temp[256];
163 char *buf1 = *retbuf;
164 uint32 working_size = 0;
165 UNISTR2 name_index, name;
166
167 memset(temp, 0, sizeof(temp));
168 snprintf(temp, sizeof(temp), "%d", keyval);
169 kbuf.dptr = temp;
170 kbuf.dsize = strlen(temp);
171 dbuf = tdb_fetch(tdb, kbuf);
172 if(dbuf.dptr == NULL)
173 {
174 /* If a key isn't there, just bypass it -- this really shouldn't
175 happen unless someone's mucking around with the tdb */
176 DEBUG(3, ("_reg_perfcount_multi_sz_from_tdb: failed to find key [%s] in [%s].\n",
177 temp, tdb_name(tdb)));
178 return buffer_size;
179 }
180 /* First encode the name_index */
181 working_size = (kbuf.dsize + 1)*sizeof(uint16);
182 buf1 = (char *)SMB_REALLOC(buf1, buffer_size + working_size);
183 if(!buf1) {
184 buffer_size = 0;
185 return buffer_size;
186 }
187 init_unistr2(&name_index, kbuf.dptr, UNI_STR_TERMINATE);
188 memcpy(buf1+buffer_size, (char *)name_index.buffer, working_size);
189 buffer_size += working_size;
190 /* Now encode the actual name */
191 working_size = (dbuf.dsize + 1)*sizeof(uint16);
192 buf1 = (char *)SMB_REALLOC(buf1, buffer_size + working_size);
193 if(!buf1) {
194 buffer_size = 0;
195 return buffer_size;
196 }
197 memset(temp, 0, sizeof(temp));
198 memcpy(temp, dbuf.dptr, dbuf.dsize);
199 SAFE_FREE(dbuf.dptr);
200 init_unistr2(&name, temp, UNI_STR_TERMINATE);
201 memcpy(buf1+buffer_size, (char *)name.buffer, working_size);
202 buffer_size += working_size;
203
204 *retbuf = buf1;
205
206 return buffer_size;
207}
208
209/*********************************************************************
210*********************************************************************/
211
212uint32 reg_perfcount_get_counter_help(uint32 base_index, char **retbuf)
213{
214 char *buf1 = NULL;
215 uint32 buffer_size = 0;
216 TDB_CONTEXT *names;
217 const char *fname = counters_directory( NAMES_DB );
218 int i;
219
220 if(base_index == 0)
221 return 0;
222
223 names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
224
225 if(names == NULL)
226 {
227 DEBUG(1, ("reg_perfcount_get_counter_help: unable to open [%s].\n", fname));
228 return 0;
229 }
230
231 for(i = 1; i <= base_index; i++)
232 {
233 buffer_size = _reg_perfcount_multi_sz_from_tdb(names, (i*2)+1, retbuf, buffer_size);
234 }
235 tdb_close(names);
236
237 /* Now terminate the MULTI_SZ with a double unicode NULL */
238 buf1 = *retbuf;
239 buf1 = (char *)SMB_REALLOC(buf1, buffer_size + 2);
240 if(!buf1) {
241 buffer_size = 0;
242 } else {
243 buf1[buffer_size++] = '\0';
244 buf1[buffer_size++] = '\0';
245 }
246
247 *retbuf = buf1;
248
249 return buffer_size;
250}
251
252/*********************************************************************
253*********************************************************************/
254
255uint32 reg_perfcount_get_counter_names(uint32 base_index, char **retbuf)
256{
257 char *buf1 = NULL;
258 uint32 buffer_size = 0;
259 TDB_CONTEXT *names;
260 const char *fname = counters_directory( NAMES_DB );
261 int i;
262
263 if(base_index == 0)
264 return 0;
265
266 names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
267
268 if(names == NULL)
269 {
270 DEBUG(1, ("reg_perfcount_get_counter_names: unable to open [%s].\n", fname));
271 return 0;
272 }
273
274 buffer_size = _reg_perfcount_multi_sz_from_tdb(names, 1, retbuf, buffer_size);
275
276 for(i = 1; i <= base_index; i++)
277 {
278 buffer_size = _reg_perfcount_multi_sz_from_tdb(names, i*2, retbuf, buffer_size);
279 }
280 tdb_close(names);
281
282 /* Now terminate the MULTI_SZ with a double unicode NULL */
283 buf1 = *retbuf;
284 buf1 = (char *)SMB_REALLOC(buf1, buffer_size + 2);
285 if(!buf1) {
286 buffer_size = 0;
287 } else {
288 buf1[buffer_size++] = '\0';
289 buf1[buffer_size++] = '\0';
290 }
291
292 *retbuf=buf1;
293
294 return buffer_size;
295}
296
297/*********************************************************************
298*********************************************************************/
299
300static void _reg_perfcount_make_key(TDB_DATA *key,
301 char *buf,
302 int buflen,
303 int key_part1,
304 const char *key_part2)
305{
306 memset(buf, 0, buflen);
307 if(key_part2 != NULL)
308 snprintf(buf, buflen,"%d%s", key_part1, key_part2);
309 else
310 snprintf(buf, buflen, "%d", key_part1);
311
312 key->dptr = buf;
313 key->dsize = strlen(buf);
314
315 return;
316}
317
318/*********************************************************************
319*********************************************************************/
320
321static BOOL _reg_perfcount_isparent(TDB_DATA data)
322{
323 if(data.dsize > 0)
324 {
325 if(data.dptr[0] == 'p')
326 return True;
327 else
328 return False;
329 }
330 return False;
331}
332
333/*********************************************************************
334*********************************************************************/
335
336static BOOL _reg_perfcount_ischild(TDB_DATA data)
337{
338 if(data.dsize > 0)
339 {
340 if(data.dptr[0] == 'c')
341 return True;
342 else
343 return False;
344 }
345 return False;
346}
347
348/*********************************************************************
349*********************************************************************/
350
351static uint32 _reg_perfcount_get_numinst(int objInd, TDB_CONTEXT *names)
352{
353 TDB_DATA key, data;
354 char buf[PERFCOUNT_MAX_LEN];
355
356 _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, objInd, "inst");
357 data = tdb_fetch(names, key);
358
359 if(data.dptr == NULL)
360 return (uint32)PERF_NO_INSTANCES;
361
362 memset(buf, 0, PERFCOUNT_MAX_LEN);
363 memcpy(buf, data.dptr, data.dsize);
364 return (uint32)atoi(buf);
365}
366
367/*********************************************************************
368*********************************************************************/
369
370static BOOL _reg_perfcount_add_object(PERF_DATA_BLOCK *block,
371 prs_struct *ps,
372 int num,
373 TDB_DATA data,
374 TDB_CONTEXT *names)
375{
376 int i;
377 BOOL success = True;
378 PERF_OBJECT_TYPE *obj;
379
380 block->objects = (PERF_OBJECT_TYPE *)TALLOC_REALLOC_ARRAY(ps->mem_ctx,
381 block->objects,
382 PERF_OBJECT_TYPE,
383 block->NumObjectTypes+1);
384 if(block->objects == NULL)
385 return False;
386 obj = &(block->objects[block->NumObjectTypes]);
387 memset((void *)&(block->objects[block->NumObjectTypes]), 0, sizeof(PERF_OBJECT_TYPE));
388 block->objects[block->NumObjectTypes].ObjectNameTitleIndex = num;
389 block->objects[block->NumObjectTypes].ObjectNameTitlePointer = 0;
390 block->objects[block->NumObjectTypes].ObjectHelpTitleIndex = num+1;
391 block->objects[block->NumObjectTypes].ObjectHelpTitlePointer = 0;
392 block->objects[block->NumObjectTypes].NumCounters = 0;
393 block->objects[block->NumObjectTypes].DefaultCounter = 0;
394 block->objects[block->NumObjectTypes].NumInstances = _reg_perfcount_get_numinst(num, names);
395 block->objects[block->NumObjectTypes].counters = NULL;
396 block->objects[block->NumObjectTypes].instances = NULL;
397 block->objects[block->NumObjectTypes].counter_data.ByteLength = sizeof(uint32);
398 block->objects[block->NumObjectTypes].counter_data.data = NULL;
399 block->objects[block->NumObjectTypes].DetailLevel = PERF_DETAIL_NOVICE;
400 block->NumObjectTypes+=1;
401
402 for(i = 0; i < (int)obj->NumInstances; i++) {
403 success = _reg_perfcount_add_instance(obj, ps, i, names);
404 }
405
406 return success;
407}
408
409/*********************************************************************
410*********************************************************************/
411
412BOOL _reg_perfcount_get_counter_data(TDB_DATA key, TDB_DATA *data)
413{
414 TDB_CONTEXT *counters;
415 const char *fname = counters_directory( DATA_DB );
416
417 counters = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
418
419 if(counters == NULL)
420 {
421 DEBUG(1, ("reg_perfcount_get_counter_data: unable to open [%s].\n", fname));
422 return False;
423 }
424
425 *data = tdb_fetch(counters, key);
426
427 tdb_close(counters);
428
429 return True;
430}
431
432/*********************************************************************
433*********************************************************************/
434
435static uint32 _reg_perfcount_get_size_field(uint32 CounterType)
436{
437 uint32 retval;
438
439 retval = CounterType;
440
441 /* First mask out reserved lower 8 bits */
442 retval = retval & 0xFFFFFF00;
443 retval = retval << 22;
444 retval = retval >> 22;
445
446 return retval;
447}
448
449/*********************************************************************
450*********************************************************************/
451
452static uint32 _reg_perfcount_compute_scale(SMB_BIG_INT data)
453{
454 int scale = 0;
455 if(data == 0)
456 return scale;
457 while(data > 100)
458 {
459 data /= 10;
460 scale--;
461 }
462 while(data < 10)
463 {
464 data *= 10;
465 scale++;
466 }
467
468 return (uint32)scale;
469}
470
471/*********************************************************************
472*********************************************************************/
473
474static BOOL _reg_perfcount_get_counter_info(PERF_DATA_BLOCK *block,
475 prs_struct *ps,
476 int CounterIndex,
477 PERF_OBJECT_TYPE *obj,
478 TDB_CONTEXT *names)
479{
480 TDB_DATA key, data;
481 char buf[PERFCOUNT_MAX_LEN];
482 size_t dsize, padding;
483 long int data32, dbuf[2];
484 SMB_BIG_INT data64;
485 uint32 counter_size;
486
487 obj->counters[obj->NumCounters].DefaultScale = 0;
488 dbuf[0] = dbuf[1] = 0;
489 padding = 0;
490
491 _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, CounterIndex, "type");
492 data = tdb_fetch(names, key);
493 if(data.dptr == NULL)
494 {
495 DEBUG(3, ("_reg_perfcount_get_counter_info: No type data for counter [%d].\n", CounterIndex));
496 return False;
497 }
498 memset(buf, 0, PERFCOUNT_MAX_LEN);
499 memcpy(buf, data.dptr, data.dsize);
500 obj->counters[obj->NumCounters].CounterType = atoi(buf);
501 DEBUG(10, ("_reg_perfcount_get_counter_info: Got type [%d] for counter [%d].\n",
502 obj->counters[obj->NumCounters].CounterType, CounterIndex));
503 SAFE_FREE(data.dptr);
504
505 /* Fetch the actual data */
506 _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, CounterIndex, "");
507 _reg_perfcount_get_counter_data(key, &data);
508 if(data.dptr == NULL)
509 {
510 DEBUG(3, ("_reg_perfcount_get_counter_info: No counter data for counter [%d].\n", CounterIndex));
511 return False;
512 }
513
514 counter_size = _reg_perfcount_get_size_field(obj->counters[obj->NumCounters].CounterType);
515
516 if(counter_size == PERF_SIZE_DWORD)
517 {
518 dsize = sizeof(data32);
519 memset(buf, 0, PERFCOUNT_MAX_LEN);
520 memcpy(buf, data.dptr, data.dsize);
521 data32 = strtol(buf, NULL, 0);
522 if((obj->counters[obj->NumCounters].CounterType & 0x00000F00) == PERF_TYPE_NUMBER)
523 obj->counters[obj->NumCounters].DefaultScale = _reg_perfcount_compute_scale((SMB_BIG_INT)data32);
524 else
525 obj->counters[obj->NumCounters].DefaultScale = 0;
526 dbuf[0] = data32;
527 padding = (dsize - (obj->counter_data.ByteLength%dsize)) % dsize;
528 }
529 else if(counter_size == PERF_SIZE_LARGE)
530 {
531 dsize = sizeof(data64);
532 memset(buf, 0, PERFCOUNT_MAX_LEN);
533 memcpy(buf, data.dptr, data.dsize);
534 data64 = atof(buf);
535 if((obj->counters[obj->NumCounters].CounterType & 0x00000F00) == PERF_TYPE_NUMBER)
536 obj->counters[obj->NumCounters].DefaultScale = _reg_perfcount_compute_scale(data64);
537 else
538 obj->counters[obj->NumCounters].DefaultScale = 0;
539 memcpy((void *)dbuf, (const void *)&data64, dsize);
540 padding = (dsize - (obj->counter_data.ByteLength%dsize)) % dsize;
541 }
542 else /* PERF_SIZE_VARIABLE_LEN */
543 {
544 dsize = data.dsize;
545 memset(buf, 0, PERFCOUNT_MAX_LEN);
546 memcpy(buf, data.dptr, data.dsize);
547 }
548 SAFE_FREE(data.dptr);
549
550 obj->counter_data.ByteLength += dsize + padding;
551 obj->counter_data.data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
552 obj->counter_data.data,
553 uint8,
554 obj->counter_data.ByteLength - sizeof(uint32));
555 if(obj->counter_data.data == NULL)
556 return False;
557 if(dbuf[0] != 0 || dbuf[1] != 0)
558 {
559 memcpy((void *)(obj->counter_data.data +
560 (obj->counter_data.ByteLength - (sizeof(uint32) + dsize))),
561 (const void *)dbuf, dsize);
562 }
563 else
564 {
565 /* Handling PERF_SIZE_VARIABLE_LEN */
566 memcpy((void *)(obj->counter_data.data +
567 (obj->counter_data.ByteLength - (sizeof(uint32) + dsize))),
568 (const void *)buf, dsize);
569 }
570 obj->counters[obj->NumCounters].CounterOffset = obj->counter_data.ByteLength - dsize;
571 if(obj->counters[obj->NumCounters].CounterOffset % dsize != 0)
572 {
573 DEBUG(3,("Improperly aligned counter [%d]\n", obj->NumCounters));
574 }
575 obj->counters[obj->NumCounters].CounterSize = dsize;
576
577 return True;
578}
579
580/*********************************************************************
581*********************************************************************/
582
583PERF_OBJECT_TYPE *_reg_perfcount_find_obj(PERF_DATA_BLOCK *block, int objind)
584{
585 int i;
586
587 PERF_OBJECT_TYPE *obj = NULL;
588
589 for(i = 0; i < block->NumObjectTypes; i++)
590 {
591 if(block->objects[i].ObjectNameTitleIndex == objind)
592 {
593 obj = &(block->objects[i]);
594 }
595 }
596
597 return obj;
598}
599
600/*********************************************************************
601*********************************************************************/
602
603static BOOL _reg_perfcount_add_counter(PERF_DATA_BLOCK *block,
604 prs_struct *ps,
605 int num,
606 TDB_DATA data,
607 TDB_CONTEXT *names)
608{
609 char *begin, *end, *start, *stop;
610 int parent;
611 PERF_OBJECT_TYPE *obj;
612 BOOL success = True;
613 char buf[PERFCOUNT_MAX_LEN];
614
615 obj = NULL;
616 memset(buf, 0, PERFCOUNT_MAX_LEN);
617 memcpy(buf, data.dptr, data.dsize);
618 begin = index(buf, '[');
619 end = index(buf, ']');
620 if(begin == NULL || end == NULL)
621 return False;
622 start = begin+1;
623
624 while(start < end) {
625 stop = index(start, ',');
626 if(stop == NULL)
627 stop = end;
628 *stop = '\0';
629 parent = atoi(start);
630
631 obj = _reg_perfcount_find_obj(block, parent);
632 if(obj == NULL) {
633 /* At this point we require that the parent object exist.
634 This can probably be handled better at some later time */
635 DEBUG(3, ("_reg_perfcount_add_counter: Could not find parent object [%d] for counter [%d].\n",
636 parent, num));
637 return False;
638 }
639 obj->counters = (PERF_COUNTER_DEFINITION *)TALLOC_REALLOC_ARRAY(ps->mem_ctx,
640 obj->counters,
641 PERF_COUNTER_DEFINITION,
642 obj->NumCounters+1);
643 if(obj->counters == NULL)
644 return False;
645 memset((void *)&(obj->counters[obj->NumCounters]), 0, sizeof(PERF_COUNTER_DEFINITION));
646 obj->counters[obj->NumCounters].CounterNameTitleIndex=num;
647 obj->counters[obj->NumCounters].CounterHelpTitleIndex=num+1;
648 obj->counters[obj->NumCounters].DetailLevel = PERF_DETAIL_NOVICE;
649 obj->counters[obj->NumCounters].ByteLength = sizeof(PERF_COUNTER_DEFINITION);
650 success = _reg_perfcount_get_counter_info(block, ps, num, obj, names);
651 obj->NumCounters += 1;
652 start = stop + 1;
653 }
654
655 /* Handle case of Objects/Counters without any counter data, which would suggest
656 that the required instances are not there yet, so change NumInstances from
657 PERF_NO_INSTANCES to 0 */
658
659 return success;
660}
661
662/*********************************************************************
663*********************************************************************/
664
665BOOL _reg_perfcount_get_instance_info(PERF_INSTANCE_DEFINITION *inst,
666 prs_struct *ps,
667 int instId,
668 PERF_OBJECT_TYPE *obj,
669 TDB_CONTEXT *names)
670{
671 TDB_DATA key, data;
672 char buf[PERFCOUNT_MAX_LEN], temp[PERFCOUNT_MAX_LEN];
673 wpstring name;
674 int pad;
675
676 /* First grab the instance data from the data file */
677 memset(temp, 0, PERFCOUNT_MAX_LEN);
678 snprintf(temp, PERFCOUNT_MAX_LEN, "i%d", instId);
679 _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, obj->ObjectNameTitleIndex, temp);
680 _reg_perfcount_get_counter_data(key, &data);
681 if(data.dptr == NULL)
682 {
683 DEBUG(3, ("_reg_perfcount_get_instance_info: No instance data for instance [%s].\n",
684 buf));
685 return False;
686 }
687 inst->counter_data.ByteLength = data.dsize + sizeof(inst->counter_data.ByteLength);
688 inst->counter_data.data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
689 inst->counter_data.data,
690 uint8,
691 data.dsize);
692 if(inst->counter_data.data == NULL)
693 return False;
694 memset(inst->counter_data.data, 0, data.dsize);
695 memcpy(inst->counter_data.data, data.dptr, data.dsize);
696 SAFE_FREE(data.dptr);
697
698 /* Fetch instance name */
699 memset(temp, 0, PERFCOUNT_MAX_LEN);
700 snprintf(temp, PERFCOUNT_MAX_LEN, "i%dname", instId);
701 _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, obj->ObjectNameTitleIndex, temp);
702 data = tdb_fetch(names, key);
703 if(data.dptr == NULL)
704 {
705 /* Not actually an error, but possibly unintended? -- just logging FYI */
706 DEBUG(3, ("_reg_perfcount_get_instance_info: No instance name for instance [%s].\n",
707 buf));
708 inst->NameLength = 0;
709 }
710 else
711 {
712 memset(buf, 0, PERFCOUNT_MAX_LEN);
713 memcpy(buf, data.dptr, data.dsize);
714 rpcstr_push((void *)name, buf, sizeof(name), STR_TERMINATE);
715 inst->NameLength = (strlen_w(name) * 2) + 2;
716 inst->data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
717 inst->data,
718 uint8,
719 inst->NameLength);
720 if (inst->data == NULL) {
721 SAFE_FREE(data.dptr);
722 return False;
723 }
724 memcpy(inst->data, name, inst->NameLength);
725 SAFE_FREE(data.dptr);
726 }
727
728 inst->ParentObjectTitleIndex = 0;
729 inst->ParentObjectTitlePointer = 0;
730 inst->UniqueID = PERF_NO_UNIQUE_ID;
731 inst->NameOffset = 6 * sizeof(uint32);
732
733 inst->ByteLength = inst->NameOffset + inst->NameLength;
734 /* Need to be aligned on a 64-bit boundary here for counter_data */
735 if((pad = (inst->ByteLength % 8)))
736 {
737 pad = 8 - pad;
738 inst->data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
739 inst->data,
740 uint8,
741 inst->NameLength + pad);
742 memset(inst->data + inst->NameLength, 0, pad);
743 inst->ByteLength += pad;
744 }
745
746 return True;
747}
748
749/*********************************************************************
750*********************************************************************/
751
752BOOL _reg_perfcount_add_instance(PERF_OBJECT_TYPE *obj,
753 prs_struct *ps,
754 int instInd,
755 TDB_CONTEXT *names)
756{
757 PERF_INSTANCE_DEFINITION *inst;
758
759 if(obj->instances == NULL) {
760 obj->instances = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
761 obj->instances,
762 PERF_INSTANCE_DEFINITION,
763 obj->NumInstances);
764 }
765 if(obj->instances == NULL)
766 return False;
767
768 memset(&(obj->instances[instInd]), 0, sizeof(PERF_INSTANCE_DEFINITION));
769 inst = &(obj->instances[instInd]);
770 return _reg_perfcount_get_instance_info(inst, ps, instInd, obj, names);
771}
772
773/*********************************************************************
774*********************************************************************/
775
776static int _reg_perfcount_assemble_global(PERF_DATA_BLOCK *block,
777 prs_struct *ps,
778 int base_index,
779 TDB_CONTEXT *names)
780{
781 BOOL success;
782 int i, j, retval = 0;
783 char keybuf[PERFCOUNT_MAX_LEN];
784 TDB_DATA key, data;
785
786 for(i = 1; i <= base_index; i++)
787 {
788 j = i*2;
789 _reg_perfcount_make_key(&key, keybuf, PERFCOUNT_MAX_LEN, j, "rel");
790 data = tdb_fetch(names, key);
791 if(data.dptr != NULL)
792 {
793 if(_reg_perfcount_isparent(data))
794 success = _reg_perfcount_add_object(block, ps, j, data, names);
795 else if(_reg_perfcount_ischild(data))
796 success = _reg_perfcount_add_counter(block, ps, j, data, names);
797 else
798 {
799 DEBUG(3, ("Bogus relationship [%s] for counter [%d].\n", data.dptr, j));
800 success = False;
801 }
802 if(success == False)
803 {
804 DEBUG(3, ("_reg_perfcount_assemble_global: Failed to add new relationship for counter [%d].\n", j));
805 retval = -1;
806 }
807 SAFE_FREE(data.dptr);
808 }
809 else
810 DEBUG(3, ("NULL relationship for counter [%d] using key [%s].\n", j, keybuf));
811 }
812 return retval;
813}
814
815/*********************************************************************
816*********************************************************************/
817
818static BOOL _reg_perfcount_get_64(SMB_BIG_UINT *retval,
819 TDB_CONTEXT *tdb,
820 int key_part1,
821 const char *key_part2)
822{
823 TDB_DATA key, data;
824 char buf[PERFCOUNT_MAX_LEN];
825
826 _reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, key_part1, key_part2);
827
828 data = tdb_fetch(tdb, key);
829 if(data.dptr == NULL)
830 {
831 DEBUG(3,("_reg_perfcount_get_64: No data found for key [%s].\n", key.dptr));
832 return False;
833 }
834
835 memset(buf, 0, PERFCOUNT_MAX_LEN);
836 memcpy(buf, data.dptr, data.dsize);
837 SAFE_FREE(data.dptr);
838
839 *retval = atof(buf);
840
841 return True;
842}
843
844/*********************************************************************
845*********************************************************************/
846
847static BOOL _reg_perfcount_init_data_block_perf(PERF_DATA_BLOCK *block,
848 TDB_CONTEXT *names)
849{
850 SMB_BIG_UINT PerfFreq, PerfTime, PerfTime100nSec;
851 TDB_CONTEXT *counters;
852 BOOL status = False;
853 const char *fname = counters_directory( DATA_DB );
854
855 counters = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
856
857 if(counters == NULL)
858 {
859 DEBUG(1, ("reg_perfcount_init_data_block_perf: unable to open [%s].\n", fname));
860 return False;
861 }
862
863 status = _reg_perfcount_get_64(&PerfFreq, names, 0, "PerfFreq");
864 if(status == False)
865 {
866 tdb_close(counters);
867 return status;
868 }
869 memcpy((void *)&(block->PerfFreq), (const void *)&PerfFreq, sizeof(PerfFreq));
870
871 status = _reg_perfcount_get_64(&PerfTime, counters, 0, "PerfTime");
872 if(status == False)
873 {
874 tdb_close(counters);
875 return status;
876 }
877 memcpy((void *)&(block->PerfTime), (const void *)&PerfTime, sizeof(PerfTime));
878
879 status = _reg_perfcount_get_64(&PerfTime100nSec, counters, 0, "PerfTime100nSec");
880 if(status == False)
881 {
882 tdb_close(counters);
883 return status;
884 }
885 memcpy((void *)&(block->PerfTime100nSec), (const void *)&PerfTime100nSec, sizeof(PerfTime100nSec));
886
887 tdb_close(counters);
888 return True;
889}
890
891/*********************************************************************
892*********************************************************************/
893
894static BOOL _reg_perfcount_init_data_block(PERF_DATA_BLOCK *block,
895 prs_struct *ps, TDB_CONTEXT *names)
896{
897 wpstring temp;
898 time_t tm;
899
900 memset(temp, 0, sizeof(temp));
901 rpcstr_push((void *)temp, "PERF", sizeof(temp), STR_TERMINATE);
902 memcpy(block->Signature, temp, strlen_w(temp) *2);
903
904 if(ps->bigendian_data == RPC_BIG_ENDIAN)
905 block->LittleEndian = 0;
906 else
907 block->LittleEndian = 1;
908 block->Version = 1;
909 block->Revision = 1;
910 block->TotalByteLength = 0;
911 block->NumObjectTypes = 0;
912 block->DefaultObject = -1;
913 block->objects = NULL;
914 tm = time(NULL);
915 make_systemtime(&(block->SystemTime), gmtime(&tm));
916 _reg_perfcount_init_data_block_perf(block, names);
917 memset(temp, 0, sizeof(temp));
918 rpcstr_push((void *)temp, global_myname(), sizeof(temp), STR_TERMINATE);
919 block->SystemNameLength = (strlen_w(temp) * 2) + 2;
920 block->data = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint8, block->SystemNameLength + (8 - (block->SystemNameLength % 8)));
921 if (block->data == NULL) {
922 return False;
923 }
924 memcpy(block->data, temp, block->SystemNameLength);
925 block->SystemNameOffset = sizeof(PERF_DATA_BLOCK) - sizeof(block->objects) - sizeof(block->data);
926 block->HeaderLength = block->SystemNameOffset + block->SystemNameLength;
927 /* Make sure to adjust for 64-bit alignment for when we finish writing the system name,
928 so that the PERF_OBJECT_TYPE struct comes out 64-bit aligned */
929 block->HeaderLength += 8 - (block->HeaderLength % 8);
930
931 return True;
932}
933
934/*********************************************************************
935*********************************************************************/
936
937static uint32 _reg_perfcount_perf_data_block_fixup(PERF_DATA_BLOCK *block, prs_struct *ps)
938{
939 int obj, cnt, inst, pad, i;
940 PERF_OBJECT_TYPE *object;
941 PERF_INSTANCE_DEFINITION *instance;
942 PERF_COUNTER_DEFINITION *counter;
943 PERF_COUNTER_BLOCK *counter_data;
944 char *temp = NULL, *src_addr, *dst_addr;
945
946 block->TotalByteLength = 0;
947 object = block->objects;
948 for(obj = 0; obj < block->NumObjectTypes; obj++)
949 {
950 object[obj].TotalByteLength = 0;
951 object[obj].DefinitionLength = 0;
952 instance = object[obj].instances;
953 counter = object[obj].counters;
954 for(cnt = 0; cnt < object[obj].NumCounters; cnt++)
955 {
956 object[obj].TotalByteLength += counter[cnt].ByteLength;
957 object[obj].DefinitionLength += counter[cnt].ByteLength;
958 }
959 if(object[obj].NumInstances != PERF_NO_INSTANCES)
960 {
961 for(inst = 0; inst < object[obj].NumInstances; inst++)
962 {
963 instance = &(object[obj].instances[inst]);
964 object[obj].TotalByteLength += instance->ByteLength;
965 counter_data = &(instance->counter_data);
966 counter = &(object[obj].counters[object[obj].NumCounters - 1]);
967 counter_data->ByteLength = counter->CounterOffset + counter->CounterSize + sizeof(counter_data->ByteLength);
968 temp = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
969 temp,
970 char,
971 counter_data->ByteLength- sizeof(counter_data->ByteLength));
972 if (temp == NULL) {
973 return 0;
974 }
975 memset(temp, 0, counter_data->ByteLength - sizeof(counter_data->ByteLength));
976 src_addr = (char *)counter_data->data;
977 for(i = 0; i < object[obj].NumCounters; i++)
978 {
979 counter = &(object[obj].counters[i]);
980 dst_addr = temp + counter->CounterOffset - sizeof(counter_data->ByteLength);
981 memcpy(dst_addr, src_addr, counter->CounterSize);
982 src_addr += counter->CounterSize;
983 }
984 /* Make sure to be 64-bit aligned */
985 if((pad = (counter_data->ByteLength % 8)))
986 {
987 pad = 8 - pad;
988 }
989 counter_data->data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
990 counter_data->data,
991 uint8,
992 counter_data->ByteLength - sizeof(counter_data->ByteLength) + pad);
993 if (counter_data->data == NULL) {
994 return 0;
995 }
996 memset(counter_data->data, 0, counter_data->ByteLength - sizeof(counter_data->ByteLength) + pad);
997 memcpy(counter_data->data, temp, counter_data->ByteLength - sizeof(counter_data->ByteLength));
998 counter_data->ByteLength += pad;
999 object[obj].TotalByteLength += counter_data->ByteLength;
1000 }
1001 }
1002 else
1003 {
1004 /* Need to be 64-bit aligned at the end of the counter_data block, so pad counter_data to a 64-bit boundary,
1005 so that the next PERF_OBJECT_TYPE can start on a 64-bit alignment */
1006 if((pad = (object[obj].counter_data.ByteLength % 8)))
1007 {
1008 pad = 8 - pad;
1009 object[obj].counter_data.data = TALLOC_REALLOC_ARRAY(ps->mem_ctx,
1010 object[obj].counter_data.data,
1011 uint8,
1012 object[obj].counter_data.ByteLength + pad);
1013 memset((void *)(object[obj].counter_data.data + object[obj].counter_data.ByteLength), 0, pad);
1014 object[obj].counter_data.ByteLength += pad;
1015 }
1016 object[obj].TotalByteLength += object[obj].counter_data.ByteLength;
1017 }
1018 object[obj].HeaderLength = sizeof(*object) - (sizeof(counter) + sizeof(instance) + sizeof(PERF_COUNTER_BLOCK));
1019 object[obj].TotalByteLength += object[obj].HeaderLength;
1020 object[obj].DefinitionLength += object[obj].HeaderLength;
1021
1022 block->TotalByteLength += object[obj].TotalByteLength;
1023 }
1024
1025 return block->TotalByteLength;
1026}
1027
1028/*********************************************************************
1029*********************************************************************/
1030
1031uint32 reg_perfcount_get_perf_data_block(uint32 base_index,
1032 prs_struct *ps,
1033 PERF_DATA_BLOCK *block,
1034 char *object_ids)
1035{
1036 uint32 buffer_size = 0;
1037 const char *fname = counters_directory( NAMES_DB );
1038 TDB_CONTEXT *names;
1039 int retval = 0;
1040
1041 names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444);
1042
1043 if(names == NULL)
1044 {
1045 DEBUG(1, ("reg_perfcount_get_perf_data_block: unable to open [%s].\n", fname));
1046 return 0;
1047 }
1048
1049 if (!_reg_perfcount_init_data_block(block, ps, names)) {
1050 DEBUG(0, ("_reg_perfcount_init_data_block failed\n"));
1051 tdb_close(names);
1052 return 0;
1053 }
1054
1055 reg_perfcount_get_last_counter(base_index);
1056
1057 if(object_ids == NULL)
1058 {
1059 /* we're getting a request for "Global" here */
1060 retval = _reg_perfcount_assemble_global(block, ps, base_index, names);
1061 }
1062 else
1063 {
1064 /* we're getting a request for a specific set of PERF_OBJECT_TYPES */
1065 retval = _reg_perfcount_assemble_global(block, ps, base_index, names);
1066 }
1067 buffer_size = _reg_perfcount_perf_data_block_fixup(block, ps);
1068
1069 tdb_close(names);
1070
1071 if (retval == -1) {
1072 return 0;
1073 }
1074
1075 return buffer_size + block->HeaderLength;
1076}
1077
1078/*********************************************************************
1079*********************************************************************/
1080
1081static BOOL _reg_perfcount_marshall_perf_data_block(prs_struct *ps, PERF_DATA_BLOCK block, int depth)
1082{
1083 int i;
1084 prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_data_block");
1085 depth++;
1086
1087 if(!prs_align(ps))
1088 return False;
1089 for(i = 0; i < 4; i++)
1090 {
1091 if(!prs_uint16("Signature", ps, depth, &block.Signature[i]))
1092 return False;
1093 }
1094 if(!prs_uint32("Little Endian", ps, depth, &block.LittleEndian))
1095 return False;
1096 if(!prs_uint32("Version", ps, depth, &block.Version))
1097 return False;
1098 if(!prs_uint32("Revision", ps, depth, &block.Revision))
1099 return False;
1100 if(!prs_uint32("TotalByteLength", ps, depth, &block.TotalByteLength))
1101 return False;
1102 if(!prs_uint32("HeaderLength", ps, depth, &block.HeaderLength))
1103 return False;
1104 if(!prs_uint32("NumObjectTypes", ps, depth, &block.NumObjectTypes))
1105 return False;
1106 if(!prs_uint32("DefaultObject", ps, depth, &block.DefaultObject))
1107 return False;
1108 if(!spoolss_io_system_time("SystemTime", ps, depth, &block.SystemTime))
1109 return False;
1110 if(!prs_uint32("Padding", ps, depth, &block.Padding))
1111 return False;
1112 if(!prs_align_uint64(ps))
1113 return False;
1114 if(!prs_uint64("PerfTime", ps, depth, &block.PerfTime))
1115 return False;
1116 if(!prs_uint64("PerfFreq", ps, depth, &block.PerfFreq))
1117 return False;
1118 if(!prs_uint64("PerfTime100nSec", ps, depth, &block.PerfTime100nSec))
1119 return False;
1120 if(!prs_uint32("SystemNameLength", ps, depth, &block.SystemNameLength))
1121 return False;
1122 if(!prs_uint32("SystemNameOffset", ps, depth, &block.SystemNameOffset))
1123 return False;
1124 /* hack to make sure we're 64-bit aligned at the end of this whole mess */
1125 if(!prs_uint8s(False, "SystemName", ps, depth, block.data,
1126 block.HeaderLength - block.SystemNameOffset))
1127 return False;
1128
1129 return True;
1130}
1131
1132/*********************************************************************
1133*********************************************************************/
1134
1135static BOOL _reg_perfcount_marshall_perf_counters(prs_struct *ps,
1136 PERF_OBJECT_TYPE object,
1137 int depth)
1138{
1139 int cnt;
1140 PERF_COUNTER_DEFINITION counter;
1141
1142 prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_counters");
1143 depth++;
1144
1145 for(cnt = 0; cnt < object.NumCounters; cnt++)
1146 {
1147 counter = object.counters[cnt];
1148
1149 if(!prs_align(ps))
1150 return False;
1151 if(!prs_uint32("ByteLength", ps, depth, &counter.ByteLength))
1152 return False;
1153 if(!prs_uint32("CounterNameTitleIndex", ps, depth, &counter.CounterNameTitleIndex))
1154 return False;
1155 if(!prs_uint32("CounterNameTitlePointer", ps, depth, &counter.CounterNameTitlePointer))
1156 return False;
1157 if(!prs_uint32("CounterHelpTitleIndex", ps, depth, &counter.CounterHelpTitleIndex))
1158 return False;
1159 if(!prs_uint32("CounterHelpTitlePointer", ps, depth, &counter.CounterHelpTitlePointer))
1160 return False;
1161 if(!prs_uint32("DefaultScale", ps, depth, &counter.DefaultScale))
1162 return False;
1163 if(!prs_uint32("DetailLevel", ps, depth, &counter.DetailLevel))
1164 return False;
1165 if(!prs_uint32("CounterType", ps, depth, &counter.CounterType))
1166 return False;
1167 if(!prs_uint32("CounterSize", ps, depth, &counter.CounterSize))
1168 return False;
1169 if(!prs_uint32("CounterOffset", ps, depth, &counter.CounterOffset))
1170 return False;
1171 }
1172
1173 return True;
1174}
1175
1176/*********************************************************************
1177*********************************************************************/
1178
1179static BOOL _reg_perfcount_marshall_perf_counter_data(prs_struct *ps,
1180 PERF_COUNTER_BLOCK counter_data,
1181 int depth)
1182{
1183 prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_counter_data");
1184 depth++;
1185
1186 if(!prs_align_uint64(ps))
1187 return False;
1188
1189 if(!prs_uint32("ByteLength", ps, depth, &counter_data.ByteLength))
1190 return False;
1191 if(!prs_uint8s(False, "CounterData", ps, depth, counter_data.data, counter_data.ByteLength - sizeof(uint32)))
1192 return False;
1193 if(!prs_align_uint64(ps))
1194 return False;
1195
1196 return True;
1197}
1198
1199/*********************************************************************
1200*********************************************************************/
1201
1202static BOOL _reg_perfcount_marshall_perf_instances(prs_struct *ps,
1203 PERF_OBJECT_TYPE object,
1204 int depth)
1205{
1206 PERF_INSTANCE_DEFINITION instance;
1207 int inst;
1208
1209 prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_instances");
1210 depth++;
1211
1212 for(inst = 0; inst < object.NumInstances; inst++)
1213 {
1214 instance = object.instances[inst];
1215
1216 if(!prs_align(ps))
1217 return False;
1218 if(!prs_uint32("ByteLength", ps, depth, &instance.ByteLength))
1219 return False;
1220 if(!prs_uint32("ParentObjectTitleIndex", ps, depth, &instance.ParentObjectTitleIndex))
1221 return False;
1222 if(!prs_uint32("ParentObjectTitlePointer", ps, depth, &instance.ParentObjectTitlePointer))
1223 return False;
1224 if(!prs_uint32("UniqueID", ps, depth, &instance.UniqueID))
1225 return False;
1226 if(!prs_uint32("NameOffset", ps, depth, &instance.NameOffset))
1227 return False;
1228 if(!prs_uint32("NameLength", ps, depth, &instance.NameLength))
1229 return False;
1230 if(!prs_uint8s(False, "InstanceName", ps, depth, instance.data,
1231 instance.ByteLength - instance.NameOffset))
1232 return False;
1233 if(_reg_perfcount_marshall_perf_counter_data(ps, instance.counter_data, depth) == False)
1234 return False;
1235 }
1236
1237 return True;
1238}
1239
1240/*********************************************************************
1241*********************************************************************/
1242
1243static BOOL _reg_perfcount_marshall_perf_objects(prs_struct *ps, PERF_DATA_BLOCK block, int depth)
1244{
1245 int obj;
1246
1247 PERF_OBJECT_TYPE object;
1248
1249 prs_debug(ps, depth, "", "_reg_perfcount_marshall_perf_objects");
1250 depth++;
1251
1252 for(obj = 0; obj < block.NumObjectTypes; obj++)
1253 {
1254 object = block.objects[obj];
1255
1256 if(!prs_align(ps))
1257 return False;
1258
1259 if(!prs_uint32("TotalByteLength", ps, depth, &object.TotalByteLength))
1260 return False;
1261 if(!prs_uint32("DefinitionLength", ps, depth, &object.DefinitionLength))
1262 return False;
1263 if(!prs_uint32("HeaderLength", ps, depth, &object.HeaderLength))
1264 return False;
1265 if(!prs_uint32("ObjectNameTitleIndex", ps, depth, &object.ObjectNameTitleIndex))
1266 return False;
1267 if(!prs_uint32("ObjectNameTitlePointer", ps, depth, &object.ObjectNameTitlePointer))
1268 return False;
1269 if(!prs_uint32("ObjectHelpTitleIndex", ps, depth, &object.ObjectHelpTitleIndex))
1270 return False;
1271 if(!prs_uint32("ObjectHelpTitlePointer", ps, depth, &object.ObjectHelpTitlePointer))
1272 return False;
1273 if(!prs_uint32("DetailLevel", ps, depth, &object.DetailLevel))
1274 return False;
1275 if(!prs_uint32("NumCounters", ps, depth, &object.NumCounters))
1276 return False;
1277 if(!prs_uint32("DefaultCounter", ps, depth, &object.DefaultCounter))
1278 return False;
1279 if(!prs_uint32("NumInstances", ps, depth, &object.NumInstances))
1280 return False;
1281 if(!prs_uint32("CodePage", ps, depth, &object.CodePage))
1282 return False;
1283 if(!prs_align_uint64(ps))
1284 return False;
1285 if(!prs_uint64("PerfTime", ps, depth, &object.PerfTime))
1286 return False;
1287 if(!prs_uint64("PerfFreq", ps, depth, &object.PerfFreq))
1288 return False;
1289
1290 /* Now do the counters */
1291 /* If no instances, encode counter_data */
1292 /* If instances, encode instace plus counter data for each instance */
1293 if(_reg_perfcount_marshall_perf_counters(ps, object, depth) == False)
1294 return False;
1295 if(object.NumInstances == PERF_NO_INSTANCES)
1296 {
1297 if(_reg_perfcount_marshall_perf_counter_data(ps, object.counter_data, depth) == False)
1298 return False;
1299 }
1300 else
1301 {
1302 if(_reg_perfcount_marshall_perf_instances(ps, object, depth) == False)
1303 return False;
1304 }
1305 }
1306
1307 return True;
1308}
1309
1310/*********************************************************************
1311*********************************************************************/
1312
1313static BOOL _reg_perfcount_marshall_hkpd(prs_struct *ps, PERF_DATA_BLOCK block)
1314{
1315 int depth = 0;
1316 if(_reg_perfcount_marshall_perf_data_block(ps, block, depth) == True)
1317 {
1318 if(_reg_perfcount_marshall_perf_objects(ps, block, depth) == True)
1319 return True;
1320 }
1321 return False;
1322}
1323
1324/*********************************************************************
1325*********************************************************************/
1326
1327WERROR reg_perfcount_get_hkpd(prs_struct *ps, uint32 max_buf_size, uint32 *outbuf_len, char *object_ids)
1328{
1329 /*
1330 * For a detailed description of the layout of this structure,
1331 * see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/performance_data_format.asp
1332 */
1333 PERF_DATA_BLOCK block;
1334 uint32 buffer_size, base_index;
1335
1336 buffer_size = 0;
1337 base_index = reg_perfcount_get_base_index();
1338 ZERO_STRUCT(block);
1339
1340 buffer_size = reg_perfcount_get_perf_data_block(base_index, ps, &block, object_ids);
1341
1342 if(buffer_size < max_buf_size)
1343 {
1344 *outbuf_len = buffer_size;
1345 if(_reg_perfcount_marshall_hkpd(ps, block) == True)
1346 return WERR_OK;
1347 else
1348 return WERR_NOMEM;
1349 }
1350 else
1351 {
1352 *outbuf_len = max_buf_size;
1353 _reg_perfcount_marshall_perf_data_block(ps, block, 0);
1354 return WERR_INSUFFICIENT_BUFFER;
1355 }
1356}
Note: See TracBrowser for help on using the repository browser.