#include "mac_shared.h"
#include "memcheck.h"
-//#include "vg_profile.c"
/*------------------------------------------------------------*/
#include "pub_tool_hashtable.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_options.h"
+#include "pub_tool_profile.h"
#include "pub_tool_tooliface.h"
#include "cg_arch.h"
pub_core_main.h \
pub_core_mallocfree.h \
pub_core_options.h \
+ pub_core_profile.h \
pub_core_redir.h \
pub_core_replacemalloc.h\
pub_core_scheduler.h \
m_main.c \
m_mallocfree.c \
m_options.c \
+ m_profile.c \
m_redir.c \
m_signals.c \
m_skiplist.c \
ume.c \
vg_messages.c \
vg_mylibc.c \
- vg_dummy_profile.c \
vg_threadmodel.c \
vg_pthreadmodel.c
extern Int VG_(fd_soft_limit);
extern Int VG_(fd_hard_limit);
-/* ---------------------------------------------------------------------
- Profiling stuff
- ------------------------------------------------------------------ */
-
-extern void VG_(init_profiling) ( void );
-extern void VG_(done_profiling) ( void );
-
-#undef VGP_PUSHCC
-#undef VGP_POPCC
-#define VGP_PUSHCC(x) if (VG_(clo_profile)) VG_(pushcc)(x)
-#define VGP_POPCC(x) if (VG_(clo_profile)) VG_(popcc)(x)
-
-
/* ---------------------------------------------------------------------
Exports of vg_intercept.c
------------------------------------------------------------------ */
#include "pub_core_aspacemgr.h"
#include "pub_core_demangle.h"
#include "pub_core_options.h"
+#include "pub_core_profile.h"
#include "pub_core_redir.h"
#include "pub_core_tooliface.h"
#include "priv_symtab.h"
#include "core.h"
#include "pub_core_demangle.h"
#include "pub_core_options.h"
+#include "pub_core_profile.h"
#include "demangle.h"
void VG_(demangle) ( Char* orig, Char* result, Int result_size )
#include "core.h"
#include "pub_core_execontext.h"
#include "pub_core_options.h"
+#include "pub_core_profile.h"
/*------------------------------------------------------------*/
/*--- Low-level ExeContext storage. ---*/
#include "pub_core_execontext.h"
#include "pub_core_main.h"
#include "pub_core_options.h"
+#include "pub_core_profile.h"
#include "pub_core_redir.h"
#include "pub_core_signals.h"
#include "pub_core_syscalls.h"
#include "core.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_options.h"
+#include "pub_core_profile.h"
#include "valgrind.h"
//zz#include "memcheck/memcheck.h"
/*--------------------------------------------------------------------*/
-/*--- Profiling machinery. #include this file into a tool to ---*/
-/*--- enable --profile=yes, but not for release versions of tools, ---*/
-/*--- because it uses glibc code. ---*/
-/*--- vg_profile.c ---*/
+/*--- Profiling machinery. m_profile.c ---*/
/*--------------------------------------------------------------------*/
/*
The GNU General Public License is contained in the file COPYING.
*/
-#ifndef __VG_PROFILE_C
-#define __VG_PROFILE_C
-
-#include "tool.h"
+#include "core.h"
+#include "pub_core_profile.h"
/* get rid of these, if possible */
#include <signal.h>
#include <sys/time.h>
-/* Override the empty definitions from tool.h */
-#undef VGP_PUSHCC
-#undef VGP_POPCC
-#define VGP_PUSHCC(x) if (VG_(clo_profile)) VG_(pushcc)(x)
-#define VGP_POPCC(x) if (VG_(clo_profile)) VG_(popcc)(x)
#define VGP_M_STACK 20
#define VGP_MAX_CCS 50
-
/* All zeroed initially because they're static */
static Int vgp_nticks;
vgp_names[n] = name;
}
-void VG_(tick) ( int sigNo )
+static void tick ( int sigNo )
{
Int cc;
vgp_nticks++;
struct itimerval value;
Int ret;
+#ifndef VG_DO_PROFILING
+ VG_(printf)("valgrind: you must compile with VG_DO_PROFILING defined\n");
+ VG_(printf)(" before using --profile=yes. Aborting.\n");
+ VG_(exit)(1);
+#endif
+
/* Register core events... tricky macro definition causes
VG_(register_profile_event)() to be called once for each core event
in VGP_CORE_LIST. */
value.it_interval.tv_usec = 10 * 1000;
value.it_value = value.it_interval;
- signal(SIGPROF, VG_(tick) );
+ signal(SIGPROF, tick );
ret = setitimer(ITIMER_PROF, &value, NULL);
- if (ret != 0) VG_(tool_panic)("vgp_init_profiling");
+ if (ret != 0) VG_(core_panic)("vgp_init_profiling");
}
void VG_(done_profiling) ( void )
"Or if you are nesting profiling events very deeply, increase\n"
"VGP_M_STACK and recompile Valgrind.\n",
VGP_M_STACK, cc, vgp_names[cc]);
- VG_(tool_panic)("Profiling stack overflow");
+ VG_(core_panic)("Profiling stack overflow");
}
vgp_sp++;
vgp_stack[vgp_sp] = cc;
VG_(printf)(
"\nProfile stack underflow. This is due to a VG_(popcc)() without\n"
"a matching VG_(pushcc)(). Make sure they all match.\n");
- VG_(tool_panic)("Profiling stack underflow");
+ VG_(core_panic)("Profiling stack underflow");
}
if (vgp_stack[vgp_sp] != cc) {
Int i;
+ VG_(printf)("profiling problem:\n");
VG_(printf)("popping %s, stack looks like:\n", vgp_names[cc]);
for (i = vgp_sp; i >= 0; i--)
VG_(printf)("%2d: %s\n", i, vgp_names[vgp_stack[i]]);
vgp_sp--;
}
-#endif /* __VG_PROFILE_C */
-
/*--------------------------------------------------------------------*/
-/*--- end vg_profile.c ---*/
+/*--- end ---*/
/*--------------------------------------------------------------------*/
+
+
#include "pub_core_errormgr.h"
#include "pub_core_main.h"
#include "pub_core_options.h"
+#include "pub_core_profile.h"
#include "pub_core_replacemalloc.h"
#include "pub_core_scheduler.h"
#include "pub_core_signals.h"
#include "core.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_options.h"
+#include "pub_core_profile.h"
#include "pub_core_stacktrace.h"
/*------------------------------------------------------------*/
#include "pub_core_debuglog.h"
#include "pub_core_aspacemgr.h"
#include "pub_core_main.h"
+#include "pub_core_profile.h"
#include "pub_core_stacktrace.h"
#include "pub_core_syscalls.h"
#include "pub_core_tooliface.h"
Bool runInLWP = False;
Bool syscall_done = False; /* we actually ran the syscall */
- VGP_PUSHCC(VgpCoreSysWrap);
+// VGP_PUSHCC(VgpCoreSysWrap);
tst = VG_(get_ThreadState)(tid);
/* VG_(post_syscall) should set this */
vg_assert(tst->syscallno == -1);
- VGP_POPCC(VgpCoreSysWrap);
+// VGP_POPCC(VgpCoreSysWrap);
}
/*--------------------------------------------------------------------*/
#include "pub_core_aspacemgr.h"
#include "pub_core_main.h" // for VG_(bbs_done)
#include "pub_core_options.h"
+#include "pub_core_profile.h"
#include "pub_core_redir.h"
#include "pub_core_signals.h"
#include "pub_core_tooliface.h"
verbosity = VG_(clo_trace_flags);
}
+ VGP_PUSHCC(VgpVexTime);
+
/* Actually do the translation. */
tl_assert2(VG_(tdict).tool_instrument,
"you forgot to set VgToolInterface function 'tool_instrument'");
vg_assert(tmpbuf_used <= N_TMPBUF);
vg_assert(tmpbuf_used > 0);
+ VGP_POPCC(VgpVexTime);
+
#undef DECIDE_IF_PRINTING_CODEGEN
/* Copy data at trans_addr into the translation cache. */
/*--------------------------------------------------------------------*/
-/*--- Dummy profiling machinery -- overridden by tools when they ---*/
-/*--- want profiling. ---*/
-/*--- vg_dummy_profile.c ---*/
+/*--- The built-in profiler. pub_core_profile.h ---*/
/*--------------------------------------------------------------------*/
/*
This file is part of Valgrind, a dynamic binary instrumentation
framework.
- Copyright (C) 2000-2005 Julian Seward
+ Copyright (C) 2000-2005 Julian Seward
jseward@acm.org
This program is free software; you can redistribute it and/or
The GNU General Public License is contained in the file COPYING.
*/
-#include "core.h"
+#ifndef __PUB_CORE_PROFILE_H
+#define __PUB_CORE_PROFILE_H
-static void vgp_die(void)
-{
- VG_(printf)(
- "\nProfiling error:\n"
- " The --profile=yes option was specified, but the tool\n"
- " wasn't built for profiling. #include \"vg_profile.c\"\n"
- " into the tool and rebuild to allow profiling.\n\n");
- VG_(exit)(1);
-}
+//--------------------------------------------------------------------
+// PURPOSE: This module implements Valgrind's internal tick-and-stack-based
+// profiler. To use it, define VG_DO_PROFILING and use --profile=yes.
+// Unfortunately, it's currently broken (and has been for some time)
+// because it doesn't interact well with signal handling.
+//--------------------------------------------------------------------
-void VG_(register_profile_event) ( Int n, Char* name )
-{
-}
+#include "pub_tool_profile.h"
-void VG_(init_profiling) ( void )
-{
- vgp_die();
-}
+extern void VG_(init_profiling) ( void );
+extern void VG_(done_profiling) ( void );
-void VG_(done_profiling) ( void )
-{
- VG_(core_panic)("done_profiling(), but not compiled for profiling??");
-}
-
-void VG_(pushcc) ( UInt cc )
-{
- vgp_die();
-}
-
-void VG_(popcc) ( UInt cc )
-{
- vgp_die();
-}
+#endif // __PUB_CORE_PROFILE_H
/*--------------------------------------------------------------------*/
-/*--- end vg_dummy_profile.c ---*/
+/*--- end ---*/
/*--------------------------------------------------------------------*/
#include "pub_tool_hashtable.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_options.h"
+#include "pub_tool_profile.h"
#include "pub_tool_replacemalloc.h"
#include "pub_tool_tooliface.h"
"Warning: set address range state: large range %d",
len);
- VGP_PUSHCC(VgpSARP);
+ //VGP_PUSHCC(VgpSARP);
/* Remove mutexes in recycled memory range from hash */
find_mutex_range(a, a+len, cleanmx);
VG_(tool_panic)("Unexpected Vge_InitStatus");
}
- VGP_POPCC(VgpSARP);
+ //VGP_POPCC(VgpSARP);
}
-EXTRA_DIST = \
- vg_profile.c
-
incincdir = $(includedir)/valgrind
incinc_HEADERS = \
pub_tool_hashtable.h \
pub_tool_mallocfree.h \
pub_tool_options.h \
+ pub_tool_profile.h \
pub_tool_replacemalloc.h \
pub_tool_skiplist.h \
pub_tool_stacktrace.h \
--- /dev/null
+
+/*--------------------------------------------------------------------*/
+/*--- The built-in profiler. pub_tool_profile.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward
+ jseward@acm.org
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307, USA.
+
+ The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_TOOL_PROFILE_H
+#define __PUB_TOOL_PROFILE_H
+
+// Define this to turn on profiling.
+//#define VG_DO_PROFILING 1
+
+/* Override the empty definitions from tool.h */
+#ifdef VG_DO_PROFILING
+# define VGP_PUSHCC(x) if (VG_(clo_profile)) VG_(pushcc)(x)
+# define VGP_POPCC(x) if (VG_(clo_profile)) VG_(popcc)(x)
+#else
+# define VGP_PUSHCC(x)
+# define VGP_POPCC(x)
+#endif
+
+/* Nb: VG_(register_profile_event)() relies on VgpUnc being the first one */
+#define VGP_CORE_LIST \
+ /* These ones depend on the core */ \
+ VGP_PAIR(VgpUnc, "unclassified"), \
+ VGP_PAIR(VgpStartup, "startup"), \
+ VGP_PAIR(VgpRun, "running"), \
+ VGP_PAIR(VgpSched, "scheduler"), \
+ VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
+ VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
+ VGP_PAIR(VgpTranslate, "translate-main"), \
+ VGP_PAIR(VgpVexTime, "Vex-time"), \
+ VGP_PAIR(VgpImprove, "improve"), \
+ VGP_PAIR(VgpESPUpdate, "ESP-update"), \
+ VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
+ VGP_PAIR(VgpExeContext, "exe-context"), \
+ VGP_PAIR(VgpReadSyms, "read-syms"), \
+ VGP_PAIR(VgpSearchSyms, "search-syms"), \
+ VGP_PAIR(VgpAddToT, "add-to-transtab"), \
+ VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \
+ VGP_PAIR(VgpDemangle, "demangle"), \
+ VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \
+ VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \
+ /* These ones depend on the tool */ \
+ VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \
+ VGP_PAIR(VgpPostCloInit, "post-clo-init"), \
+ VGP_PAIR(VgpInstrument, "instrument"), \
+ VGP_PAIR(VgpToolSysWrap, "tool-syscall-wrapper"), \
+ VGP_PAIR(VgpToolCheapSanity, "tool-cheap-sanity"), \
+ VGP_PAIR(VgpToolExpensiveSanity, "tool-expensive-sanity"), \
+ VGP_PAIR(VgpFini, "fini")
+
+#define VGP_PAIR(n,name) n
+typedef enum { VGP_CORE_LIST } VgpCoreCC;
+#undef VGP_PAIR
+
+/* When registering tool profiling events, ensure that the 'n' value is in
+ * the range (VgpFini+1..) */
+extern void VG_(register_profile_event) ( Int n, Char* name );
+
+extern void VG_(pushcc) ( UInt cc );
+extern void VG_(popcc) ( UInt cc );
+
+#endif // __PUB_TOOL_PROFILE_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
extern UInt VG_(vmessage) ( VgMsgKind kind, const HChar* format, va_list vargs );
-/*====================================================================*/
-/*=== Profiling ===*/
-/*====================================================================*/
-
-/* Nb: VG_(register_profile_event)() relies on VgpUnc being the first one */
-#define VGP_CORE_LIST \
- /* These ones depend on the core */ \
- VGP_PAIR(VgpUnc, "unclassified"), \
- VGP_PAIR(VgpStartup, "startup"), \
- VGP_PAIR(VgpRun, "running"), \
- VGP_PAIR(VgpSched, "scheduler"), \
- VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
- VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
- VGP_PAIR(VgpTranslate, "translate-main"), \
- VGP_PAIR(VgpToUCode, "to-ucode"), \
- VGP_PAIR(VgpFromUcode, "from-ucode"), \
- VGP_PAIR(VgpImprove, "improve"), \
- VGP_PAIR(VgpESPUpdate, "ESP-update"), \
- VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
- VGP_PAIR(VgpLiveness, "liveness-analysis"), \
- VGP_PAIR(VgpDoLRU, "do-lru"), \
- VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
- VGP_PAIR(VgpExeContext, "exe-context"), \
- VGP_PAIR(VgpReadSyms, "read-syms"), \
- VGP_PAIR(VgpSearchSyms, "search-syms"), \
- VGP_PAIR(VgpAddToT, "add-to-transtab"), \
- VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \
- VGP_PAIR(VgpDemangle, "demangle"), \
- VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \
- VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \
- /* These ones depend on the tool */ \
- VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \
- VGP_PAIR(VgpPostCloInit, "post-clo-init"), \
- VGP_PAIR(VgpInstrument, "instrument"), \
- VGP_PAIR(VgpToolSysWrap, "tool-syscall-wrapper"), \
- VGP_PAIR(VgpToolCheapSanity, "tool-cheap-sanity"), \
- VGP_PAIR(VgpToolExpensiveSanity, "tool-expensive-sanity"), \
- VGP_PAIR(VgpFini, "fini")
-
-#define VGP_PAIR(n,name) n
-typedef enum { VGP_CORE_LIST } VgpCoreCC;
-#undef VGP_PAIR
-
-/* When registering tool profiling events, ensure that the 'n' value is in
- * the range (VgpFini+1..) */
-extern void VG_(register_profile_event) ( Int n, Char* name );
-
-extern void VG_(pushcc) ( UInt cc );
-extern void VG_(popcc) ( UInt cc );
-
-/* Define them only if they haven't already been defined by vg_profile.c */
-#ifndef VGP_PUSHCC
-# define VGP_PUSHCC(x)
-#endif
-#ifndef VGP_POPCC
-# define VGP_POPCC(x)
-#endif
-
-
/*====================================================================*/
/*=== Useful stuff to call from generated code ===*/
/*====================================================================*/
#include "pub_tool_hashtable.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_options.h"
+#include "pub_tool_profile.h"
#include "pub_tool_replacemalloc.h"
#include "pub_tool_stacktrace.h"
#include "pub_tool_tooliface.h"
#include "pub_tool_hashtable.h"
#include "pub_tool_mallocfree.h"
#include "pub_tool_options.h"
+#include "pub_tool_profile.h"
#include "pub_tool_replacemalloc.h"
#include "pub_tool_tooliface.h"