-
Notifications
You must be signed in to change notification settings - Fork 2
/
printStackTraceWorkerThread.js
30 lines (24 loc) · 1.14 KB
/
printStackTraceWorkerThread.js
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
/**
* Prints stack trace for worker threads for debugging
*/
const Common = Java.type('com.serotonin.m2m2.Common');
const BackgroundProcessingImpl = Java.type('com.serotonin.m2m2.rt.maint.BackgroundProcessingImpl');
const ThreadPoolExecutor = Java.type('java.util.concurrent.ThreadPoolExecutor');
const Worker = Java.type('java.util.concurrent.ThreadPoolExecutor$Worker');
//const fieldToAccess = "lowPriorityService";
const fieldToAccess = "mediumPriorityService";
//const fieldToAccess = "highPriorityService";
const priorityService = BackgroundProcessingImpl.class.getDeclaredField(fieldToAccess);
priorityService.setAccessible(true);
const priorityServiceObject = priorityService.get(Common.backgroundProcessing);
const workers = ThreadPoolExecutor.class.getDeclaredField('workers');
workers.setAccessible(true);
const workersObject = workers.get(priorityServiceObject);
const thread = Worker.class.getDeclaredField('thread');
thread.setAccessible(true);
workersObject.forEach(worker => {
const threadObject = thread.get(worker);
for(const line of threadObject.getStackTrace())
print(line);
print("--------------------------");
});