forked from TritonDataCenter/statemap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlx-cmd-statemap.d
102 lines (85 loc) · 2.16 KB
/
lx-cmd-statemap.d
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
#!/usr/sbin/dtrace -Cs
/*
* Copyright 2017, Joyent, Inc.
*/
#pragma D option quiet
#pragma D option destructive
#define T_WAKEABLE 0x0002
typedef enum {
STATE_ON_CPU = 0,
STATE_OFF_CPU_WAITING = 1,
STATE_OFF_CPU_FUTEX = 2,
STATE_OFF_CPU_IO = 3,
STATE_OFF_CPU_BLOCKED = 4,
STATE_OFF_CPU_DEAD = 5,
STATE_MAX = 6
} state_t;
#define STATE_METADATA(_state, _str, _color) \
printf("\t\t\"%s\": {\"value\": %d, \"color\": \"%s\" }%s\n", \
_str, _state, _color, _state < STATE_MAX - 1 ? "," : "");
BEGIN
{
wall = walltimestamp;
printf("{\n\t\"start\": [ %d, %d ],\n",
wall / 1000000000, wall % 1000000000);
printf("\t\"title\": \"all %s LX processes\",\n", $$1);
printf("\t\"host\": \"%s\",\n", `utsname.nodename);
printf("\t\"states\": {\n");
STATE_METADATA(STATE_ON_CPU, "on-cpu", "#DAF7A6")
STATE_METADATA(STATE_OFF_CPU_WAITING, "off-cpu-waiting", "#f9f9f9")
STATE_METADATA(STATE_OFF_CPU_FUTEX, "off-cpu-futex", "#f0f0f0")
STATE_METADATA(STATE_OFF_CPU_IO, "off-cpu-io", "#FFC300")
STATE_METADATA(STATE_OFF_CPU_BLOCKED, "off-cpu-blocked", "#C70039")
STATE_METADATA(STATE_OFF_CPU_DEAD, "off-cpu-dead", "#581845")
printf("\t}\n}\n");
start = timestamp;
}
zfs_fillpage:entry
/execname == $$1/
{
self->state = STATE_OFF_CPU_IO;
}
zfs_fillpage:return
/execname == $$1/
{
self->state = STATE_ON_CPU;
}
lx_futex:entry
/execname == $$1/
{
self->state = STATE_OFF_CPU_FUTEX;
}
lx_futex:return
/execname == $$1/
{
self->state = STATE_ON_CPU;
}
sched:::off-cpu
/execname == $$1/
{
printf("{ \"time\": \"%d\", \"entity\": \"%d/%d\", ",
timestamp - start, pid, tid);
printf("\"state\": %d }\n", self->state != STATE_ON_CPU ?
self->state : curthread->t_flag & T_WAKEABLE ?
STATE_OFF_CPU_WAITING : STATE_OFF_CPU_BLOCKED);
}
sched:::on-cpu
/execname == $$1/
{
self->state = STATE_ON_CPU;
printf("{ \"time\": \"%d\", \"entity\": \"%d/%d\", ",
timestamp - start, pid, tid);
printf("\"state\": %d }\n", self->state);
}
proc:::lwp-exit
/execname == $$1/
{
printf("{ \"time\": \"%d\", \"entity\": \"%d/%d\", ",
timestamp - start, pid, tid);
printf("\"state\": %d }\n", STATE_OFF_CPU_DEAD);
}
tick-1sec
/timestamp - start > 60 * 1000000000/
{
exit(0);
}