#include <string>
Go to the source code of this file.
Functions | |
void | writeProfileData (int inputFileDescriptor, const std::string &prefix) |
void writeProfileData | ( | int | inputFileDescriptor, |
const std::string & | prefix | ||
) |
Definition at line 159 of file ProfParse.cc.
References Sym::addr_, trackerHits::c, alignCSCRings::e, Sym::id_, idComp(), idSort(), info, Sym::library_, make_name(), mergeVDriftHistosByStation::name, Sym::name_, Sym::next_id_, Reader::nextSample(), pathSort(), alignCSCRings::r, python::multivaluedict::sort(), AlCaHLTBitMon_QueryRunRegistry::string, symSort(), pileupDistInMC::total, PathTracker::tree_, v, relativeConstraints::value, and verifyFile().
Referenced by SimpleProfiler::complete(), and writeProfileDataC().
{ std::string output_tree(prefix+"_paths"); std::string output_names(prefix+"_names"); std::string output_totals(prefix+"_totals"); std::ofstream nost(output_names.c_str()); std::ofstream tost(output_tree.c_str()); std::ofstream sost(output_totals.c_str()); verifyFile(nost,output_names); verifyFile(tost,output_tree); verifyFile(sost,output_totals); VertexSet symset; PathSet pathset; std::pair<VertexSet::iterator,bool> irc,prev_irc; std::pair<PathSet::iterator,bool> prc; VoidVec v; int len=0; int total=0; int total_failed=0; int total_missing=0; // int failure_count=0; Sym last_none_entry; Sym last_good_entry; Reader r(fd); std::string unk("unknown_name"); while (r.nextSample(v)) { PathTracker ptrack; ++total; len = v.size(); if(len==0) continue; // should never happen! VoidVec::reverse_iterator c(v.rbegin()),e(v.rend()); bool first_pass=true; while(c != e) { Sym::address_type value = reinterpret_cast<Sym::address_type>(*c); const Sym* entry = 0; Dl_info info; void* addr = static_cast<void*>(value); if(dladdr(addr,&info) != 0) { std::string name = make_name(info, addr, "unknown_"); last_good_entry.name_ = name; last_good_entry.library_ = info.dli_fname; last_good_entry.id_ = 0; void* function_address = info.dli_saddr; // If we find the address of this function, we make a // unique VertexTracker for that function. If not, we // make a unique VertexTracker for this exact address. last_good_entry.addr_ = function_address ? function_address : value; entry = &last_good_entry; } else { // dladdr has failed /* std::cerr << "sample " << total << ": dladdr failed for address: " << *c << std::endl; */ ++total_failed; std::ostringstream oss; oss << "lookup_failure_" << addr; last_none_entry.name_ = oss.str(); last_none_entry.library_ = "unknown"; last_none_entry.id_ = Sym::next_id_++; last_none_entry.addr_ = value; entry = &last_none_entry; } irc = symset.insert(VertexTracker(*entry)); if(irc.second) { irc.first->setID(); } irc.first->incTotal(); ptrack.tree_.push_back(irc.first->id_); if(!first_pass) ++prev_irc.first->edges_[irc.first->id_]; else first_pass=false; prev_irc = irc; ++c; } irc.first->incLeaf(); prc = pathset.insert(ptrack); if(prc.second) { prc.first->setID(); } prc.first->incTotal(); } // ------------------ copy the vertices for sorting and searching ------ int setsize = symset.size(); int edgesize = 0; Viter vsyms; vsyms.reserve(setsize); //cout << "------ symset -----" << std::endl; VertexSet::const_iterator isym(symset.begin()),esym(symset.end()); while(isym!=esym) { //cout << " " << *isym << std::endl; vsyms.push_back(isym); ++isym; } // ------ calculate samples for parents and percentages in vertices ------ //edm::sort_all(vsyms,idSort); std::sort(vsyms.begin(), vsyms.end(), idSort); //Viter::iterator Vib(vsyms.begin()),Vie(vsyms.end()); //std::cout << "sorted table --------------" << std::endl; //while(Vib!=Vie) { std::cout << " " << *(*Vib) << std::endl; ++Vib; } PathSet::const_iterator pat_it_beg(pathset.begin()), pat_it_end(pathset.end()); while(pat_it_beg!=pat_it_end) { // get set of unique IDs from the path ULVec pathcopy(pat_it_beg->tree_); //edm::sort_all(pathcopy); std::sort(pathcopy.begin(), pathcopy.end()); ULVec::iterator iter = unique(pathcopy.begin(),pathcopy.end()); ULVec::iterator cop_beg(pathcopy.begin()); //cout << "length of unique = " << distance(cop_beg,iter) << std::endl; while(cop_beg!=iter) { //cout << " entry " << *cop_beg << std::endl; Viter::iterator sym_iter = upper_bound(vsyms.begin(),vsyms.end(), *cop_beg,idComp); if(sym_iter==vsyms.begin()) { ++total_missing; /* std::cerr << "found a missing sym entry for address " << *cop_beg << std::endl; */ } else { --sym_iter; //cout << " symiter " << *(*sym_iter) << std::endl; (*sym_iter)->incPath(pat_it_beg->total_); } ++cop_beg; } ++pat_it_beg; } VertexSet::iterator ver_iter(symset.begin()),ver_iter_end(symset.end()); float ftotal = (total != 0 ? (float)total : 1.0); // Avoids possible divide by zero. while(ver_iter != ver_iter_end) { ver_iter->percent_leaf_ = (float)ver_iter->total_as_leaf_ / ftotal; ver_iter->percent_path_ = (float)ver_iter->in_path_ / ftotal; ++ver_iter; } // -------------- write out the vertices ---------------- //edm::sort_all(vsyms,symSort); std::sort(vsyms.begin(), vsyms.end(), symSort); Viter::reverse_iterator vvi(vsyms.rbegin()),vve(vsyms.rend()); while(vvi != vve) { nost << *(*vvi) << "\n"; ++vvi; } // --------------- write out the paths ------------------ int pathsize = pathset.size(); Piter vpaths; vpaths.reserve(pathsize); PathSet::const_iterator ipath(pathset.begin()),epath(pathset.end()); while(ipath != epath) { vpaths.push_back(ipath); ++ipath; } //edm::sort_all(vpaths,pathSort); std::sort(vpaths.begin(),vpaths.end(),pathSort); Piter::reverse_iterator ppi(vpaths.rbegin()),ppe(vpaths.rend()); while(ppi != ppe) { tost << *(*ppi) << "\n"; ++ppi; } // ------------ totals -------------------- sost << "total_samples " << total << "\n" << "total_functions " << setsize << "\n" << "total_paths " << pathsize << "\n" << "total_edges " << edgesize << std::endl << "total_failed_lookups " << total_failed << std::endl << "total_missing_sym_entries " << total_missing << std::endl; }