Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(778)

Unified Diff: physmem_alloc_analysis/physmem_alloc_analyzer.py

Issue 1217243006: Analyze contiguous physical memory chunks that mmap system call gives (Closed) Base URL: https://github.com/acutebridge/rowhammer-test.git@phymem_alloc
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: physmem_alloc_analysis/physmem_alloc_analyzer.py
diff --git a/physmem_alloc_analysis/physmem_alloc_analyzer.py b/physmem_alloc_analysis/physmem_alloc_analyzer.py
new file mode 100644
index 0000000000000000000000000000000000000000..a60558130c4c46ec29a085ddce0f499c7fe1b9ab
--- /dev/null
+++ b/physmem_alloc_analysis/physmem_alloc_analyzer.py
@@ -0,0 +1,60 @@
+# Copyright 2015, Google, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import operator
+
+
+def ExtractBits(val, offset_in_bits, size_in_bits):
Mark Seaborn 2015/07/01 19:21:23 Not used; can be removed.
ruiq 2015/07/01 20:42:59 Done.
+ return [(val >> offset_in_bits) & ((1 << size_in_bits) - 1),
+ size_in_bits]
+
+
+def GetResultPfns(log_filename):
+ for line in open(log_filename):
+ parts = line.strip('\n')[:-1].split(' ');
+ yield [int(part, 16) for part in parts]
+
+
+def Main():
+ counter = 0
Mark Seaborn 2015/07/01 19:21:23 Not used
ruiq 2015/07/01 20:42:59 Done.
+ cont_count = {}
+ for pfns in GetResultPfns('physmem_alloc_results'):
+ i1 = 0
+ i2 = 0
+ while i2 < len(pfns):
+ while i2 + 1 < len(pfns) and pfns[i2+1] - pfns[i2] == 1:
+ i2 += 1
+ size = i2 - i1 + 1
+ cont_count.setdefault(size, 0)
+ cont_count[size] += 1
+ i2 += 1
+ i1 = i2
+
+ total_pages = 0
+ for size, count in cont_count.iteritems():
+ total_pages += size * count
+ cont_fraction = {}
Mark Seaborn 2015/07/01 19:21:22 I don't think you need to build another dict for t
ruiq 2015/07/01 20:42:59 Done.
+ for size, count in cont_count.iteritems():
+ cont_fraction[size] = 1.0 * size * count / total_pages
+
+ sorted_by_size = sorted(cont_fraction.items(), key=operator.itemgetter(0))
Mark Seaborn 2015/07/01 19:21:22 Note that this is equivalent to: sorted_by_size =
ruiq 2015/07/01 20:42:59 Done.
+ for size, fraction in sorted_by_size:
+ count = cont_count[size]
+ size_total = size * count
+ print "%10d %10d %10d %10.2f" % (size, count, size_total, fraction)
Mark Seaborn 2015/07/01 19:21:22 Nit: be consistent about whether you use ' or " fo
ruiq 2015/07/01 20:42:59 Done.
+
+
+if __name__ == '__main__':
+ Main()

Powered by Google App Engine
This is Rietveld 408576698