-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkpagecskipwatch
executable file
·125 lines (102 loc) · 3.48 KB
/
kpagecskipwatch
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
#!/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)
# return y * 1024 + x
def page2pixel(page):
block = page >> 10
x = (block & 31) * 32
y = (block >> 5) * 32
x += (page & 1023) & 31
y += (page & 1023) >> 5
# x = page % 1024
# y = page / 1024
return x, y
class kpageblockwatch:
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("kpagecskip")
window.connect("destroy", lambda w: gtk.main_quit())
vbox = gtk.VBox(False, 1)
window.add(vbox)
self.map = pagemap.kpagetype(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.map = pagemap.kpagetype(self.source)
p = self.map
t = p.flags(self.amap.pfn_offset(), p.pages())
pix = 0
i = 0
while i < len(t):
x, y = page2pixel(i)
if y >= self.height:
i += 1
continue
pix = 3 * (y * 1024 + x)
flag = t[i]
if flag == 1:
# red
b[pix + 0] = 255
b[pix + 1] = 0
b[pix + 2] = 0
else:
# green
b[pix + 0] = 0
b[pix + 1] = 255
b[pix + 2] = 0
i += 1
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()
kpageblockwatch(options.source)
main()