~bkerensa/ubuntu/raring/valgrind/merge-from-deb

« back to all changes in this revision

Viewing changes to callgrind/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrés Roldán
  • Date: 2008-06-13 02:31:40 UTC
  • mto: (1.4.1 upstream) (2.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20080613023140-iwk33rz9rhvfkr96
Import upstream version 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
   This file is part of Callgrind, a Valgrind tool for call graph
9
9
   profiling programs.
10
10
 
11
 
   Copyright (C) 2002-2006, Josef Weidendorfer (Josef.Weidendorfer@gmx.de)
 
11
   Copyright (C) 2002-2007, Josef Weidendorfer (Josef.Weidendorfer@gmx.de)
12
12
 
13
 
   This skin is derived from and contains code from Cachegrind
14
 
   Copyright (C) 2002-2006 Nicholas Nethercote (njn25@cam.ac.uk)
 
13
   This tool is derived from and contains code from Cachegrind
 
14
   Copyright (C) 2002-2007 Nicholas Nethercote (njn@valgrind.org)
15
15
 
16
16
   This program is free software; you can redistribute it and/or
17
17
   modify it under the terms of the GNU General Public License as
112
112
}
113
113
 
114
114
static
115
 
EventSet* insert_simcall(IRBB* bbOut, InstrInfo* ii, UInt dataSize,
 
115
EventSet* insert_simcall(IRSB* bbOut, InstrInfo* ii, UInt dataSize,
116
116
                         Bool instrIssued,
117
117
                         IRExpr* loadAddrExpr, IRExpr* storeAddrExpr)
118
118
{
228
228
    
229
229
    di = unsafeIRDirty_0_N( argc, helperName, 
230
230
                                  VG_(fnptr_to_fnentry)( helperAddr ), argv);
231
 
    addStmtToIRBB( bbOut, IRStmt_Dirty(di) );
 
231
    addStmtToIRSB( bbOut, IRStmt_Dirty(di) );
232
232
 
233
233
    return es;
234
234
}
239
239
 * Fills the InstrInfo struct if not seen before
240
240
 */
241
241
static
242
 
void endOfInstr(IRBB* bbOut, InstrInfo* ii, Bool bb_seen_before,
 
242
void endOfInstr(IRSB* bbOut, InstrInfo* ii, Bool bb_seen_before,
243
243
                UInt instr_offset, UInt instrLen, UInt dataSize, 
244
244
                UInt* cost_offset, Bool instrIssued,
245
245
                IRExpr* loadAddrExpr, IRExpr* storeAddrExpr)
344
344
 *
345
345
 * Called from CLG_(get_bb)
346
346
 */
347
 
void CLG_(collectBlockInfo)(IRBB* bbIn,
 
347
void CLG_(collectBlockInfo)(IRSB* bbIn,
348
348
                            /*INOUT*/ UInt* instrs,
349
349
                            /*INOUT*/ UInt* cjmps,
350
350
                            /*INOUT*/ Bool* cjmp_inverted)
389
389
}
390
390
 
391
391
static
392
 
void collectStatementInfo(IRTypeEnv* tyenv, IRBB* bbOut, IRStmt* st,
 
392
void collectStatementInfo(IRTypeEnv* tyenv, IRSB* bbOut, IRStmt* st,
393
393
                          Addr* instrAddr, UInt* instrLen,
394
394
                          IRExpr** loadAddrExpr, IRExpr** storeAddrExpr,
395
395
                          UInt* dataSize, IRType hWordTy)
419
419
      *instrLen =        st->Ist.IMark.len;
420
420
      break;
421
421
 
422
 
   case Ist_Tmp: {
423
 
      IRExpr* data = st->Ist.Tmp.data;
 
422
   case Ist_WrTmp: {
 
423
      IRExpr* data = st->Ist.WrTmp.data;
424
424
      if (data->tag == Iex_Load) {
425
425
         IRExpr* aexpr = data->Iex.Load.addr;
426
426
         CLG_ASSERT( isIRAtom(aexpr) );
468
468
 
469
469
   case Ist_Put:
470
470
   case Ist_PutI:
471
 
   case Ist_MFence:
 
471
   case Ist_MBE:
472
472
   case Ist_Exit:
473
473
       break;
474
474
 
481
481
}
482
482
 
483
483
static
484
 
void addConstMemStoreStmt( IRBB* bbOut, UWord addr, UInt val, IRType hWordTy)
 
484
void addConstMemStoreStmt( IRSB* bbOut, UWord addr, UInt val, IRType hWordTy)
485
485
{
486
 
    addStmtToIRBB( bbOut,
 
486
    addStmtToIRSB( bbOut,
487
487
                   IRStmt_Store(CLGEndness,
488
488
                                IRExpr_Const(hWordTy == Ity_I32 ?
489
489
                                             IRConst_U32( addr ) :
492
492
}   
493
493
 
494
494
static
495
 
IRBB* CLG_(instrument)( VgCallbackClosure* closure,
496
 
                        IRBB* bbIn,
 
495
IRSB* CLG_(instrument)( VgCallbackClosure* closure,
 
496
                        IRSB* bbIn,
497
497
                        VexGuestLayout* layout,
498
498
                        VexGuestExtents* vge,
499
499
                        IRType gWordTy, IRType hWordTy )
500
500
{
501
501
   Int      i;
502
 
   IRBB*    bbOut;
 
502
   IRSB*    bbOut;
503
503
   IRStmt*  st, *stnext;
504
504
   Addr     instrAddr, origAddr;
505
505
   UInt     instrLen = 0, dataSize;
529
529
 
530
530
   CLG_DEBUG(3, "+ instrument(BB %p)\n", (Addr)closure->readdr);
531
531
 
532
 
   /* Set up BB for instrumented IR */
533
 
   bbOut           = emptyIRBB();
534
 
   bbOut->tyenv    = dopyIRTypeEnv(bbIn->tyenv);
535
 
   bbOut->next     = dopyIRExpr(bbIn->next);
536
 
   bbOut->jumpkind = bbIn->jumpkind;
 
532
   /* Set up SB for instrumented IR */
 
533
   bbOut = deepCopyIRSBExceptStmts(bbIn);
537
534
 
538
535
   // Copy verbatim any IR preamble preceding the first IMark
539
536
   i = 0;
540
537
   while (i < bbIn->stmts_used && bbIn->stmts[i]->tag != Ist_IMark) {
541
 
      addStmtToIRBB( bbOut, bbIn->stmts[i] );
 
538
      addStmtToIRSB( bbOut, bbIn->stmts[i] );
542
539
      i++;
543
540
   }
544
541
 
583
580
   di = unsafeIRDirty_0_N( 1, "setup_bbcc", 
584
581
                              VG_(fnptr_to_fnentry)( & CLG_(setup_bbcc) ), 
585
582
                              argv);
586
 
   addStmtToIRBB( bbOut, IRStmt_Dirty(di) );
 
583
   addStmtToIRSB( bbOut, IRStmt_Dirty(di) );
587
584
 
588
585
   instrCount = 0;
589
586
   costOffset = 0;
643
640
              cJumps++;
644
641
          }
645
642
 
646
 
          addStmtToIRBB( bbOut, st );
 
643
          addStmtToIRSB( bbOut, st );
647
644
          st = stnext;
648
645
      } 
649
646
      while (!beforeIBoundary);
704
701
// any reason at all: to free up space, because the guest code was
705
702
// unmapped or modified, or for any arbitrary reason.
706
703
static
707
 
void clg_discard_basic_block_info ( Addr64 orig_addr64, VexGuestExtents vge )
 
704
void clg_discard_superblock_info ( Addr64 orig_addr64, VexGuestExtents vge )
708
705
{
709
706
    Addr orig_addr = (Addr)orig_addr64;
710
707
 
711
708
    tl_assert(vge.n_used > 0);
712
709
 
713
710
   if (0)
714
 
      VG_(printf)( "discard_basic_block_info: %p, %p, %llu\n",
 
711
      VG_(printf)( "discard_superblock_info: %p, %p, %llu\n",
715
712
                   (void*)(Addr)orig_addr,
716
713
                   (void*)(Addr)vge.base[0], (ULong)vge.len[0]);
717
714
 
820
817
   case VG_USERREQ__DUMP_STATS_AT:
821
818
     {
822
819
       Char buf[512];
823
 
       VG_(sprintf)(buf,"Client Request: %s", args[1]);
 
820
       VG_(sprintf)(buf,"Client Request: %s", (Char*)args[1]);
824
821
       CLG_(dump_profile)(buf, True);
825
822
       *ret = 0;                 /* meaningless */
826
823
     }
886
883
static
887
884
void CLG_(post_syscalltime)(ThreadId tid, UInt syscallno, SysRes res)
888
885
{
889
 
  if (CLG_(clo).collect_systime) {
 
886
  if (CLG_(clo).collect_systime &&
 
887
      CLG_(current_state).bbcc) {
890
888
    Int o = CLG_(sets).off_full_systime;
891
889
#if CLG_MICROSYSTIME
892
890
    struct vki_timeval tv_now;
924
922
  /* pop all remaining items from CallStack for correct sum
925
923
   */
926
924
  CLG_(forall_threads)(unwind_thread);
927
 
  
 
925
 
928
926
  CLG_(dump_profile)(0, False);
929
 
  
 
927
 
930
928
  CLG_(finish_command)();
931
 
  
 
929
 
932
930
  if (VG_(clo_verbosity) == 0) return;
933
931
  
934
932
  /* Hash table stats */
1025
1023
/*--- Setup                                                        ---*/
1026
1024
/*--------------------------------------------------------------------*/
1027
1025
 
 
1026
static void clg_start_client_code_callback ( ThreadId tid, ULong blocks_done )
 
1027
{
 
1028
   static ULong last_blocks_done = 0;
 
1029
 
 
1030
   if (0)
 
1031
      VG_(printf)("%d R %llu\n", (Int)tid, blocks_done);
 
1032
 
 
1033
   /* throttle calls to CLG_(run_thread) by number of BBs executed */
 
1034
   if (blocks_done - last_blocks_done < 5000) return;
 
1035
   last_blocks_done = blocks_done;
 
1036
 
 
1037
   CLG_(run_thread)( tid );
 
1038
}
 
1039
 
1028
1040
static
1029
1041
void CLG_(post_clo_init)(void)
1030
1042
{
1031
 
   Char *dir = 0, *fname = 0;
1032
 
 
1033
1043
   VG_(clo_vex_control).iropt_unroll_thresh = 0;
1034
1044
   VG_(clo_vex_control).guest_chase_thresh = 0;
1035
1045
 
1042
1052
       CLG_(clo).dump_line = True;
1043
1053
   }
1044
1054
 
1045
 
   CLG_(init_files)(&dir,&fname);
1046
 
   CLG_(init_command)(dir,fname);
 
1055
   CLG_(init_dumps)();
 
1056
   CLG_(init_command)();
1047
1057
 
1048
1058
   (*CLG_(cachesim).post_clo_init)();
1049
1059
 
1073
1083
    VG_(details_name)            ("Callgrind");
1074
1084
    VG_(details_version)         (NULL);
1075
1085
    VG_(details_description)     ("a call-graph generating cache profiler");
1076
 
    VG_(details_copyright_author)("Copyright (C) 2002-2006, and GNU GPL'd, "
 
1086
    VG_(details_copyright_author)("Copyright (C) 2002-2007, and GNU GPL'd, "
1077
1087
                                  "by Josef Weidendorfer et al.");
1078
1088
    VG_(details_bug_reports_to)  (VG_BUGS_TO);
1079
 
    VG_(details_avg_translation_sizeB) ( 245 );
 
1089
    VG_(details_avg_translation_sizeB) ( 500 );
1080
1090
 
1081
1091
    VG_(basic_tool_funcs)        (CLG_(post_clo_init),
1082
1092
                                  CLG_(instrument),
1083
1093
                                  CLG_(fini));
1084
1094
 
1085
 
    VG_(needs_basic_block_discards)(clg_discard_basic_block_info);
 
1095
    VG_(needs_superblock_discards)(clg_discard_superblock_info);
1086
1096
 
1087
1097
 
1088
1098
    VG_(needs_command_line_options)(CLG_(process_cmd_line_option),
1093
1103
    VG_(needs_syscall_wrapper)(CLG_(pre_syscalltime),
1094
1104
                               CLG_(post_syscalltime));
1095
1105
 
1096
 
    VG_(track_thread_run) ( & CLG_(run_thread) );
1097
 
    VG_(track_pre_deliver_signal)  ( & CLG_(pre_signal) );
1098
 
    VG_(track_post_deliver_signal)  ( & CLG_(post_signal) );
 
1106
    VG_(track_start_client_code)  ( & clg_start_client_code_callback );
 
1107
    VG_(track_pre_deliver_signal) ( & CLG_(pre_signal) );
 
1108
    VG_(track_post_deliver_signal)( & CLG_(post_signal) );
1099
1109
 
1100
1110
    CLG_(set_clo_defaults)();
1101
1111
}