-
Notifications
You must be signed in to change notification settings - Fork 2
/
kpageflagswatch
executable file
·145 lines (118 loc) · 4.08 KB
/
kpageflagswatch
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk, gobject, os, array, sys, optparse
import pagemap
def pixel2page(x, y):
block = ((y >> 5) << 5) + (x >> 5)
return (block << 10) + ((y & 31) << 5) + (x & 31)
def page2pixel(page):
block = page >> 10
x = (block & 31) * 32
y = (block >> 5) * 32
x += (page & 1023) & 31
y += (page & 1023) >> 5
return x, y
class kpageflagswatch:
def __init__(self, source):
self.source = source and source or ""
self.amap = pagemap.archmap(self.source)
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("kpageflags")
window.connect("destroy", lambda w: gtk.main_quit())
vbox = gtk.VBox(False, 1)
window.add(vbox)
self.map = pagemap.kpageflags(self.source)
self.height = ((self.map.pages() - self.amap.pfn_offset() + 1023)/1024 + 31)/32 * 32
self.image = array.array('B', '\0'*1024*self.height*3)
self.area = gtk.DrawingArea()
self.area.set_size_request(1024,self.height)
self.area.set_events(gtk.gdk.POINTER_MOTION_MASK |
gtk.gdk.POINTER_MOTION_HINT_MASK )
self.area.connect("expose-event", self.area_expose_cb)
self.area.connect("motion-notify-event", self.motion_cb)
self.area.show()
vbox.add(self.area)
self.statusbar = gtk.Statusbar()
self.statusbar.show()
self.contextid = self.statusbar.get_context_id("")
vbox.add(self.statusbar)
vbox.show()
window.show()
self.style = self.area.get_style()
self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
self.timer()
self.window = window
def motion_cb(self, area, event):
x, y = area.get_pointer()
addr = pixel2page(x, y) * 4096
caption = "%08x:" % addr
self.statusbar.pop(self.contextid)
self.statusbar.push(self.contextid, caption)
def area_expose_cb(self, area, event):
self.draw_rgb_image()
return True
def timer(self):
self.update_image()
gobject.timeout_add(300, self.timer)
def update_image(self):
b = self.image
self.oldmap = self.map
self.map = pagemap.kpageflags(self.source)
p = self.map
op = self.oldmap
r = p.flags(self.amap.pfn_offset(), p.pages())
pix = 0
for i in xrange(len(r)):
x, y = page2pixel(i)
if y >= self.height:
continue
lastpix = pix
pix = 3 * (y * 1024 + x)
f = r[i]
#if f & (1 << 14):
# b[pix + 0] = b[lastpix + 0]
# b[pix + 1] = b[lastpix + 1]
# b[pix + 2] = b[lastpix + 2]
# continue
if f & (1 << 10): # buddy
b[pix + 0] = 0
b[pix + 1] = 0
b[pix + 2] = 0
continue
if f & (1 << 7): # slab
b[pix + 0] = 255
b[pix + 1] = 255
b[pix + 2] = 255
continue
if f & 1:
b[pix + 1] = 255 # locked
else:
b[pix + 1] = 0
if f & 16: # dirty
b[pix + 0] = 255
else:
b[pix + 0] = 0
if f & (1 << 5): # lru
b[pix + 2] = 128
elif f & (1 << 6): # active
b[pix + 2] = 255
else:
b[pix + 2] = 0
self.draw_rgb_image()
def draw_rgb_image(self):
self.area.window.draw_rgb_image(self.gc, 0, 0, 1024, self.height,
gtk.gdk.RGB_DITHER_NONE,
self.image.tostring(), 1024*3)
def main():
gtk.main()
return 0
if __name__ == "__main__":
parser = optparse.OptionParser("%prog [options]")
parser.add_option("-S", "--source", type="str",
help="/proc data source")
defaults = {}
parser.set_defaults(**defaults)
(options, args) = parser.parse_args()
kpageflagswatch(options.source)
main()