11from tkinter import *
2+ from controller import Model
23
34from view .base_view import Baseview
45
@@ -9,23 +10,46 @@ def __init__(self,root) -> None:
910 self .root = root
1011 self .frame = Frame (self .root ,width = self .width ,height = self .height )
1112 label = Label (self .frame ,text = "Memory profiling" )
12- label . pack ()
13+ copy = Model . MEMORY_STAMPS . copy ()
1314
15+ mlist = list (copy .values ())
16+ if len (copy ) > 0 :
17+ self .canvas = Canvas (self .frame ,bg = self .color ,width = self .width ,height = self .height ,scrollregion = (0 ,0 ,max (self .rectange_width * len (copy ),self .width ),max (max (mlist ).end_memory - max (mlist ).start_memory ,self .height * self .canvas_scaler )))
18+ else :
19+ self .canvas = Canvas (self .frame ,bg = self .color ,width = self .width ,height = self .height ,scrollregion = (0 ,0 ,self .width * self .canvas_scaler ,self .height * self .canvas_scaler ))
1420 def draw (self ):
1521 self .frame .pack (expand = True , fill = BOTH )
16- canvas = Canvas ( self . frame , bg = self . color , width = self . width , height = self . height , scrollregion = ( 0 , 0 , self . width * self . canvas_scaler , self . height * self . canvas_scaler ))
22+
1723 hbar = Scrollbar (self .frame ,orient = HORIZONTAL )
1824 hbar .pack (side = BOTTOM ,fill = X )
19- hbar .config (command = canvas .xview )
25+ hbar .config (command = self . canvas .xview )
2026 vbar = Scrollbar (self .frame ,orient = VERTICAL )
2127 vbar .pack (side = RIGHT ,fill = Y )
22- vbar .config (command = canvas .yview )
23- canvas .config (width = self .width ,height = self .height )
24- canvas .config (xscrollcommand = hbar .set , yscrollcommand = vbar .set )
25- canvas .pack (side = LEFT ,expand = True ,fill = BOTH )
28+ vbar .config (command = self .canvas .yview )
29+ self .canvas .config (width = self .width ,height = self .height )
30+ self .canvas .config (xscrollcommand = hbar .set , yscrollcommand = vbar .set )
31+ self .canvas .pack (side = LEFT ,expand = True ,fill = BOTH )
32+ self .update ()
2633
27- def draw_rect (self ,x1 ,x2 ,y1 ,y2 ):
28- self .canvas .create_rectangle ((x1 ,x2 ,y1 ,y2 ))
29-
30- def destroy (self ):
31- self .frame .destroy ()
34+ def update (self ):
35+ copy = Model .MEMORY_STAMPS .copy ()
36+ if len (copy ) <= 0 :
37+ return
38+ mlist = list (copy .values ())
39+ mlist_sorted = sorted (mlist )
40+ max_mlist = max (mlist )
41+ for index ,i in enumerate (mlist_sorted ):
42+ memory_stamp = i
43+ memory_leaked = memory_stamp .end_memory - memory_stamp .start_memory
44+ if memory_leaked == 0 :
45+ continue
46+ self .scaler = 1 / 10
47+ x = index * (self .rectange_width + self .rectange_spacing )
48+ y = (max_mlist .end_memory - max_mlist .start_memory ) * self .scaler
49+ width = x + self .rectange_width + 50
50+ height = memory_leaked * self .scaler # it is in kb
51+ self .draw_rect ( x ,y ,width ,height )
52+
53+ self .canvas .create_text ((x + width )/ 2 ,(y + height )/ 2 - self .rectange_height / 3 , text = memory_stamp .name , fill = "white" )
54+ self .canvas .create_text ((x + width )/ 2 ,(y + height )/ 2 , text = 'memory_leaked: ' + str (memory_leaked ), fill = "white" )
55+ self .canvas .create_text ((x + width )/ 2 ,(y + height )/ 2 + self .rectange_height / 3 , text = memory_stamp .id , fill = "white" )
0 commit comments