Skip to content

Instantly share code, notes, and snippets.

@wenjianhn
Created October 25, 2021 08:33
Show Gist options
  • Save wenjianhn/1418e8e8eb064345ebc9756f897aed78 to your computer and use it in GitHub Desktop.
Save wenjianhn/1418e8e8eb064345ebc9756f897aed78 to your computer and use it in GitHub Desktop.
Analyzing allocation and freeing events(includes kmem:mm_page_alloc, kmem:mm_page_alloc_zone_locked, kmem:mm_page_free, kmem:mm_page_free_batched and kmem:mm_page_pcpu_drain)
#!/usr/bin/env python
from __future__ import print_function
import sys
from collections import Counter
def get_order(head):
h = head.split()
for i in h:
if i.startswith("order="):
return int(i.split('=')[1])
def main():
if len(sys.argv) < 2:
print("Usage:\n %s <perf_script_output_file>" % sys.argv[0], file=sys.stderr)
sys.exit(-1)
counter = Counter()
order = -1
trace = ''
with open(sys.argv[1]) as f:
for line in f:
if order == -1:
order = get_order(line)
elif line == '\n':
counter[trace] += 4096L << order
print(trace, counter[trace])
order = -1
trace = ''
else:
trace += line
for t, b in counter.most_common():
print("Freed/Allocated %d MiB by\n%s" % (b/1024/1024, t))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment