40
40
*/
41
41
package com .oracle .graal .python .builtins .modules ;
42
42
43
- import static com .oracle .graal .python .runtime .exception .PythonErrorType .NotImplementedError ;
44
43
import static com .oracle .graal .python .runtime .exception .PythonErrorType .ValueError ;
45
44
46
45
import java .lang .management .ManagementFactory ;
56
55
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
57
56
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
58
57
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
58
+ import com .oracle .truffle .api .TruffleOptions ;
59
59
import com .oracle .truffle .api .dsl .Fallback ;
60
60
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
61
61
import com .oracle .truffle .api .dsl .NodeFactory ;
@@ -78,17 +78,24 @@ abstract static class GetRuUsageNode extends PythonBuiltinNode {
78
78
@ Specialization (guards = {"who == RUSAGE_THREAD" })
79
79
@ TruffleBoundary
80
80
PTuple getruusageThread (@ SuppressWarnings ("unused" ) int who ) {
81
- ThreadMXBean threadMXBean = ManagementFactory .getThreadMXBean ();
82
81
long id = Thread .currentThread ().getId ();
83
- double ru_utime = threadMXBean .getThreadUserTime (id ) / 1000000000.0 ; // time in user mode (float)
84
- double ru_stime = threadMXBean .getThreadCpuTime (id ) / 1000000000.0 ; // time in system mode (float)
82
+ Runtime runtime = Runtime .getRuntime ();
85
83
84
+ double ru_utime = -1 ; // time in user mode (float)
85
+ double ru_stime = -1 ; // time in system mode (float)
86
86
long ru_maxrss ; // maximum resident set size
87
- if (threadMXBean instanceof com .sun .management .ThreadMXBean ) {
88
- com .sun .management .ThreadMXBean thMxBean = (com .sun .management .ThreadMXBean ) threadMXBean ;
89
- ru_maxrss = thMxBean .getThreadAllocatedBytes (id );
87
+
88
+ if (!TruffleOptions .AOT ) {
89
+ ThreadMXBean threadMXBean = ManagementFactory .getThreadMXBean ();
90
+ ru_utime = threadMXBean .getThreadUserTime (id ) / 1000000000.0 ;
91
+ ru_stime = threadMXBean .getThreadCpuTime (id ) / 1000000000.0 ;
92
+ if (threadMXBean instanceof com .sun .management .ThreadMXBean ) {
93
+ com .sun .management .ThreadMXBean thMxBean = (com .sun .management .ThreadMXBean ) threadMXBean ;
94
+ ru_maxrss = thMxBean .getThreadAllocatedBytes (id );
95
+ } else {
96
+ ru_maxrss = runtime .maxMemory ();
97
+ }
90
98
} else {
91
- Runtime runtime = Runtime .getRuntime ();
92
99
ru_maxrss = runtime .maxMemory ();
93
100
}
94
101
@@ -119,18 +126,28 @@ PTuple getruusageThread(@SuppressWarnings("unused") int who) {
119
126
@ Specialization (guards = {"who == RUSAGE_SELF" })
120
127
@ TruffleBoundary
121
128
PTuple getruusageSelf (@ SuppressWarnings ("unused" ) int who ) {
122
- ThreadMXBean threadMXBean = ManagementFactory .getThreadMXBean ();
123
- double ru_utime = 0 ; // time in user mode (float)
124
- double ru_stime = 0 ; // time in system mode (float)
125
- for (long thId : threadMXBean .getAllThreadIds ()) {
126
- ru_utime += threadMXBean .getThreadUserTime (thId ) / 1000000000.0 ;
127
- ru_stime += threadMXBean .getThreadCpuTime (thId ) / 1000000000.0 ;
128
- }
129
+ Runtime runtime = Runtime .getRuntime ();
130
+
131
+ double ru_utime = -1 ; // time in user mode (float)
132
+ double ru_stime = -1 ; // time in system mode (float)
133
+ long ru_maxrss ;
134
+
135
+ if (!TruffleOptions .AOT ) {
136
+ ru_utime = 0 ;
137
+ ru_stime = 0 ;
138
+ ThreadMXBean threadMXBean = ManagementFactory .getThreadMXBean ();
139
+ for (long thId : threadMXBean .getAllThreadIds ()) {
140
+ ru_utime += threadMXBean .getThreadUserTime (thId ) / 1000000000.0 ;
141
+ ru_stime += threadMXBean .getThreadCpuTime (thId ) / 1000000000.0 ;
142
+ }
129
143
130
- MemoryMXBean memoryMXBean = ManagementFactory .getMemoryMXBean ();
131
- MemoryUsage heapMemoryUsage = memoryMXBean .getHeapMemoryUsage ();
132
- MemoryUsage nonHeapMemoryUsage = memoryMXBean .getNonHeapMemoryUsage ();
133
- long ru_maxrss = heapMemoryUsage .getCommitted () + nonHeapMemoryUsage .getCommitted ();
144
+ MemoryMXBean memoryMXBean = ManagementFactory .getMemoryMXBean ();
145
+ MemoryUsage heapMemoryUsage = memoryMXBean .getHeapMemoryUsage ();
146
+ MemoryUsage nonHeapMemoryUsage = memoryMXBean .getNonHeapMemoryUsage ();
147
+ ru_maxrss = heapMemoryUsage .getCommitted () + nonHeapMemoryUsage .getCommitted ();
148
+ } else {
149
+ ru_maxrss = runtime .maxMemory ();
150
+ }
134
151
135
152
String osName = System .getProperty ("os.name" );
136
153
if (osName .contains ("Linux" )) {
0 commit comments