237 {
238
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;
243 return;
244 }
245
246 double inv_total_bytes = 1. / static_cast<double> (statbuf.st_size);
247 {
248 unsigned long long byte_counter = 0, stack_counter = 0, total_size = 0;
249
250
251 std::cout <<
"reading traces from " <<
input <<
" ... " << std::endl;
252 FILE* fprof = popen( ("gzip -dc " + input).c_str(), "r" );
253
254 long size = 0, nstack = 0, step_progress = 0, progress = 0;
255 const int maxstack = 128;
257
258 std::cout.setf( std::ios::fixed, std::ios::floatfield );
259 std::cout << std::setprecision( 2 );
260
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;
265 if (nstack < 0)
266 nstack = 0;
267 else if (nstack > maxstack) {
268 nskip = nstack - maxstack;
269 nstack = maxstack;
270 }
271 if ((
long)fread( (
void*)stacktrace,
sizeof(
Address_t), nstack, fprof ) < nstack)
break;
272 while (nskip > 0) {
274 if ((
long)fread( &dum,
sizeof(
Address_t), 1, fprof ) < 1)
break;
276 }
277
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();
287 }
288 }
289 }
290
291 stack_counter += 1;
292 total_size += size;
293
294 CallInfo_t caller_info( 0, stacktrace[nstack-1] );
297
299
300 for (
int i = nstack-1;
i > 0; --
i ) {
301
302
303
304
305
306 callee_info =
CallInfo_t( stacktrace[i], stacktrace[i-1] );
307
308
310
311
312
313 callee_info =
CallInfo_t( stacktrace[i], stacktrace[0] );
314
316
317
318
320 }
321
322 }
323
326
327
331
335
336
339
340 break;
341
342 } else if ( i == 1 ) {
343
344
347
350
354
355 break;
356 }
357
358 caller = callee;
359 caller_info = callee_info;
360 }
361
362 }
363
364 pclose( fprof );
365
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();
371 }
372 }
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;
376 }
377
378 {
379
380 std::cout << "calculating sizes ... " << std::endl;
383 }
384
385 }
386
387 {
388
389 std::cout <<
"writing output to " <<
output <<
" ... (" <<
gCallTree.size() <<
" top level entries)" << std::endl;
390
391 std::ofstream fresult(
output.c_str() );
392 fresult << "events: memsize nallocs\n\n";
393
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';
400 }
401 fresult << '\n';
402
407 }
408
409 fresult.close();
410
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;
415
416 }
417
418
424}
unsigned long long gTotalSize2
unsigned long long gTotalIncl
unsigned long long gTotalCalls
unsigned long long gTotalSize1
void WriteCallPoint(std::ofstream &f, const CallInfo_t &call_info, const CallPoint &callpoint)
std::string getSymbol(Address_t address)
std::pair< Address_t, Address_t > CallInfo_t
bool isKnownSymbol(const CallInfo_t &call_info)
unsigned long long m_news
unsigned long long m_called