Skip to content

Commit

Permalink
Added new script to capture number of symbols typically
Browse files Browse the repository at this point in the history
  • Loading branch information
fzakaria committed Oct 4, 2023
1 parent 92440ba commit 284515f
Show file tree
Hide file tree
Showing 3 changed files with 647 additions and 1 deletion.
20 changes: 19 additions & 1 deletion benchmarks/bin_symbol_size.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
#! /usr/bin/env python
"""Go through /bin and print out the number of symbols in each binary."""

import itertools
import json
import os
import subprocess
from collections import defaultdict

data = defaultdict(lambda: 0)

for root, dirs, files in os.walk("/bin"):

def is_elf_file(filepath):
try:
with open(filepath, "rb") as file:
# Read the first four bytes of the file
magic_number = file.read(4)
except FileNotFoundError:
return False
except IOError:
return False

# Check if the magic number matches the ELF signature
return magic_number == b"\x7fELF"


for root, dirs, files in itertools.chain(os.walk("/bin"), os.walk("/usr/bin")):
for file in files:
full_path_file = os.path.join(root, file)
if not os.path.isfile(full_path_file) or not os.access(full_path_file, os.X_OK):
pass
if not is_elf_file(full_path_file):
continue # skip non-ELF files
result = subprocess.run(
f"readelf -s {full_path_file} | wc -l",
capture_output=True,
Expand Down
34 changes: 34 additions & 0 deletions benchmarks/graph_bin_symbol_size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#! /usr/bin/env python3

import json
import os

import pandas as pd
from plotnine import (
aes,
after_stat,
geom_histogram,
ggplot,
labs,
save_as_pdf_pages,
theme_minimal,
)

SCRIPT_DIR = os.path.dirname(__file__)
JSON_FILE = open(os.path.join(SCRIPT_DIR, "symbols-ubuntu.json"), "r")

# Load JSON data into a Python dictionary
data_dict = json.load(JSON_FILE)

# Convert to DataFrame
df = pd.DataFrame(list(data_dict.items()), columns=["File", "Symbols"])

# Create plot
plot = (
ggplot(df, aes(x="Symbols", y=after_stat("ncount")))
+ geom_histogram(bins=100, fill="skyblue", color="black", alpha=0.7)
+ labs(title="", x="Number of Symbols", y="Normalized Count")
+ theme_minimal()
)

save_as_pdf_pages([plot])
Loading

0 comments on commit 284515f

Please sign in to comment.