/[eiffelstudio]/branches/eth/eve/Src/library/memory_analyzer/ma_draw_history.e
ViewVC logotype

Contents of /branches/eth/eve/Src/library/memory_analyzer/ma_draw_history.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 83441 - (show annotations)
Sat Jun 5 13:52:53 2010 UTC (9 years, 7 months ago) by jasonw
File size: 6744 byte(s)
Renamed branch eve3 to eve. The eve branch serves as the new branch for the EVE project.
1 note
2 description: "Draw history of the memory useage."
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 date: "$Date$"
6 revision: "$Revision$"
7
8 class
9 MA_DRAW_HISTORY
10
11 inherit
12 MA_DRAW_STATISTIC
13
14 MA_SINGLETON_FACTORY
15 export
16 {NONE} all
17 end
18 create
19 make_default
20
21 feature {NONE} -- Initlization
22
23 make_default
24 -- Creation method
25 do
26 graph_height := 80
27 graph_width := 400
28 bottom_interval := 20
29 create internal_pixmap.make_with_size (graph_width, graph_height)
30 internal_pixmap.set_background_color (graph_pixmap_background_color)
31 create graph_used_history.make (100)
32 create graph_overhead_history.make (100)
33 end
34
35 feature -- Command
36
37 draw_graph (a_used_percent, a_overhead_percent: DOUBLE)
38 -- Do draw_history graph and draw_history_grid.
39 do
40 save_history (a_used_percent, a_overhead_percent)
41 update_graph
42 end
43
44 update_graph
45 -- Update the graph, because size may changed.
46 do
47 internal_pixmap.clear
48 internal_pixmap.set_size (main_window.gc_graphs.width, main_window.gc_graphs.height)
49 draw_history_grid
50 -- draw used line
51 draw_history_graph_line (graph_used_history, graph_used_color, line_used_width)
52 -- draw overhead line
53 draw_history_graph_line (graph_overhead_history, graph_overhead_color, line_overhead_width)
54
55 control_graph_size
56 end
57
58
59 feature {NONE} -- Control
60
61 control_graph_size
62 -- Control the graph history size, so the graph will not so big.
63 require
64 two_history_same_size: graph_used_history.count = graph_overhead_history.count
65 do
66 if graph_used_history.count >= history_size then
67 graph_used_history.start
68 graph_used_history.remove
69 graph_overhead_history.start
70 graph_overhead_history.remove
71 reduced_x := reduced_x + 1
72 end
73 ensure
74 graph_used_history_size_reduced_one: graph_used_history.count >= history_size implies graph_used_history.count = (old graph_used_history.count) - 1
75 graph_overhead_history_size_reduced_one: graph_used_history.count >= history_size implies graph_overhead_history.count = (old graph_overhead_history.count) - 1
76 end
77
78
79 feature {NONE} -- Implemention
80
81 history_size: INTEGER
82 -- Ths size of ARRAYED_LIST which contain the history of the graph.
83 do
84 Result := 1000
85 end
86
87 history_show_size: INTEGER
88 -- Size of ARRAYED_LIST which will be used for show current's width.
89 do
90 Result := graph_width // step
91 end
92
93
94 draw_history_graph_line (a_history: like graph_used_history; a_color: EV_COLOR; a_width: INTEGER)
95 -- Only draw the graph of used/overhead history.
96 require
97 a_history_not_void: a_history /= Void
98 a_color_not_void: a_color /= Void
99 local
100 current_x: INTEGER
101 current_percent: DOUBLE
102 l_draw_array: ARRAYED_LIST [EV_COORDINATE]
103 l_offset: INTEGER
104 do
105 from
106 create l_draw_array.make (2)
107 a_history.start
108 if a_history.count > history_show_size then
109 a_history.move (a_history.count - history_show_size)
110 l_offset := (a_history.count - history_show_size) * step
111 end
112 until
113 a_history.after
114 loop
115 current_x := a_history.item.pos
116 current_percent := a_history.item.percent
117 if a_history.index >= 2 then
118 internal_pixmap.set_foreground_color (a_color)
119 internal_pixmap.set_line_width (a_width)
120 if last_used_percent /= current_percent or a_history.index /= a_history.count then
121 l_draw_array.extend (create {EV_COORDINATE}.make_with_position (graph_width - (current_x - reduced_x * step) + l_offset, inner_graph_draw_height_y (current_percent)))
122 last_used_percent := a_history.item.percent
123 last_used_x := a_history.item.pos
124 end
125 else
126 last_used_percent := a_history.item.percent
127 last_used_x := a_history.item.pos
128 l_draw_array.extend (create {EV_COORDINATE}.make_with_position (graph_width - (last_used_x - reduced_x * step), inner_graph_draw_height_y (last_used_percent)))
129 end
130 a_history.forth
131 end
132 if l_draw_array.count >= 2 then
133 internal_pixmap.draw_polyline (l_draw_array.to_array, False)
134 end
135 end
136
137 draw_history_grid
138 -- Draw the grid on the history graph.
139 local
140 i : INTEGER
141 do
142 from
143 internal_pixmap.set_line_width (line_grid_width)
144 i := 0
145 until
146 i >= internal_pixmap.width
147 loop
148 internal_pixmap.set_foreground_color (graph_inner_background_color)
149 -- draw vertical lines
150 internal_pixmap.draw_straight_line ( i, 0, i, internal_pixmap.height)
151 i := i + grid_size
152 end
153
154 from
155 i := 0
156 until
157 i >= internal_pixmap.height
158 loop
159 -- draw horizontal lines
160 internal_pixmap.draw_straight_line ( 0, i, internal_pixmap.width, i)
161 i := i + grid_size
162 end
163 end
164
165 save_history (used_percent, overhead_percent:DOUBLE)
166 -- Save the used, overhead graph internal_pixmap data.
167 require
168 used_percent_valid: used_percent >= 0 and used_percent <= 1
169 overhead_percent_valid: overhead_percent >= 0 and overhead_percent <= 1
170 do
171 current_position_x := current_position_x + step
172 graph_used_history.extend ([current_position_x, used_percent])
173 graph_overhead_history.extend ([current_position_x, overhead_percent])
174 ensure
175 graph_used_history_saved: graph_used_history.count = old graph_used_history.count + 1
176 graph_overhead_history_saved: graph_overhead_history.count = old graph_overhead_history.count + 1
177 end
178
179 feature {NONE} -- Fields
180
181 step: INTEGER = 6
182 -- The x step between update graph.
183
184 line_used_width: INTEGER = 3
185 -- Used line width.
186
187 line_overhead_width: INTEGER = 2
188 -- Overhead line width.
189
190 line_grid_width: INTEGER = 1
191 -- Grid line width.
192
193 reduced_x: INTEGER
194 -- Reduced x which is because control graph_size.
195
196 last_used_x, last_overhead_x: INTEGER
197 -- Store last x position.
198
199 last_used_percent, last_overhead_percent: DOUBLE
200 -- Store last percent.
201
202 current_position_x : INTEGER
203 -- Current internal_pixmap x position on the internal_pixmap diagram.
204
205 graph_used_history: ARRAYED_LIST [TUPLE [pos: INTEGER; percent: DOUBLE]]
206 -- The list store used graph history.
207
208 graph_overhead_history : ARRAYED_LIST [TUPLE [pos: INTEGER; percent: DOUBLE]]
209 -- The list of graph overhead history.
210
211 invariant
212
213 graph_height_set: graph_height /= 0
214 graph_width_set: graph_width /= 0
215 bottom_interval_set: bottom_interval /= 0
216 graph_used_history_not_void: graph_used_history /= Void
217 graph_overhead_history_not_void: graph_overhead_history /= Void
218
219 note
220 copyright: "Copyright (c) 1984-2006, Eiffel Software and others"
221 license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
222 source: "[
223 Eiffel Software
224 356 Storke Road, Goleta, CA 93117 USA
225 Telephone 805-685-1006, Fax 805-685-6869
226 Website http://www.eiffel.com
227 Customer support http://support.eiffel.com
228 ]"
229
230
231
232
233 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23