239 boost::io::ios_base_all_saver coutsave (std::cout);
241 if (
stat(
input.c_str(), &statbuf ) != 0 ) {
242 std::cout <<
"failed to stat " <<
input <<
" ... exiting ... " << std::endl;
246 double inv_total_bytes = 1. /
static_cast<double> (statbuf.st_size);
248 unsigned long long byte_counter = 0, stack_counter = 0, total_size = 0;
251 std::cout <<
"reading traces from " <<
input <<
" ... " << std::endl;
252 FILE* fprof = popen( (
"gzip -dc " +
input).c_str(),
"r" );
254 long size = 0, nstack = 0, step_progress = 0, progress = 0;
255 const int maxstack = 128;
258 std::cout.setf( std::ios::fixed, std::ios::floatfield );
259 std::cout << std::setprecision( 2 );
261 std::cout <<
" progress: ["; std::cout.flush();
262 while ( fread( (
void*)&
size,
sizeof(
long), 1, fprof ) ) {
263 if (fread( (
void*)&nstack,
sizeof(
long), 1, fprof ) < 1)
break;
267 else if (nstack > maxstack) {
268 nskip = nstack - maxstack;
271 if ((
long)fread( (
void*)stacktrace,
sizeof(
Address_t), nstack, fprof ) < nstack)
break;
274 if ((
long)fread( &dum,
sizeof(
Address_t), 1, fprof ) < 1)
break;
278 byte_counter += (2+nstack)*4;
279 progress = long(2.5*byte_counter * inv_total_bytes);
280 if ( progress > 100 ) progress = 100;
281 if ( step_progress < progress ) {
282 for ( ; step_progress <= progress; ++step_progress ) {
283 if ( ! (step_progress % 20) ) {
284 std::cout << step_progress <<
"%"; std::cout.flush();
285 }
else if ( ! (step_progress % 5) ) {
286 std::cout <<
'.'; std::cout.flush();
294 CallInfo_t caller_info( 0, stacktrace[nstack-1] );
300 for (
int i = nstack-1;
i > 0; --
i ) {
306 callee_info =
CallInfo_t( stacktrace[
i], stacktrace[
i-1] );
313 callee_info =
CallInfo_t( stacktrace[
i], stacktrace[0] );
319 callee_info.second = gMalloc;
342 }
else if (
i == 1 ) {
359 caller_info = callee_info;
366 for ( ; step_progress <= 100; ++step_progress ) {
367 if ( ! (step_progress % 20) ) {
368 std::cout << step_progress <<
"%"; std::cout.flush();
369 }
else if ( ! (step_progress % 5) ) {
370 std::cout <<
'.'; std::cout.flush();
373 std::cout <<
"]" << std::endl;
374 std::cout <<
"number of stacks: " << stack_counter << std::endl;
375 std::cout <<
"total alloc size: " << total_size << std::endl;
380 std::cout <<
"calculating sizes ... " << std::endl;
389 std::cout <<
"writing output to " <<
output <<
" ... (" <<
gCallTree.size() <<
" top level entries)" << std::endl;
391 std::ofstream fresult(
output.c_str() );
392 fresult <<
"events: memsize nallocs\n\n";
394 fresult <<
"fl=athena.cxx\nfn=athena\n0 0\n";
396 fresult <<
"cfn=" <<
getSymbol( icp->first.second ) <<
'\n';
397 fresult <<
"calls=" << icp->second.m_called <<
' ' << icp->first.second <<
'\n';
398 fresult << icp->first.first <<
' ' << icp->second.m_inclusive
399 <<
' ' << icp->second.m_called <<
'\n';
411 std::cout <<
"cross-check all calls: " <<
gTotalCalls << std::endl;
412 std::cout <<
"cross-check inclusive: " <<
gTotalIncl << std::endl;
413 std::cout <<
"cross-check-size (non-allocator): " <<
gTotalSize1 << std::endl;
414 std::cout <<
"cross-check-size (allocator): " <<
gTotalSize2 << std::endl;