Files
TransPyC/lib/constants/config.py
T
TermiNexus 84d91d53e5 perf(hotspot): 计时串行化并改为自身耗时(exclusive)统计
--hotspot-sites 的每函数计时原为裸 rdtsc 的 inclusive 耗时,导致 _parse_* 一条调用链各项数值几乎相同、无法定位自身成本,且短函数测量不可信。

新增 _EmitReadTimestamp:x86_64 用 lfence 加 readcyclecounter 串行化读(业界通行的 lfence;rdtsc),非 x86_64 编译期降级为裸 readcyclecounter;入口与每个 ret 前共用。选 intrinsic 组合而非内联汇编,避免约束串转义与渲染风险。

用深度栈实现自身耗时:全局 __fhs_tdepth 与 [512 x i64] __fhs_tstart/__fhs_tchild,self = inc 减去本帧内被插桩子调用 inc 之和;递归靠每调用独立 slot 与深度索引天然正确;深度溢出或终结指令非 ret 的块明确跳过不记账(仅计进入次数),不伪造数值。入口段用 select 而非条件分支,避免改动 CFG。

hotspot_time.txt 行为 函数名 self inc 进入次数(仍按 self 降序),段头注明单位 tick 与 self 口径;hotspot_sites.txt 格式保持不变;帮助文本同步更新。未插桩的被调方(含 libc)耗时计入调用者 self,属该方法固有性质并已注明。
2026-09-14 13:42:14 +08:00

60 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 常量定义
from __future__ import annotations
DEFAULT_INPUT_FILE: str = 'test.vp'
DEFAULT_OUTPUT_FILE: str = 'test.ll'
SLICE_THRESHOLD: int = 50
SLICE_LEVEL_DEFAULT: int = 3
SLICE_LEVELS: dict[int | str, str] = {
0: 'no_optimize',
1: 'conservative',
2: 'moderate',
3: 'aggressive',
's': 'size',
}
DEFAULT_COMPILE_COMMAND: str = 'gcc'
DEFAULT_COMPILE_FLAGS: str = ''
DEFAULT_METADATA: dict[str, str] = {
'PROJECT_NAME': 'TransPyC Project',
'AUTHOR': 'TransPyC Team',
'VERSION': '1.0.0',
'DESCRIPTION': 'Auto-generated LLVM IR file',
'COPYRIGHT_YEAR': '2026',
'COPYRIGHT_HOLDER': 'Galactic Vorpal Software Development Studio (e.g. GVSDS Inc.)'
}
# 调用点热点统计(--hotspot-sites)默认白名单:内存/字符串族被调函数基名
# (基名 = 去掉 16 位 sha1 模块前缀后的名字,如 "23499a69276862b2.strcmp" -> "strcmp")
DEFAULT_HOTSPOT_CALLEES: tuple[str, ...] = (
'strcmp', 'strncmp', 'strchr', 'strlen', 'strstr',
'memcpy', 'memset', 'memmove', 'strcpy', 'strcat',
)
ERROR_MESSAGES: dict[str, str] = {
'MISSING_ARGS': 'Missing required arguments -f and/or -o',
'UNKNOWN_ARG': 'Unknown argument',
'UNSUPPORTED_TYPE': 'Unsupported file type',
'FAILED_PARSE': 'Failed to parse file',
'COMPILE_FAILED': 'Compilation or execution failed'
}
HELP_MESSAGE: str = '''
Usage: python TransPyC.py -f InputFile -o OutputFile [-wh header_files] [-debug DebugFile]
[-cc compile_command] [-cflags CompileFlags] [-run] [-args RunArgs] [-h HelperFiles]
[--hotspot-sites [SitesFile]] [--hotspot-callees a,b,c] [--hotspot-sites-all]
-h: Specify helper files (C or Python) to help identify structs, functions, variables, and ptrs
--hotspot-sites: 统计各调用点真实运行次数(Ctrl+C 退出时写入 SitesFile,默认 hotspot_sites.txt,
按计数降序),并为每个函数定义加计时器:自身耗时 self、包含式耗时 inc 与进入次数,
按 self 降序写入同目录 hotspot_time.txt(行为 `<函数名> <self> <inc> <进入次数>`);
单位 tick(x86_64 上为序列化的 lfence; rdtsc 计数)。self 已扣除本函数内被插桩
子调用的 inc,但**不含未插桩的被调方**(间接调用、strcmp/memcpy 等无定义的外部
函数、深度溢出跳过的调用),这些仍计入调用者的 self
--hotspot-callees: --hotspot-sites 的白名单被调函数基名(逗号分隔,默认内存/字符串族)
--hotspot-sites-all: --hotspot-sites 对全部直接 call 点插桩(忽略白名单,体积/开销大)
'''
mode: str = "strict"