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
|
def draw_chunk_usage(chunks, range_, img_size=(1024, 128)):
start, end = range_
width, height = img_size
image = Image.new("RGB", img_size, "WHITE")
draw = ImageDraw.Draw(image)
red = ImageColor.getcolor("RED", "RGB")
green = ImageColor.getcolor("GREEN", "RGB")
black = ImageColor.getcolor("BLACK", "RGB")
white = ImageColor.getcolor("WHITE", "RGB")
for chunk in chunks:
chunk_start = chunk.as_address()
data_start = chunk.as_mem()
chunk_end = chunk_start + chunk.chunksize()
if chunk_start >= start and chunk_end <= end:
color = green if chunk.is_inuse() else red
# Draw heap chunk metadata rectangle first
# Leftmost top corner
x1 = ((((chunk_start - start) * width) // (end - start)), 0)
# Rightmost bottom corner
x2 = ((((data_start - start) * width) // (end - start)), height)
draw.rectangle((x1, x2), white, black)
# Then draw heap chunk data rectangle
x1 = ((((data_start - start) * width) // (end - start)), 0)
x2 = ((((chunk_end - start) * width) // (end - start)), height)
draw.rectangle((x1, x2), color, black)
draw.text((x1[0] + 10, x1[1] + 10), hexdump_as_bytes(data_start, 32), black)
return image |
Partager