gouring/inline_cost.py
Nugraha 7eedf9754b
all: use of unsafe pointer for ring, and adjustments
There's other adjustment/addition:
 * Function name CQE/SQE renamed to Cqe/Sqe.
 * SQ entry union sets value withput util to reduce function
   complexity, so leaving function budget for another stuff.
 * UserData has its own type, implement for uint64, uintptr,
   and unsafe.
 * TODO: decide what to use `Syscall` or `RawSyscall`.
 * Exposed `SeenCqe`.
 * Ignore *.test file extension.
 * Inline cost tool.

Signed-off-by: Nugraha <richiisei@gmail.com>
2022-07-28 19:45:51 +07:00

63 lines
No EOL
1.7 KiB
Python

#!/bin/python3
import re
import subprocess
from io import BytesIO
from typing import Tuple, List
from sys import (
stdout as sys_stdout,
stderr as sys_stderr
)
# https://dave.cheney.net/2020/05/02/mid-stack-inlining-in-go
gcflags = [
"-m=2",
]
re_cost = re.compile(rb"with cost (\d+) as:")
re_cost2 = re.compile(rb"cost (\d+) exceeds")
def main():
h = subprocess.Popen(
args=["go","build","-gcflags="+" ".join(gcflags),"."],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
ret: Tuple[str, str] = h.communicate()
stdout, stderr = ret
lines: List[bytes] = stderr.split(b"\n")
inlined_lines: List[bytes] = [line for line in lines if b"inline" in line]
can_inline: List[Tuple[bytes, int]] = []
cannot_inline: List[Tuple[bytes, int]] = []
for line in inlined_lines:
if b"can inline" in line:
inline_cost = int(re_cost.findall(line)[0])
can_inline += [ (line, inline_cost) ]
elif b"cannot inline" in line:
cur_cost = 0
try:
cur_cost = int(re_cost2.findall(line)[0])
except: pass
cannot_inline += [ (line, cur_cost) ]
else:
sys_stderr.write(b"[UNK] ")
sys_stderr.write(line)
sys_stderr.write(b"\n")
# sort by cost
# can_inline = sorted(can_inline, key=lambda v: v[1])
# cannot_inline = sorted(cannot_inline, key=lambda v: v[1])
for item in can_inline:
print( (str(item[1]).encode() +b"\t"+ item[0]) .decode() )
print("============")
for item in cannot_inline:
print( (str(item[1]).encode() +b"\t"+ item[0]) .decode() )
if __name__ == "__main__":
main()