tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

logalloc_stats.py (1424B)


      1 #!/usr/bin/python3
      2 # This Source Code Form is subject to the terms of the Mozilla Public
      3 # License, v. 2.0. If a copy of the MPL was not distributed with this
      4 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
      5 
      6 
      7 import sys
      8 
      9 from logalloc_munge import split_log_line
     10 
     11 
     12 def get_size(line):
     13    try:
     14        pid, tid, func, args, result = split_log_line(line)
     15        if func == "malloc":
     16            return int(args[0])
     17        elif func == "calloc":
     18            return int(args[0]) * int(args[1])
     19        elif func == "memalign":
     20            return int(args[1])
     21        elif func == "realloc":
     22            return int(args[1])
     23        else:
     24            return None
     25    except Exception:
     26        return None
     27 
     28 
     29 def main():
     30    small = 0
     31    large = 0
     32    huge = 0
     33 
     34    for line in sys.stdin:
     35        size = get_size(line.strip())
     36        if not size:
     37            continue
     38 
     39        # Assumes a 4KiB page size, which is not true on Apple Silicon and
     40        # some other platforms.
     41        if size < 4096:
     42            small += 1
     43        elif size < 1024 * 1024:
     44            large += 1
     45        else:
     46            huge += 1
     47 
     48    total = small + large + huge
     49 
     50    def print_percent(name, value):
     51        pct = 100 * value / total
     52        print(f"{name:<5}: {value:>12,} {pct:6.2f}%")
     53 
     54    print_percent("Small", small)
     55    print_percent("Large", large)
     56    print_percent("Huge", huge)
     57 
     58 
     59 if __name__ == "__main__":
     60    main()