/
mono-perfcounters.c
714 lines (664 loc) · 18.6 KB
/
mono-perfcounters.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
/*
* mono-perfcounters.c
*
* Performance counters support.
*
* Author: Paolo Molaro (lupus@ximian.com)
*
* (C) 2008 Novell, Inc
*/
#include "config.h"
#include <time.h>
#include <string.h>
#include <stdlib.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include "metadata/mono-perfcounters.h"
#include "metadata/appdomain.h"
/* for mono_stats */
#include "metadata/class-internals.h"
#include "utils/mono-time.h"
#include <mono/io-layer/io-layer.h>
/* map of CounterSample.cs */
struct _MonoCounterSample {
gint64 rawValue;
gint64 baseValue;
gint64 counterFrequency;
gint64 systemFrequency;
gint64 timeStamp;
gint64 timeStamp100nSec;
gint64 counterTimeStamp;
int counterType;
};
/* map of PerformanceCounterType.cs */
enum {
NumberOfItemsHEX32=0x00000000,
NumberOfItemsHEX64=0x00000100,
NumberOfItems32=0x00010000,
NumberOfItems64=0x00010100,
CounterDelta32=0x00400400,
CounterDelta64=0x00400500,
SampleCounter=0x00410400,
CountPerTimeInterval32=0x00450400,
CountPerTimeInterval64=0x00450500,
RateOfCountsPerSecond32=0x10410400,
RateOfCountsPerSecond64=0x10410500,
RawFraction=0x20020400,
CounterTimer=0x20410500,
Timer100Ns=0x20510500,
SampleFraction=0x20C20400,
CounterTimerInverse=0x21410500,
Timer100NsInverse=0x21510500,
CounterMultiTimer=0x22410500,
CounterMultiTimer100Ns=0x22510500,
CounterMultiTimerInverse=0x23410500,
CounterMultiTimer100NsInverse=0x23510500,
AverageTimer32=0x30020400,
ElapsedTime=0x30240500,
AverageCount64=0x40020500,
SampleBase=0x40030401,
AverageBase=0x40030402,
RawBase=0x40030403,
CounterMultiBase=0x42030500
};
enum {
SingleInstance,
MultiInstance,
CatTypeUnknown = -1
};
#define PERFCTR_CAT(id,name,help,type,first_counter) CATEGORY_ ## id,
#define PERFCTR_COUNTER(id,name,help,type)
enum {
#include "mono-perfcounters-def.h"
NUM_CATEGORIES
};
#undef PERFCTR_CAT
#undef PERFCTR_COUNTER
#define PERFCTR_CAT(id,name,help,type,first_counter) CATEGORY_START_ ## id = -1,
#define PERFCTR_COUNTER(id,name,help,type) COUNTER_ ## id,
/* each counter is assigned an id starting from 0 inside the category */
enum {
#include "mono-perfcounters-def.h"
END_COUNTERS
};
#undef PERFCTR_CAT
#undef PERFCTR_COUNTER
#define PERFCTR_CAT(id,name,help,type,first_counter)
#define PERFCTR_COUNTER(id,name,help,type) CCOUNTER_ ## id,
/* this is used just to count the number of counters */
enum {
#include "mono-perfcounters-def.h"
NUM_COUNTERS
};
typedef struct {
const char *name;
const char *help;
unsigned char id;
signed char type;
short first_counter;
} CategoryDesc;
typedef struct {
const char *name;
const char *help;
int id;
int type;
} CounterDesc;
#undef PERFCTR_CAT
#undef PERFCTR_COUNTER
#define PERFCTR_CAT(id,name,help,type,first_counter) {name, help, CATEGORY_ ## id, type, CCOUNTER_ ## first_counter},
#define PERFCTR_COUNTER(id,name,help,type)
static const CategoryDesc
predef_categories [] = {
#include "mono-perfcounters-def.h"
{NULL, NULL, NUM_CATEGORIES, -1, NUM_COUNTERS}
};
#undef PERFCTR_CAT
#undef PERFCTR_COUNTER
#define PERFCTR_CAT(id,name,help,type,first_counter)
#define PERFCTR_COUNTER(id,name,help,type) {name, help, COUNTER_ ## id, type},
static const CounterDesc
predef_counters [] = {
#include "mono-perfcounters-def.h"
{NULL, NULL, -1, 0}
};
/*
* We have several different classes of counters:
* *) system counters
* *) runtime counters
* *) remote counters
* *) user-defined counters
* *) windows counters (the implementation on windows will use this)
*
* To easily handle the differences we create a vtable for each class that contains the
* function pointers with the actual implementation to access the counters.
*/
typedef struct _ImplVtable ImplVtable;
typedef MonoBoolean (*SampleFunc) (ImplVtable *vtable, MonoBoolean only_value, MonoCounterSample* sample);
typedef gint64 (*UpdateFunc) (ImplVtable *vtable, MonoBoolean do_incr, gint64 value);
struct _ImplVtable {
void *arg;
SampleFunc sample;
UpdateFunc update;
};
static ImplVtable*
create_vtable (void *arg, SampleFunc sample, UpdateFunc update)
{
ImplVtable *vtable = g_new (ImplVtable, 1);
vtable->arg = arg;
vtable->sample = sample;
vtable->update = update;
return vtable;
}
MonoPerfCounters *mono_perfcounters = NULL;
void
mono_perfcounters_init (void)
{
/* later allocate in the shared memory area */
mono_perfcounters = g_new0 (MonoPerfCounters, 1);
}
static int
mono_string_compare_ascii (MonoString *str, const char *ascii_str)
{
guint16 *strc = mono_string_chars (str);
while (*strc == *ascii_str++) {
if (*strc == 0)
return 0;
strc++;
}
return *strc - *(const unsigned char *)(ascii_str - 1);
}
/* fill the info in sample (except the raw value) */
static void
fill_sample (MonoCounterSample *sample)
{
sample->timeStamp = mono_100ns_ticks ();
sample->timeStamp100nSec = sample->timeStamp;
sample->counterTimeStamp = sample->timeStamp;
sample->counterFrequency = 10000000;
sample->systemFrequency = 10000000;
// the real basevalue needs to be get from a different counter...
sample->baseValue = 0;
}
static int
id_from_string (MonoString *instance)
{
int id = -1;
if (mono_string_length (instance)) {
char *id_str = mono_string_to_utf8 (instance);
char *end;
id = strtol (id_str, &end, 0);
g_free (id_str);
if (end == id_str)
return -1;
}
return id;
}
static void
get_cpu_times (int cpu_id, gint64 *user, gint64 *systemt, gint64 *irq, gint64 *sirq, gint64 *idle)
{
char buf [256];
char *s;
int hz = 100 * 2; // 2 numprocs
gint64 user_ticks, nice_ticks, system_ticks, idle_ticks, iowait_ticks, irq_ticks, sirq_ticks;
FILE *f = fopen ("/proc/stat", "r");
if (!f)
return;
while ((s = fgets (buf, sizeof (buf), f))) {
char *data = NULL;
if (cpu_id < 0 && strncmp (s, "cpu", 3) == 0 && g_ascii_isspace (s [3])) {
data = s + 4;
} else if (cpu_id >= 0 && strncmp (s, "cpu", 3) == 0 && strtol (s + 3, &data, 10) == cpu_id) {
if (data == s + 3)
continue;
data++;
} else {
continue;
}
sscanf (data, "%Lu %Lu %Lu %Lu %Lu %Lu %Lu", &user_ticks, &nice_ticks, &system_ticks, &idle_ticks, &iowait_ticks, &irq_ticks, &sirq_ticks);
}
fclose (f);
if (user)
*user = (user_ticks + nice_ticks) * 10000000 / hz;
if (systemt)
*systemt = (system_ticks) * 10000000 / hz;
if (irq)
*irq = (irq_ticks) * 10000000 / hz;
if (sirq)
*sirq = (sirq_ticks) * 10000000 / hz;
if (idle)
*idle = (idle_ticks) * 10000000 / hz;
}
static MonoBoolean
get_cpu_counter (ImplVtable *vtable, MonoBoolean only_value, MonoCounterSample *sample)
{
gint64 value = 0;
int id = GPOINTER_TO_INT (vtable->arg);
int pid = id >> 5;
id &= 0x1f;
if (!only_value) {
fill_sample (sample);
sample->baseValue = 1;
}
sample->counterType = predef_counters [predef_categories [CATEGORY_PROC].first_counter + id].type;
switch (id) {
case COUNTER_CPU_USER_TIME:
get_cpu_times (pid, &value, NULL, NULL, NULL, NULL);
sample->rawValue = value;
return TRUE;
case COUNTER_CPU_PRIV_TIME:
get_cpu_times (pid, NULL, &value, NULL, NULL, NULL);
sample->rawValue = value;
return TRUE;
case COUNTER_CPU_INTR_TIME:
get_cpu_times (pid, NULL, NULL, &value, NULL, NULL);
sample->rawValue = value;
return TRUE;
case COUNTER_CPU_DCP_TIME:
get_cpu_times (pid, NULL, NULL, NULL, &value, NULL);
sample->rawValue = value;
return TRUE;
case COUNTER_CPU_PROC_TIME:
get_cpu_times (pid, NULL, NULL, NULL, NULL, &value);
sample->rawValue = value;
return TRUE;
}
return FALSE;
}
static void*
cpu_get_impl (MonoString* counter, MonoString* instance, int *type, MonoBoolean *custom)
{
int id = id_from_string (instance) << 5;
int i;
const CategoryDesc *desc = &predef_categories [CATEGORY_CPU];
*custom = FALSE;
/* increase the shift above and the mask also in the implementation functions */
g_assert (32 > desc [1].first_counter - desc->first_counter);
for (i = desc->first_counter; i < desc [1].first_counter; ++i) {
const CounterDesc *cdesc = &predef_counters [i];
if (mono_string_compare_ascii (counter, cdesc->name) == 0) {
*type = cdesc->type;
return create_vtable (GINT_TO_POINTER (id | cdesc->id), get_cpu_counter, NULL);
}
}
return NULL;
}
/*
* /proc/pid/stat format:
* pid (cmdname) S
* [0] ppid pgid sid tty_nr tty_pgrp flags min_flt cmin_flt maj_flt cmaj_flt
* [10] utime stime cutime cstime prio nice threads start_time vsize rss
* [20] rsslim start_code end_code start_stack esp eip pending blocked sigign sigcatch
* [30] wchan 0 0 exit_signal cpu rt_prio policy
*/
static gint64
get_process_time (int pid, int pos, int sum)
{
char buf [512];
char *s, *end;
FILE *f;
int len, i;
gint64 value;
g_snprintf (buf, sizeof (buf), "/proc/%d/stat", pid);
f = fopen (buf, "r");
if (!f)
return 0;
len = fread (buf, 1, sizeof (buf), f);
fclose (f);
if (len <= 0)
return 0;
s = strchr (buf, ')');
if (!s)
return 0;
s++;
while (g_ascii_isspace (*s)) s++;
if (!*s)
return 0;
/* skip the status char */
while (*s && !g_ascii_isspace (*s)) s++;
if (!*s)
return 0;
for (i = 0; i < pos; ++i) {
while (g_ascii_isspace (*s)) s++;
if (!*s)
return 0;
while (*s && !g_ascii_isspace (*s)) s++;
if (!*s)
return 0;
}
/* we are finally at the needed item */
value = strtoul (s, &end, 0);
/* add also the following value */
if (sum) {
while (g_ascii_isspace (*s)) s++;
if (!*s)
return 0;
value += strtoul (s, &end, 0);
}
return value;
}
static gint64
get_pid_stat_item (int pid, const char *item)
{
char buf [256];
char *s;
FILE *f;
int len = strlen (item);
g_snprintf (buf, sizeof (buf), "/proc/%d/status", pid);
f = fopen (buf, "r");
if (!f)
return 0;
while ((s = fgets (buf, sizeof (buf), f))) {
if (*item != *buf)
continue;
if (strncmp (buf, item, len))
continue;
if (buf [len] != ':')
continue;
fclose (f);
return atoi (buf + len + 1);
}
fclose (f);
return 0;
}
static MonoBoolean
get_process_counter (ImplVtable *vtable, MonoBoolean only_value, MonoCounterSample *sample)
{
int id = GPOINTER_TO_INT (vtable->arg);
int pid = id >> 5;
if (pid < 0)
return FALSE;
id &= 0x1f;
if (!only_value) {
fill_sample (sample);
sample->baseValue = 1;
}
sample->counterType = predef_counters [predef_categories [CATEGORY_PROC].first_counter + id].type;
switch (id) {
case COUNTER_PROC_USER_TIME:
sample->rawValue = get_process_time (pid, 12, FALSE);
return TRUE;
case COUNTER_PROC_PRIV_TIME:
sample->rawValue = get_process_time (pid, 13, FALSE);
return TRUE;
case COUNTER_PROC_PROC_TIME:
sample->rawValue = get_process_time (pid, 12, TRUE);
return TRUE;
case COUNTER_PROC_THREADS:
sample->rawValue = get_pid_stat_item (pid, "Threads");
return TRUE;
case COUNTER_PROC_VBYTES:
sample->rawValue = get_pid_stat_item (pid, "VmSize") * 1024;
return TRUE;
case COUNTER_PROC_WSET:
sample->rawValue = get_pid_stat_item (pid, "VmRSS") * 1024;
return TRUE;
case COUNTER_PROC_PBYTES:
sample->rawValue = get_pid_stat_item (pid, "VmData") * 1024;
return TRUE;
}
return FALSE;
}
static void*
process_get_impl (MonoString* counter, MonoString* instance, int *type, MonoBoolean *custom)
{
int id = id_from_string (instance) << 5;
int i;
const CategoryDesc *desc = &predef_categories [CATEGORY_PROC];
*custom = FALSE;
/* increase the shift above and the mask also in the implementation functions */
g_assert (32 > desc [1].first_counter - desc->first_counter);
for (i = desc->first_counter; i < desc [1].first_counter; ++i) {
const CounterDesc *cdesc = &predef_counters [i];
if (mono_string_compare_ascii (counter, cdesc->name) == 0) {
*type = cdesc->type;
return create_vtable (GINT_TO_POINTER (id | cdesc->id), get_process_counter, NULL);
}
}
return NULL;
}
static MonoBoolean
mono_mem_counter (ImplVtable *vtable, MonoBoolean only_value, MonoCounterSample *sample)
{
int id = GPOINTER_TO_INT (vtable->arg);
if (!only_value) {
fill_sample (sample);
sample->baseValue = 1;
}
sample->counterType = predef_counters [predef_categories [CATEGORY_MONO_MEM].first_counter + id].type;
switch (id) {
case COUNTER_MEM_NUM_OBJECTS:
sample->rawValue = mono_stats.new_object_count;
return TRUE;
}
return FALSE;
}
static void*
mono_mem_get_impl (MonoString* counter, MonoString* instance, int *type, MonoBoolean *custom)
{
int i;
const CategoryDesc *desc = &predef_categories [CATEGORY_MONO_MEM];
*custom = FALSE;
for (i = desc->first_counter; i < desc [1].first_counter; ++i) {
const CounterDesc *cdesc = &predef_counters [i];
if (mono_string_compare_ascii (counter, cdesc->name) == 0) {
*type = cdesc->type;
return create_vtable (GINT_TO_POINTER (cdesc->id), mono_mem_counter, NULL);
}
}
return NULL;
}
/* consider storing the pointer directly in vtable->arg, so the runtime overhead is lower:
* this needs some way to set sample->counterType as well, though.
*/
static MonoBoolean
predef_writable_counter (ImplVtable *vtable, MonoBoolean only_value, MonoCounterSample *sample)
{
int cat_id = GPOINTER_TO_INT (vtable->arg);
int id = cat_id >> 16;
cat_id &= 0xffff;
if (!only_value) {
fill_sample (sample);
sample->baseValue = 1;
}
sample->counterType = predef_counters [predef_categories [cat_id].first_counter + id].type;
switch (id) {
case COUNTER_ASPNET_REQ_Q:
sample->rawValue = mono_perfcounters->aspnet_requests_queued;
return TRUE;
}
return FALSE;
}
static gint64
predef_writable_update (ImplVtable *vtable, MonoBoolean do_incr, gint64 value)
{
glong *ptr = NULL;
int cat_id = GPOINTER_TO_INT (vtable->arg);
int id = cat_id >> 16;
cat_id &= 0xffff;
switch (cat_id) {
case CATEGORY_ASPNET:
switch (id) {
case COUNTER_ASPNET_REQ_Q: ptr = (glong*)&mono_perfcounters->aspnet_requests_queued; break;
}
break;
}
if (ptr) {
if (do_incr) {
/* FIXME: we need to do this atomically */
*ptr += value;
return *ptr;
}
/* this can be non-atomic */
*ptr = value;
return value;
}
return 0;
}
static void*
predef_writable_get_impl (int cat, MonoString* counter, MonoString* instance, int *type, MonoBoolean *custom)
{
int i;
const CategoryDesc *desc = &predef_categories [cat];
*custom = TRUE;
for (i = desc->first_counter; i < desc [1].first_counter; ++i) {
const CounterDesc *cdesc = &predef_counters [i];
if (mono_string_compare_ascii (counter, cdesc->name) == 0) {
*type = cdesc->type;
return create_vtable (GINT_TO_POINTER ((cdesc->id << 16) | cat), predef_writable_counter, predef_writable_update);
}
}
return NULL;
}
static const CategoryDesc*
find_category (MonoString *category)
{
int i;
for (i = 0; i < NUM_CATEGORIES; ++i) {
if (mono_string_compare_ascii (category, predef_categories [i].name) == 0)
return &predef_categories [i];
}
return NULL;
}
void*
mono_perfcounter_get_impl (MonoString* category, MonoString* counter, MonoString* instance,
MonoString* machine, int *type, MonoBoolean *custom)
{
const CategoryDesc *cdesc;
/* no support for counters on other machines */
if (mono_string_compare_ascii (machine, "."))
return NULL;
cdesc = find_category (category);
if (!cdesc)
return NULL;
switch (cdesc->id) {
case CATEGORY_CPU:
return cpu_get_impl (counter, instance, type, custom);
case CATEGORY_PROC:
return process_get_impl (counter, instance, type, custom);
case CATEGORY_MONO_MEM:
return mono_mem_get_impl (counter, instance, type, custom);
case CATEGORY_ASPNET:
return predef_writable_get_impl (cdesc->id, counter, instance, type, custom);
}
return NULL;
}
MonoBoolean
mono_perfcounter_get_sample (void *impl, MonoBoolean only_value, MonoCounterSample *sample)
{
ImplVtable *vtable = impl;
if (vtable && vtable->sample)
return vtable->sample (vtable, only_value, sample);
return FALSE;
}
gint64
mono_perfcounter_update_value (void *impl, MonoBoolean do_incr, gint64 value)
{
ImplVtable *vtable = impl;
if (vtable && vtable->update)
return vtable->update (vtable, do_incr, value);
return 0;
}
void
mono_perfcounter_free_data (void *impl)
{
g_free (impl);
}
/* Category icalls */
MonoBoolean
mono_perfcounter_category_del (MonoString *name)
{
return FALSE;
}
MonoString*
mono_perfcounter_category_help (MonoString *category, MonoString *machine)
{
const CategoryDesc *cdesc;
/* no support for counters on other machines */
if (mono_string_compare_ascii (machine, "."))
return NULL;
cdesc = find_category (category);
if (!cdesc)
return NULL;
return mono_string_new (mono_domain_get (), cdesc->help);
}
MonoBoolean
mono_perfcounter_category_exists (MonoString *counter, MonoString *category, MonoString *machine)
{
int i;
const CategoryDesc *cdesc;
/* no support for counters on other machines */
if (mono_string_compare_ascii (machine, "."))
return FALSE;
cdesc = find_category (category);
if (!cdesc)
return FALSE;
/* counter is allowed to be null */
if (!counter)
return TRUE;
for (i = cdesc->first_counter; i < cdesc [1].first_counter; ++i) {
const CounterDesc *desc = &predef_counters [i];
if (mono_string_compare_ascii (counter, desc->name) == 0)
return TRUE;
}
return FALSE;
}
/*
* Since we'll keep a copy of the category per-process, we should also make sure
* categories with the same name are compatible.
*/
MonoBoolean
mono_perfcounter_create (MonoString *category, MonoString *help, int type, MonoArray *items)
{
return FALSE;
}
int
mono_perfcounter_instance_exists (MonoString *instance, MonoString *category, MonoString *machine)
{
const CategoryDesc *cdesc;
/* no support for counters on other machines */
if (mono_string_compare_ascii (machine, "."))
return FALSE;
cdesc = find_category (category);
if (!cdesc)
return FALSE;
return FALSE;
}
MonoArray*
mono_perfcounter_category_names (MonoString *machine)
{
int i;
MonoArray *res;
MonoDomain *domain = mono_domain_get ();
/* no support for counters on other machines */
if (mono_string_compare_ascii (machine, "."))
return mono_array_new (domain, mono_get_string_class (), 0);
res = mono_array_new (domain, mono_get_string_class (), NUM_CATEGORIES);
for (i = 0; i < NUM_CATEGORIES; ++i) {
const CategoryDesc *cdesc = &predef_categories [i];
mono_array_setref (res, i, mono_string_new (domain, cdesc->name));
}
return res;
}
MonoArray*
mono_perfcounter_counter_names (MonoString *category, MonoString *machine)
{
int i;
const CategoryDesc *cdesc;
MonoArray *res;
MonoDomain *domain = mono_domain_get ();
/* no support for counters on other machines */
if (mono_string_compare_ascii (machine, ".") || !(cdesc = find_category (category)))
return mono_array_new (domain, mono_get_string_class (), 0);
res = mono_array_new (domain, mono_get_string_class (), cdesc [1].first_counter - cdesc->first_counter);
for (i = cdesc->first_counter; i < cdesc [1].first_counter; ++i) {
const CounterDesc *desc = &predef_counters [i];
mono_array_setref (res, i - cdesc->first_counter, mono_string_new (domain, desc->name));
}
return res;
}
MonoArray*
mono_perfcounter_instance_names (MonoString *category, MonoString *machine)
{
return mono_array_new (mono_domain_get (), mono_get_string_class (), 0);
}