tick_plot__compile.ipynb
clang插件对llvm源码插桩,分析函数调用日志(1)
分析
进出、链、出
df进出=df[ df['tickKind'].isin( [FuncEnter,FuncReturn] ) ]
#代码中,只有在函数进入时,计算了链条长度 并写磁盘
df入=df[ df['tickKind'].isin( [FuncEnter] ) ]
df链=df入
# 函数本地时长 应 用 出时的计数器的值
df出=df[ df['tickKind'].isin( [FuncReturn] ) ]
从funcEnterId查funcId的字典
fei2fi = df链.set_index('funcEnterId')['funcId'].to_dict()
type(fei2fi), list(fei2fi.items())[0:10]
(dict,
[(0, 725),
(1, 576),
(2, 355),
(3, 2237),
(4, 165),
(5, 355),
(6, 2237),
(7, 165),
(8, 355),
(9, 2237)])
fei2fn = df链.set_index('funcEnterId')['funcName'].to_dict()
type(fei2fn), list(fei2fn.items())[0:10]
(dict,
[(0, 'llvm::cl::getGeneralCategory'),
(1, 'llvm::cl::OptionCategory::registerCategory'),
(2, 'llvm::ManagedStaticBase::RegisterManagedStatic'),
(3, 'llvm::llvm_is_multithreaded'),
(4, 'getManagedStaticMutex'),
(5, 'llvm::ManagedStaticBase::RegisterManagedStatic'),
(6, 'llvm::llvm_is_multithreaded'),
(7, 'getManagedStaticMutex'),
(8, 'llvm::ManagedStaticBase::RegisterManagedStatic'),
(9, 'llvm::llvm_is_multithreaded')])
构造字段funcIdSeq
#利用字典fei2fi ,将输入 funcEnterIdSeqK 转为 funcIdSeqK
def funcEnterIdSeq2funcIdSeq(funcEnterIdSeqK:str):
fis=[]
fiK=None
for feiK_str in funcEnterIdSeqK.split("#"):
if feiK_str == '':
continue
feiK=int(feiK_str) # feiK 必须是数字格式,如果不是 正好报错
fiK=fei2fi[feiK] # feiK 必须在字典fei2fi中,如果不在 正好报错
fis.append(fiK)
fiKStr_ls= [ f'{fiK}' for fiK in fis]
return '#'.join(fiKStr_ls)
#利用字典fei2fn ,将输入 funcEnterIdSeqK 转为 funcNameSeqK
def funcEnterIdSeq2funcNameSeq(funcEnterIdSeqK:str):
fns=[]
fnK=None
for feiK_str in funcEnterIdSeqK.split("#"):
if feiK_str == '':
continue
feiK=int(feiK_str) # feiK 必须是数字格式,如果不是 正好报错
fnK=fei2fn[feiK] # feiK 必须在字典fei2fi中,如果不在 正好报错
fns.append(fnK)
return '#'.join(fns)
#测试函数funcEnterIdSeq2funcIdSeq
# funcEnterIdSeqK="#3#2#1#"
# funcEnterIdSeq2funcIdSeq(funcEnterIdSeqK),funcEnterIdSeq2funcNameSeq(funcEnterIdSeqK)
df进出['funcIdSeq']=df进出['funcEnterIdSeq'] .apply(lambda feisJ: funcEnterIdSeq2funcIdSeq(feisJ) )
df入['funcIdSeq']=df入['funcEnterIdSeq'] .apply(lambda feisJ: funcEnterIdSeq2funcIdSeq(feisJ) )
df链=df入
df出['funcIdSeq']=df出['funcEnterIdSeq'] .apply(lambda feisJ: funcEnterIdSeq2funcIdSeq(feisJ) )
df进出['funcNameSeq']=df进出['funcEnterIdSeq'] .apply(lambda feisJ: funcEnterIdSeq2funcNameSeq(feisJ) )
df入['funcNameSeq']=df入['funcEnterIdSeq'] .apply(lambda feisJ: funcEnterIdSeq2funcNameSeq(feisJ) )
df链=df入
df出['funcNameSeq']=df出['funcEnterIdSeq'] .apply(lambda feisJ: funcEnterIdSeq2funcNameSeq(feisJ) )
查看
df进出.shape, df链.shape, df出.shape
#((666718, 26), (333359, 26), (333359, 26))
df进出.head(5)
查看2
函数本地时长分组 = df出.groupby('funcLocalClock').size().reset_index(name='该时长的出数')
函数本地时长分组_降序 = 函数本地时长分组.sort_values(by='该时长的出数', ascending=False)
函数本地时长分组_降序.head(5)
3.4B 时长边界_时上链异数
df时=df出
时顶=df出['funcLocalClock'].max()
时底=df出['funcLocalClock'].min()
print("时顶,时底", 时顶,时底)
时长边界_时上链异数_对们=[]
for 时长边界k in range(时底,时顶):
时上函=df时[ df时['funcLocalClock'].ge(时长边界k) ] .funcId.unique()
时上链=df链[ df链['funcId'].isin( 时上函 ) ]
时上链异数=len(时上链.funcIdSeq.unique()) #funcEnterIdSeq 改为 funcIdSeq
时长边界_时上链异数_对们.append( (时长边界k,时上链异数) )
if 时上链异数 <=1:
break
if 时长边界k % 800 == 0:
print(f"时长边界k,时上链异数 :{时长边界k},{时上链异数}")
3.4 计算 本地时长短的函数id们
长短函数调用链列表
['llvm::StringMapImpl::RehashTable',
'',
'llvm::StringMapImpl::RehashTable#llvm::PassRegistry::registerPass#LLVMInitializeX86Target',
'llvm::StringMapImpl::RehashTable#llvm::PassRegistry::registerPass#llvm::initializeGlobalISel#LLVMInitializeX86Target',
'llvm::StringMapImpl::RehashTable#llvm::PassRegistry::registerPass#llvm::initializeLazyBPIPassPass#llvm::initializeGlobalISel#LLVMInitializeX86Target',
'llvm::opt::OptTable::OptTable#clang::driver::getDriverOptTable#clang::driver::getDriverMode',
'llvm::StringMapImpl::RehashTable#llvm::opt::OptTable::OptTable#clang::driver::getDriverOptTable#clang::driver::getDriverMode',
'llvm::opt::OptTable::addValues#clang::driver::getDriverOptTable#clang::driver::getDriverMode',
'llvm::StringMapImpl::RehashTable#clang::driver::Driver::getToolChain#clang::driver::Driver::BuildCompilation',
#csdn blog 复制不了那么多行
'llvm::StringMapImpl::RehashTable#llvm::MCContext::createELFSectionImpl#llvm::MCContext::createELFRelSection#(anonymous namespace)::ELFWriter::createRelocationSection#(anonymous namespace)::ELFWriter::writeObject#llvm::MCAssembler::Finish#llvm::MCObjectStreamer::finishImpl#llvm::MCELFStreamer::finishImpl#llvm::MCStreamer::finish#llvm::AsmPrinter::doFinalization#llvm::FPPassManager::doFinalization#(anonymous namespace)::MPPassManager::runOnModule#(anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline#(anonymous namespace)::EmitAssemblyHelper::EmitAssembly#clang::EmitBackendOutput#clang::ParseAST#clang::ASTFrontendAction::ExecuteAction#clang::CodeGenAction::ExecuteAction#clang::FrontendAction::Execute#clang::CompilerInstance::ExecuteAction#cc1_main#ExecuteCC1Tool#llvm::CrashRecoveryContext::RunSafely#clang::driver::CC1Command::Execute#clang::driver::Compilation::ExecuteCommand#clang::driver::Compilation::ExecuteJobs#clang::driver::Driver::ExecuteCompilation',
'llvm::StringMapImpl::RehashTable#llvm::MCContext::createELFSectionImpl#llvm::MCContext::getELFSection#llvm::MCContext::getELFSection#(anonymous namespace)::ELFWriter::computeSymbolTable#(anonymous namespace)::ELFWriter::writeObject#llvm::MCAssembler::Finish#llvm::MCObjectStreamer::finishImpl#llvm::MCELFStreamer::finishImpl#llvm::MCStreamer::finish#llvm::AsmPrinter::doFinalization#llvm::FPPassManager::doFinalization#(anonymous namespace)::MPPassManager::runOnModule#(anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline#(anonymous namespace)::EmitAssemblyHelper::EmitAssembly#clang::EmitBackendOutput#clang::ParseAST#clang::ASTFrontendAction::ExecuteAction#clang::CodeGenAction::ExecuteAction#clang::FrontendAction::Execute#clang::CompilerInstance::ExecuteAction#cc1_main#ExecuteCC1Tool#llvm::CrashRecoveryContext::RunSafely#clang::driver::CC1Command::Execute#clang::driver::Compilation::ExecuteCommand#clang::driver::Compilation::ExecuteJobs#clang::driver::Driver::ExecuteCompilation']
4 作图