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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 92684 - (show annotations)
Fri Jun 7 15:28:53 2013 UTC (6 years, 7 months ago) by jasonw
File size: 13575 byte(s)
<<Merged from trunk#92682.>>
1 note
2 description: "Save memory states at differents point and analyze the difference."
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_MEMORY_CHANGE_MEDIATOR
10
11 inherit
12 ANY
13
14 MA_SINGLETON_FACTORY
15 export
16 {NONE} all
17 end
18 create
19 make
20
21 feature {NONE} -- Initialization
22
23 make (a_memory_spot_1, a_memory_spot_2, a_increased_object_result: EV_GRID)
24 -- Initialize `Current'.
25 require
26 not_void: attached a_memory_spot_1
27 not_void: attached a_memory_spot_2
28 not_void: attached a_increased_object_result
29 do
30 create states.make (10)
31 grid_from_state := a_memory_spot_1
32 grid_to_state := a_memory_spot_2
33 grid_from_state.enable_single_row_selection
34 grid_to_state.enable_single_row_selection
35 grid_changed := a_increased_object_result
36
37 create grid_data.make (10)
38 init_grid
39 grid_changed.set_item_pebble_function (agent handle_pick_item)
40 grid_changed.set_accept_cursor (accept_node_class)
41 grid_changed.set_deny_cursor (deny_node_class)
42 end
43
44 feature -- Command
45
46 states_open_from_file
47 -- Open states from disk.
48 local
49 l_item: MA_MEMORY_STATE
50 l_list: ARRAYED_LIST [MA_MEMORY_STATE]
51 do
52 states.open_states
53 l_list := states.states
54 from
55 l_list.start
56 grid_data.wipe_out
57 until
58 l_list.after
59 loop
60 l_item := l_list.item
61 grid_data.extend ([grid_state_prefix + l_list.index.out, l_item.objects_total_count, l_item.memory_used_eiffel, l_item.memory_used_c])
62 l_list.forth
63 end
64 update_grid_content
65 ensure
66 grid_data_set: states.states.count = grid_data.count
67 end
68
69 states_save_to_file
70 -- Save states to a disk file.
71 do
72 states.save_states
73 end
74
75 adjust_widgets_layout
76 -- Adjust the split, 2 grids' positon and size to make it nice looking.
77 do
78 adjust_split_vertical
79 adjust_split_horizontal
80 end
81
82 adjust_split_vertical
83 -- Adjust the split area (which ia at the top area)'s position.
84 do
85 main_window.split_incre.set_split_position ((main_window.split_incre.width / 2).ceiling)
86 end
87
88 adjust_split_horizontal
89 -- Adjust the split area (which ia at the bottom area)'s position.
90 do
91 main_window.split_incre_horizontal.set_split_position (main_window.split_incre_horizontal.minimum_split_position
92 + main_window.memory_spot_1.row_count * main_window.memory_spot_1.row_height + main_window.memory_spot_1.header.height)
93 end
94
95 adjust_column_width (a_column_index: INTEGER; a_grid: EV_GRID)
96 -- Adjust a column width to fix the max width of the item its contain.
97 do
98 if a_grid.row_count > 0 then
99 a_grid.column (a_column_index).set_width (a_grid.column (a_column_index).required_width_of_item_span (1, a_grid.row_count))
100 end
101 end
102
103 add_current_state
104 -- Save current memory state, show them in grid.
105 local
106 l_state: MA_MEMORY_STATE
107 do
108 system_util.collect
109 create l_state.make_with_memory_map (memory.memory_count_map)
110 states.extend (l_state)
111 grid_data.extend ([grid_state_prefix + states.count.out, l_state.objects_total_count,
112 l_state.memory_used_eiffel, l_state.memory_used_c])
113 update_grid_content
114 ensure
115 states_add_one: states.count = old states.count + 1
116 end
117
118 show_object_count_changed
119 -- Show the object increased objects information in the result grid.
120 local
121 l_state_1, l_state_2: MA_MEMORY_STATE
122 l_info_dlg: EV_INFORMATION_DIALOG
123 do
124 if grid_from_state.has_selected_row then
125 if grid_to_state.has_selected_row then
126 l_state_2 := states.i_th (grid_to_state.selected_rows.first.index)
127 l_state_1 := states.i_th (grid_from_state.selected_rows.first.index)
128 grid_util.grid_remove_and_clear_all_rows (grid_changed)
129 grid_data_increased := l_state_1.compare (l_state_2)
130 update_grid_increased_content
131 else
132 create l_info_dlg.make_with_text ("Please select a To State from the right grid.")
133 l_info_dlg.show_relative_to_window (main_window)
134 end
135 else
136 create l_info_dlg.make_with_text ("Please select a From State from the left grid.")
137 l_info_dlg.show_relative_to_window (main_window)
138 end
139 end
140
141 update_grid_content
142 -- Fill grid_from_state, grid_to_state using grid data.
143 local
144 l_item: EV_GRID_LABEL_ITEM
145 l_i: INTEGER
146 do
147 from
148 grid_data.start
149 grid_util.grid_remove_and_clear_all_rows (grid_from_state)
150 grid_util.grid_remove_and_clear_all_rows (grid_to_state)
151 l_i := 1
152 until
153 grid_data.after
154 loop
155 -- set state name
156 create l_item.make_with_text (grid_data.item.type_name)
157 l_item.set_pixmap (icons.system_state_from_icon)
158 grid_from_state.set_item (1, l_i, l_item.deep_twin)
159 l_item.set_pixmap (icons.system_state_to_icon)
160 grid_to_state.set_item (1, l_i, l_item)
161 -- set object count
162 create l_item.make_with_text (grid_data.item.e_mem.out)
163 grid_from_state.set_item (2, l_i, l_item.deep_twin)
164 grid_to_state.set_item (2, l_i, l_item)
165
166 -- set eiffel memory used
167 create l_item.make_with_text (grid_data.item.c_mem.out)
168 grid_from_state.set_item (3, l_i, l_item.deep_twin)
169 grid_to_state.set_item (3, l_i, l_item)
170 -- set c memory used
171 create l_item.make_with_text (grid_data.item.type_id.out)
172 grid_from_state.set_item (4, l_i, l_item.deep_twin)
173 grid_to_state.set_item (4, l_i, l_item)
174
175 grid_data.forth
176 l_i := l_i + 1
177 end
178 ensure
179 grid_data_set: grid_from_state.row_count = grid_data.count and grid_to_state.row_count = grid_data.count
180 end
181
182 feature {NONE} -- Implemention
183
184 update_grid_increased_content
185 -- Show the increased objects in the bottom result grid.
186 require
187 set: attached grid_data_increased
188 local
189 l_int: INTEGER
190 l_item: EV_GRID_LABEL_ITEM
191 l_i: INTEGER
192 l_grid_data_increased: like grid_data_increased
193 do
194 from
195 l_grid_data_increased := grid_data_increased
196 check attached l_grid_data_increased end -- Implied by precondition `set'
197 l_grid_data_increased.start
198 until
199 l_grid_data_increased.after
200 loop
201 if not filter.filter_class (l_grid_data_increased.item_for_iteration.text) then
202 l_i := l_i + 1
203 create l_item.make_with_text (l_grid_data_increased.item_for_iteration.text)
204 l_item.set_pixmap (icons.object_grid_class_icon)
205 grid_changed.set_item (1, l_i, l_item)
206 l_int := l_grid_data_increased.item_for_iteration.nb
207 create l_item.make_with_text (l_int.out)
208 if l_int > 0 then
209 l_item.set_foreground_color (increased_color)
210 else
211 l_item.set_foreground_color (decreased_color)
212 end
213 grid_changed.set_item (2, l_i, l_item)
214 end
215 l_grid_data_increased.forth
216 end
217 end
218
219 init_grid
220 -- Init the grid's title.
221 do
222 grid_from_state.insert_new_column (1)
223 grid_from_state.insert_new_column (2)
224 grid_from_state.insert_new_column (3)
225 grid_from_state.insert_new_column (4)
226 grid_from_state.column (1).set_title ("From state")
227 grid_from_state.column (2).set_title ("Objects count")
228 grid_from_state.column (3).set_title ("Eiffel memory used")
229 grid_from_state.column (4).set_title ("C memory used")
230 grid_from_state.column (1).header_item.pointer_double_press_actions.force_extend (agent adjust_column_width (1, grid_from_state))
231 grid_from_state.column (2).header_item.pointer_double_press_actions.force_extend (agent adjust_column_width (2, grid_from_state))
232 grid_from_state.column (3).header_item.pointer_double_press_actions.force_extend (agent adjust_column_width (3, grid_from_state))
233 grid_from_state.column (4).header_item.pointer_double_press_actions.force_extend (agent adjust_column_width (4, grid_from_state))
234
235 grid_to_state.insert_new_column (1)
236 grid_to_state.insert_new_column (2)
237 grid_to_state.insert_new_column (3)
238 grid_to_state.insert_new_column (4)
239 grid_to_state.column (1).header_item.pointer_double_press_actions.force_extend (agent adjust_column_width (1, grid_to_state))
240 grid_to_state.column (2).header_item.pointer_double_press_actions.force_extend (agent adjust_column_width (2, grid_to_state))
241 grid_to_state.column (3).header_item.pointer_double_press_actions.force_extend (agent adjust_column_width (3, grid_to_state))
242 grid_to_state.column (4).header_item.pointer_double_press_actions.force_extend (agent adjust_column_width (4, grid_to_state))
243 grid_to_state.column (1).set_title ("To state")
244 grid_to_state.column (2).set_title ("Objects count")
245 grid_to_state.column (3).set_title ("Eiffel memory used")
246 grid_to_state.column (4).set_title ("C memory used")
247
248 grid_changed.insert_new_column (1)
249 grid_changed.insert_new_column (2)
250 grid_changed.column (1).set_title ("Object type")
251 grid_changed.column (2).set_title ("Delta")
252 grid_changed.column (1).header_item.pointer_button_press_actions.force_extend (agent on_grid_header_click (1))
253 grid_changed.column (2).header_item.pointer_button_press_actions.force_extend (agent on_grid_header_click (2))
254 grid_changed.column (1).header_item.pointer_double_press_actions.force_extend (agent adjust_column_width (1, grid_changed))
255 grid_changed.column (2).header_item.pointer_double_press_actions.force_extend (agent adjust_column_width (2, grid_changed))
256 ensure
257 grid_from_state_column_set: grid_from_state.column_count = 4
258 grid_to_state_column_set: grid_to_state.column_count = 4
259 grid_changed_column_set: grid_changed.column_count = 2
260 end
261
262 on_grid_header_click (a_column_index: INTEGER)
263 -- User click on the column header of index `a_column_index'.
264 require
265 a_column_index_positive: a_column_index > 0
266 a_column_index_not_too_big: a_column_index <= grid_changed.column_count
267 do
268 if grid_changed.header.pointed_divider_index = 0 then
269 if sorted_column = a_column_index then
270 -- We invert the sorting.
271 sorting_order := not sorting_order
272 else
273 sorted_column := a_column_index
274 sorting_order := False
275 end
276 if grid_data_increased /= Void then
277 sort_data
278 update_grid_increased_content
279 end
280 end
281 end
282
283 handle_pick_item (a_item: EV_GRID_LABEL_ITEM): MA_CLASS_STONE
284 -- User pick a item from grid to filter.
285 local
286 l_result: detachable like handle_pick_item
287 do
288 if a_item /= Void and a_item.column.index = 1 then
289 l_result := create {MA_CLASS_STONE}.make (a_item.text)
290 end
291 check attached l_result end -- FIXME: Implied by ...?
292 Result := l_result
293 end
294
295 sort_data
296 -- Sort `grid_data' according to `sorted_column' and `sorting_order'.
297 require
298 set: attached grid_data_increased
299 local
300 l_sorter: QUICK_SORTER [like grid_data_increased_row]
301 l_agent_sorter: AGENT_EQUALITY_TESTER [like grid_data_increased_row]
302 l_grid_data_increased: like grid_data_increased
303 do
304 inspect
305 sorted_column
306 when 1 then create l_agent_sorter.make (agent sort_on_type_name)
307 when 2 then create l_agent_sorter.make (agent sort_on_count)
308 end
309 create l_sorter.make (l_agent_sorter)
310 l_grid_data_increased := grid_data_increased
311 check attached l_grid_data_increased end -- Implied by precondition
312 l_sorter.sort (l_grid_data_increased)
313 end
314
315 sorting_order: BOOLEAN
316 -- If True, sorted from the smaller to the bigger.
317
318 sorted_column: INTEGER
319 -- Column on which sorting is done.
320
321 sort_on_type_name (u, v: like grid_data_increased_row): BOOLEAN
322 -- Compare u, v.
323 require
324 u_not_void: u /= Void
325 v_not_void: v /= Void
326 do
327 if sorting_order then
328 Result := u.text < v.text
329 else
330 Result := u.text > v.text
331 end
332 end
333
334 sort_on_count (u, v: like grid_data_increased_row): BOOLEAN
335 -- Compare u, v.
336 require
337 u_not_void: u /= Void
338 v_not_void: v /= Void
339 do
340 if sorting_order then
341 Result := u.nb < v.nb
342 else
343 Result := v.nb < u.nb
344 end
345 end
346
347 grid_data_increased_row: TUPLE [text: STRING; nb: INTEGER]
348 -- Anchor type should not called.
349 -- first INTEGER is increased object count, second INTEGER is the increased objects type id
350 require
351 False
352 local
353 l_result: detachable like grid_data_increased_row
354 do
355 check False end -- Anchor type only
356 check attached l_result end -- Satisfy void-safe compiler
357 Result := l_result
358 end
359
360 grid_data_increased: detachable ARRAYED_LIST [like grid_data_increased_row]
361 -- the objects increased, first INTEGER is increased object count, second INTEGER is the increased objects type id
362
363 grid_data: ARRAYED_LIST [like row_data]
364 -- Data used to fill grid.
365
366 row_data: TUPLE [type_name: STRING; e_mem: INTEGER; c_mem: INTEGER; type_id: INTEGER]
367 -- Type for the data inserted in grid
368 -- It is [Object Type Name, Eiffel Memory Used, C Memory Used, TypeId].
369 require
370 False
371 local
372 l_result: detachable like row_data
373 do
374 check False end -- Anchor type only
375 check attached l_result end -- Satisfy void-safe compiler
376 Result := l_result
377 end
378
379 grid_from_state, grid_to_state: EV_GRID -- Two grid show states.
380
381 grid_changed: EV_GRID
382 -- The grid to show objects increased.
383
384 states: MA_MEMORY_STATE_MANAGER
385
386 grid_state_prefix: STRING = "States: "
387 -- The states grid prefix of first column.
388
389 invariant
390 states_not_void: states /= Void
391 grid_1_not_void: grid_from_state /= Void
392 grid_2_not_void: grid_to_state /= Void
393 grid_increased_not_void: grid_changed /= Void
394 grid_data_not_void: grid_data /= Void
395 note
396 copyright: "Copyright (c) 1984-2013, Eiffel Software and others"
397 license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
398 source: "[
399 Eiffel Software
400 5949 Hollister Ave., Goleta, CA 93117 USA
401 Telephone 805-685-1006, Fax 805-685-6869
402 Website http://www.eiffel.com
403 Customer support http://support.eiffel.com
404 ]"
405
406
407
408
409 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23