<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sugarlabs.org/index.php?action=history&amp;feed=atom&amp;title=Development_Team%2FMemory%2FUsage_Analysis</id>
	<title>Development Team/Memory/Usage Analysis - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sugarlabs.org/index.php?action=history&amp;feed=atom&amp;title=Development_Team%2FMemory%2FUsage_Analysis"/>
	<link rel="alternate" type="text/html" href="https://wiki.sugarlabs.org/index.php?title=Development_Team/Memory/Usage_Analysis&amp;action=history"/>
	<updated>2026-05-13T06:22:43Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://wiki.sugarlabs.org/index.php?title=Development_Team/Memory/Usage_Analysis&amp;diff=46738&amp;oldid=prev</id>
		<title>Patrol: moved Walter is a wanker 12/Memory/Usage Analysis to Development Team/Memory/Usage Analysis over redirect: revert</title>
		<link rel="alternate" type="text/html" href="https://wiki.sugarlabs.org/index.php?title=Development_Team/Memory/Usage_Analysis&amp;diff=46738&amp;oldid=prev"/>
		<updated>2010-02-24T01:33:13Z</updated>

		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/index.php?title=Walter_is_a_wanker_12/Memory/Usage_Analysis&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Walter is a wanker 12/Memory/Usage Analysis (page does not exist)&quot;&gt;Walter is a wanker 12/Memory/Usage Analysis&lt;/a&gt; to &lt;a href=&quot;/go/Development_Team/Memory/Usage_Analysis&quot; title=&quot;Development Team/Memory/Usage Analysis&quot;&gt;Development Team/Memory/Usage Analysis&lt;/a&gt; over redirect: revert&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 21:33, 23 February 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Patrol</name></author>
	</entry>
	<entry>
		<id>https://wiki.sugarlabs.org/index.php?title=Development_Team/Memory/Usage_Analysis&amp;diff=46607&amp;oldid=prev</id>
		<title>Page move vandal: moved Development Team/Memory/Usage Analysis to Walter is a wanker 12/Memory/Usage Analysis:&amp;#32;Walter is a wanker</title>
		<link rel="alternate" type="text/html" href="https://wiki.sugarlabs.org/index.php?title=Development_Team/Memory/Usage_Analysis&amp;diff=46607&amp;oldid=prev"/>
		<updated>2010-02-24T00:21:33Z</updated>

		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/go/Development_Team/Memory/Usage_Analysis&quot; title=&quot;Development Team/Memory/Usage Analysis&quot;&gt;Development Team/Memory/Usage Analysis&lt;/a&gt; to &lt;a href=&quot;/index.php?title=Walter_is_a_wanker_12/Memory/Usage_Analysis&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Walter is a wanker 12/Memory/Usage Analysis (page does not exist)&quot;&gt;Walter is a wanker 12/Memory/Usage Analysis&lt;/a&gt;: Walter is a wanker&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 20:21, 23 February 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Page move vandal</name></author>
	</entry>
	<entry>
		<id>https://wiki.sugarlabs.org/index.php?title=Development_Team/Memory/Usage_Analysis&amp;diff=45598&amp;oldid=prev</id>
		<title>Patrol: moved Anal bleaching 15/Memory/Usage Analysis to Development Team/Memory/Usage Analysis over redirect: revert</title>
		<link rel="alternate" type="text/html" href="https://wiki.sugarlabs.org/index.php?title=Development_Team/Memory/Usage_Analysis&amp;diff=45598&amp;oldid=prev"/>
		<updated>2010-02-21T22:42:05Z</updated>

		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/index.php?title=Anal_bleaching_15/Memory/Usage_Analysis&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Anal bleaching 15/Memory/Usage Analysis (page does not exist)&quot;&gt;Anal bleaching 15/Memory/Usage Analysis&lt;/a&gt; to &lt;a href=&quot;/go/Development_Team/Memory/Usage_Analysis&quot; title=&quot;Development Team/Memory/Usage Analysis&quot;&gt;Development Team/Memory/Usage Analysis&lt;/a&gt; over redirect: revert&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 18:42, 21 February 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Patrol</name></author>
	</entry>
	<entry>
		<id>https://wiki.sugarlabs.org/index.php?title=Development_Team/Memory/Usage_Analysis&amp;diff=45148&amp;oldid=prev</id>
		<title>Anal bleaching: moved Development Team/Memory/Usage Analysis to Anal bleaching 15/Memory/Usage Analysis:&amp;#32;Anal bleaching</title>
		<link rel="alternate" type="text/html" href="https://wiki.sugarlabs.org/index.php?title=Development_Team/Memory/Usage_Analysis&amp;diff=45148&amp;oldid=prev"/>
		<updated>2010-02-21T22:22:37Z</updated>

		<summary type="html">&lt;p&gt;moved &lt;a href=&quot;/go/Development_Team/Memory/Usage_Analysis&quot; title=&quot;Development Team/Memory/Usage Analysis&quot;&gt;Development Team/Memory/Usage Analysis&lt;/a&gt; to &lt;a href=&quot;/index.php?title=Anal_bleaching_15/Memory/Usage_Analysis&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Anal bleaching 15/Memory/Usage Analysis (page does not exist)&quot;&gt;Anal bleaching 15/Memory/Usage Analysis&lt;/a&gt;: Anal bleaching&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 18:22, 21 February 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Anal bleaching</name></author>
	</entry>
	<entry>
		<id>https://wiki.sugarlabs.org/index.php?title=Development_Team/Memory/Usage_Analysis&amp;diff=39051&amp;oldid=prev</id>
		<title>RafaelOrtiz: Created page with &#039;Guppy-pe can give us detailed statistics about which python objects are taking space in the heap, the relationships between them and some more useful data. Particularly useful is…&#039;</title>
		<link rel="alternate" type="text/html" href="https://wiki.sugarlabs.org/index.php?title=Development_Team/Memory/Usage_Analysis&amp;diff=39051&amp;oldid=prev"/>
		<updated>2009-10-10T04:45:19Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;Guppy-pe can give us detailed statistics about which python objects are taking space in the heap, the relationships between them and some more useful data. Particularly useful is…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Guppy-pe can give us detailed statistics about which python objects are taking space in the heap, the relationships between them and some more useful data. Particularly useful is the ability to take a snapshot of the current state and later print the diff between both points.&lt;br /&gt;
&lt;br /&gt;
 See http://guppy-pe.sourceforge.net/heapy_Use.html#heapykinds.Use.monitor.&lt;br /&gt;
&lt;br /&gt;
The following patch to sugar-shell will periodically print some interesting information about memory usage. It may not apply cleanly, but anybody interested in using it will need anyway to read and understand this code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
diff --git a/bin/sugar-shell b/bin/sugar-shell&lt;br /&gt;
index b0f66b4..29f130a 100755&lt;br /&gt;
--- a/bin/sugar-shell&lt;br /&gt;
+++ b/bin/sugar-shell&lt;br /&gt;
@@ -85,7 +85,117 @@ def _shell_started_cb():&lt;br /&gt;
     hw_manager = hardwaremanager.get_manager()&lt;br /&gt;
     hw_manager.set_dcon_freeze(0)&lt;br /&gt;
 &lt;br /&gt;
+global mem_used, objects, garbage&lt;br /&gt;
+mem_used = 0&lt;br /&gt;
+objects = 0&lt;br /&gt;
+garbage = 0&lt;br /&gt;
+&lt;br /&gt;
+def _log_mem_usage(): &lt;br /&gt;
+    import analysis, os, gc, logging&lt;br /&gt;
+    for i in xrange(3):&lt;br /&gt;
+        total = len(gc.get_objects())&lt;br /&gt;
+        unreachable = gc.collect()&lt;br /&gt;
+        logging.debug(&amp;#039;After collection - total before: %r total after: %r unreachable: %r&amp;#039; % (total, len(gc.get_objects()), unreachable))&lt;br /&gt;
+&lt;br /&gt;
+    global mem_used, objects, garbage&lt;br /&gt;
+&lt;br /&gt;
+    current_mem = analysis.Analysis(os.getpid()).ApproxRealMemoryUsage()&lt;br /&gt;
+    current_objects = len(gc.get_objects())&lt;br /&gt;
+    current_garbage = len(gc.garbage)&lt;br /&gt;
+    logging.debug(&amp;#039;mem: %i increment: %i&amp;#039; % (current_mem, current_mem - mem_used))&lt;br /&gt;
+    logging.debug(&amp;#039;total objects: %i increment: %i&amp;#039; % (current_objects, current_objects - objects))&lt;br /&gt;
+    logging.debug(&amp;#039;garbage: %i increment: %i\n&amp;#039; % (current_garbage, current_garbage - garbage))&lt;br /&gt;
+&lt;br /&gt;
+    mem_used = current_mem&lt;br /&gt;
+    objects = current_objects&lt;br /&gt;
+    garbage = current_garbage&lt;br /&gt;
+&lt;br /&gt;
+    return True&lt;br /&gt;
+&lt;br /&gt;
+global prev_heap&lt;br /&gt;
+prev_heap = None&lt;br /&gt;
+&lt;br /&gt;
+def _log_objects(): &lt;br /&gt;
+    import gc&lt;br /&gt;
+    gc.collect()&lt;br /&gt;
+&lt;br /&gt;
+    global prev_heap    &lt;br /&gt;
+    import guppy, logging&lt;br /&gt;
+    import view.BuddyIcon&lt;br /&gt;
+    h = guppy.hpy()&lt;br /&gt;
+&lt;br /&gt;
+    heap = h.heap()&lt;br /&gt;
+&lt;br /&gt;
+    if prev_heap is not None:&lt;br /&gt;
+        diff = heap.diff(prev_heap)&lt;br /&gt;
+        for i in xrange(6):&lt;br /&gt;
+            logging.debug(diff)&lt;br /&gt;
+            diff = diff.more&lt;br /&gt;
+&lt;br /&gt;
+    prev_heap = heap&lt;br /&gt;
+    &lt;br /&gt;
+    return True&lt;br /&gt;
+&lt;br /&gt;
+global obj_occurrences&lt;br /&gt;
+obj_occurrences = {}&lt;br /&gt;
+&lt;br /&gt;
+def _get_obj_dict():&lt;br /&gt;
+    import gc&lt;br /&gt;
+    &lt;br /&gt;
+    obj_dict = {}&lt;br /&gt;
+    for o in gc.get_objects():&lt;br /&gt;
+        t = str(type(o))&lt;br /&gt;
+        if t in obj_dict:&lt;br /&gt;
+            obj_dict[t] += 1&lt;br /&gt;
+        else:&lt;br /&gt;
+            obj_dict[t] = 1&lt;br /&gt;
+    &lt;br /&gt;
+    return obj_dict&lt;br /&gt;
+    &lt;br /&gt;
+def _calc_diff(dict_a, dict_b):&lt;br /&gt;
+    types_a = set(dict_a.keys())&lt;br /&gt;
+    types_b = set(dict_b.keys())&lt;br /&gt;
+    types = types_a | types_b&lt;br /&gt;
+    result = {}&lt;br /&gt;
+    &lt;br /&gt;
+    for t in types:&lt;br /&gt;
+        if t in dict_a and t in dict_b:&lt;br /&gt;
+            result[t] = dict_a[t] - dict_b[t]&lt;br /&gt;
+        elif t in dict_a:&lt;br /&gt;
+            result[t] = dict_a[t]&lt;br /&gt;
+        else:&lt;br /&gt;
+            result[t] = - dict_b[t]&lt;br /&gt;
+        if result[t] == 0:&lt;br /&gt;
+            del result[t]&lt;br /&gt;
+    return result&lt;br /&gt;
+    &lt;br /&gt;
+def _log_diff():&lt;br /&gt;
+    import logging&lt;br /&gt;
+    logging.debug(&amp;#039;Heap diff:&amp;#039;)&lt;br /&gt;
+        &lt;br /&gt;
+    current_objs = _get_obj_dict()&lt;br /&gt;
+    &lt;br /&gt;
+    global obj_occurrences&lt;br /&gt;
+    if obj_occurrences:&lt;br /&gt;
+        diff = _calc_diff(current_objs, obj_occurrences)&lt;br /&gt;
+        for t, freq in diff.iteritems():&lt;br /&gt;
+            logging.debug(&amp;#039;%s\t%d&amp;#039; % (t, freq))&lt;br /&gt;
+            &lt;br /&gt;
+    obj_occurrences = current_objs&lt;br /&gt;
+    &lt;br /&gt;
+    logging.debug(&amp;#039;-----------------------------------&amp;#039;)&lt;br /&gt;
+    &lt;br /&gt;
+    return True&lt;br /&gt;
+&lt;br /&gt;
 def main():&lt;br /&gt;
+    import gc&lt;br /&gt;
+    gc.set_debug(gc.DEBUG_LEAK)&lt;br /&gt;
+    &lt;br /&gt;
+    #_log_objects()&lt;br /&gt;
+    #gobject.timeout_add(30000, _log_objects)&lt;br /&gt;
+    gobject.timeout_add(5000, _log_mem_usage)&lt;br /&gt;
+    #gobject.timeout_add(5000, _log_diff)&lt;br /&gt;
+    &lt;br /&gt;
     gobject.idle_add(_shell_started_cb)&lt;br /&gt;
 &lt;br /&gt;
     logsmanager.setup()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>RafaelOrtiz</name></author>
	</entry>
</feed>