line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include "pl_util.h" |
2
|
|
|
|
|
|
|
#include "pl_stats.h" |
3
|
|
|
|
|
|
|
#include "ppport.h" |
4
|
|
|
|
|
|
|
|
5
|
20
|
|
|
|
|
|
static void save_stat(pTHX_ Duk* duk, const char* category, const char* name, double value) |
6
|
|
|
|
|
|
|
{ |
7
|
20
|
|
|
|
|
|
STRLEN clen = strlen(category); |
8
|
20
|
|
|
|
|
|
STRLEN nlen = strlen(name); |
9
|
20
|
|
|
|
|
|
HV* data = 0; |
10
|
20
|
|
|
|
|
|
SV* pvalue = 0; |
11
|
20
|
|
|
|
|
|
SV** found = hv_fetch(duk->stats, category, clen, 0); |
12
|
20
|
100
|
|
|
|
|
if (found) { |
13
|
18
|
|
|
|
|
|
SV* ref = SvRV(*found); |
14
|
|
|
|
|
|
|
/* value not a valid hashref? bail out */ |
15
|
18
|
50
|
|
|
|
|
if (SvTYPE(ref) != SVt_PVHV) { |
16
|
0
|
|
|
|
|
|
croak("Found category %s in stats but it is not a hashref\n", category); |
17
|
|
|
|
|
|
|
return; |
18
|
|
|
|
|
|
|
} |
19
|
18
|
|
|
|
|
|
data = (HV*) ref; |
20
|
|
|
|
|
|
|
} else { |
21
|
2
|
|
|
|
|
|
SV* ref = 0; |
22
|
2
|
|
|
|
|
|
data = newHV(); |
23
|
2
|
|
|
|
|
|
ref = newRV_noinc((SV*) data); |
24
|
2
|
50
|
|
|
|
|
if (hv_store(duk->stats, category, clen, ref, 0)) { |
25
|
2
|
|
|
|
|
|
SvREFCNT_inc(ref); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
0
|
|
|
|
|
|
croak("Could not create category %s in stats\n", category); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
20
|
|
|
|
|
|
pvalue = sv_2mortal(newSVnv(value)); |
33
|
20
|
50
|
|
|
|
|
if (hv_store(data, name, nlen, pvalue, 0)) { |
34
|
20
|
|
|
|
|
|
SvREFCNT_inc(pvalue); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
0
|
|
|
|
|
|
croak("Could not create entry %s for category %s in stats\n", name, category); |
38
|
|
|
|
|
|
|
} |
39
|
20
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
5004044
|
|
|
|
|
|
void pl_stats_start(pTHX_ Duk* duk, Stats* stats) |
42
|
|
|
|
|
|
|
{ |
43
|
5004044
|
100
|
|
|
|
|
if (!(duk->flags & DUK_OPT_FLAG_GATHER_STATS)) { |
44
|
5004034
|
|
|
|
|
|
return; |
45
|
|
|
|
|
|
|
} |
46
|
10
|
|
|
|
|
|
stats->t0 = now_us(); |
47
|
10
|
|
|
|
|
|
stats->m0 = total_memory_pages() * duk->pagesize_bytes; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
5004041
|
|
|
|
|
|
void pl_stats_stop(pTHX_ Duk* duk, Stats* stats, const char* name) |
51
|
|
|
|
|
|
|
{ |
52
|
5004041
|
100
|
|
|
|
|
if (!(duk->flags & DUK_OPT_FLAG_GATHER_STATS)) { |
53
|
5004031
|
|
|
|
|
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
10
|
|
|
|
|
|
stats->t1 = now_us(); |
56
|
10
|
|
|
|
|
|
stats->m1 = total_memory_pages() * duk->pagesize_bytes; |
57
|
|
|
|
|
|
|
|
58
|
10
|
|
|
|
|
|
save_stat(aTHX_ duk, name, "elapsed_us", stats->t1 - stats->t0); |
59
|
10
|
|
|
|
|
|
save_stat(aTHX_ duk, name, "memory_bytes", stats->m1 - stats->m0); |
60
|
|
|
|
|
|
|
} |