line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include |
2
|
|
|
|
|
|
|
#include |
3
|
|
|
|
|
|
|
#include "duk_console.h" |
4
|
|
|
|
|
|
|
#include "pl_util.h" |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#define FILE_MEMORY_STATUS "/proc/self/statm" |
7
|
|
|
|
|
|
|
|
8
|
4000758
|
|
|
|
|
|
double now_us(void) |
9
|
|
|
|
|
|
|
{ |
10
|
|
|
|
|
|
|
struct timeval tv; |
11
|
4000758
|
|
|
|
|
|
double now = 0.0; |
12
|
4000758
|
|
|
|
|
|
int rc = gettimeofday(&tv, 0); |
13
|
4000758
|
50
|
|
|
|
|
if (rc == 0) { |
14
|
4000758
|
|
|
|
|
|
now = 1000000.0 * tv.tv_sec + tv.tv_usec; |
15
|
|
|
|
|
|
|
} |
16
|
4000758
|
|
|
|
|
|
return now; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
20
|
|
|
|
|
|
long total_memory_pages(void) |
20
|
|
|
|
|
|
|
{ |
21
|
20
|
|
|
|
|
|
long pages = 0; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
/* |
24
|
|
|
|
|
|
|
* /proc/[pid]/statm |
25
|
|
|
|
|
|
|
* Provides information about memory usage, measured in pages. |
26
|
|
|
|
|
|
|
* size total program size |
27
|
|
|
|
|
|
|
* (same as VmSize in /proc/[pid]/status) |
28
|
|
|
|
|
|
|
* resident resident set size |
29
|
|
|
|
|
|
|
* (same as VmRSS in /proc/[pid]/status) |
30
|
|
|
|
|
|
|
* share shared pages (from shared mappings) |
31
|
|
|
|
|
|
|
* text text (code) |
32
|
|
|
|
|
|
|
* lib library (unused in Linux 2.6) |
33
|
|
|
|
|
|
|
* data data + stack |
34
|
|
|
|
|
|
|
* dirty dirty pages (unused in Linux 2.6) |
35
|
|
|
|
|
|
|
*/ |
36
|
20
|
|
|
|
|
|
FILE* fp = 0; |
37
|
|
|
|
|
|
|
do { |
38
|
|
|
|
|
|
|
long size, resident, share, text, lib, data, dpages; |
39
|
|
|
|
|
|
|
int nread; |
40
|
20
|
|
|
|
|
|
fp = fopen(FILE_MEMORY_STATUS, "r"); |
41
|
20
|
50
|
|
|
|
|
if (!fp) { |
42
|
|
|
|
|
|
|
/* silently ignore, some OSs do not have this file */ |
43
|
0
|
|
|
|
|
|
break; |
44
|
|
|
|
|
|
|
} |
45
|
20
|
|
|
|
|
|
nread = fscanf(fp, "%ld %ld %ld %ld %ld %ld %ld", |
46
|
|
|
|
|
|
|
&size, &resident, &share, &text, &lib, &data, &dpages); |
47
|
20
|
50
|
|
|
|
|
if (nread != 7) { |
48
|
|
|
|
|
|
|
/* silently ignore, avoid noisy errors */ |
49
|
0
|
|
|
|
|
|
break; |
50
|
|
|
|
|
|
|
} |
51
|
20
|
|
|
|
|
|
pages = size; |
52
|
|
|
|
|
|
|
} while (0); |
53
|
20
|
50
|
|
|
|
|
if (fp) { |
54
|
20
|
|
|
|
|
|
fclose(fp); |
55
|
20
|
|
|
|
|
|
fp = 0; |
56
|
|
|
|
|
|
|
} |
57
|
20
|
|
|
|
|
|
return pages; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
4000699
|
|
|
|
|
|
int check_duktape_call_for_errors(int rc, duk_context* ctx) |
61
|
|
|
|
|
|
|
{ |
62
|
4000699
|
100
|
|
|
|
|
if (rc == DUK_EXEC_SUCCESS) { |
63
|
|
|
|
|
|
|
/* no error */ |
64
|
4000687
|
|
|
|
|
|
return 1; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
12
|
50
|
|
|
|
|
if (duk_is_error(ctx, -1)) { |
68
|
|
|
|
|
|
|
/* |
69
|
|
|
|
|
|
|
* Error and we should have a stack trace. |
70
|
|
|
|
|
|
|
* Accessing .stack might cause an error to be thrown, so wrap this |
71
|
|
|
|
|
|
|
* access in a duk_safe_call() if it matters. |
72
|
|
|
|
|
|
|
*/ |
73
|
12
|
|
|
|
|
|
duk_get_prop_string(ctx, -1, "stack"); |
74
|
12
|
|
|
|
|
|
duk_console_log(DUK_CONSOLE_FLUSH | DUK_CONSOLE_TO_STDERR, |
75
|
|
|
|
|
|
|
"error: %s\n", duk_safe_to_string(ctx, -1)); |
76
|
12
|
|
|
|
|
|
duk_pop(ctx); |
77
|
12
|
|
|
|
|
|
return 0; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
/* |
81
|
|
|
|
|
|
|
* Error without a stack trace. |
82
|
|
|
|
|
|
|
* Non-Error value, coerce safely to string. |
83
|
|
|
|
|
|
|
*/ |
84
|
0
|
|
|
|
|
|
duk_console_log(DUK_CONSOLE_FLUSH | DUK_CONSOLE_TO_STDERR, |
85
|
|
|
|
|
|
|
"error: %s\n", duk_safe_to_string(ctx, -1)); |
86
|
0
|
|
|
|
|
|
return 1; |
87
|
|
|
|
|
|
|
} |