llvm.org GIT mirror llvm / 770b97b
Removing dependency on third party library for Intel JIT event support. Patch committed on behalf of Kirill Uhanov git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164831 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Kaylor 8 years ago
16 changed file(s) with 1386 addition(s) and 477 deletion(s). Raw diff Collapse all Expand all
176176
177177 if( LLVM_USE_INTEL_JITEVENTS )
178178 # Verify we are on a supported platform
179 if( CMAKE_SYSTEM_NAME MATCHES "Windows" OR CMAKE_SYSTEM_NAME MATCHES "Linux" )
180 # Directory where Intel Parallel Amplifier XE 2011 is installed.
181 if ( WIN32 )
182 set(LLVM_INTEL_JITEVENTS_DIR $ENV{VTUNE_AMPLIFIER_XE_2011_DIR})
183 else ( WIN32 )
184 set(LLVM_INTEL_JITEVENTS_DIR "/opt/intel/vtune_amplifier_xe_2011")
185 endif ( WIN32 )
186
187 # Set include and library search paths for Intel JIT Events API
188 set(LLVM_INTEL_JITEVENTS_INCDIR "${LLVM_INTEL_JITEVENTS_DIR}/include")
189
190 if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
191 set(LLVM_INTEL_JITEVENTS_LIBDIR "${LLVM_INTEL_JITEVENTS_DIR}/lib64")
192 else ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
193 set(LLVM_INTEL_JITEVENTS_LIBDIR "${LLVM_INTEL_JITEVENTS_DIR}/lib32")
194 endif ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
195 else()
179 if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
196180 message(FATAL_ERROR
197181 "Intel JIT API support is available on Linux and Windows only.")
198182 endif()
12891289
12901290 dnl Enable support for Intel JIT Events API.
12911291 AC_ARG_WITH(intel-jitevents,
1292 AS_HELP_STRING([--with-intel-jitevents=],
1293 [Specify location of run-time support library for Intel JIT API (default=/opt/intel/vtune_amplifier_xe_2011)]),
1292 AS_HELP_STRING([--with-intel-jitevents Notify Intel JIT profiling API of generated code]),
12941293 [
1294 case "$withval" in
1295 yes) AC_SUBST(USE_INTEL_JITEVENTS,[1]);;
1296 no) AC_SUBST(USE_INTEL_JITEVENTS,[0]);;
1297 *) AC_MSG_ERROR([Invalid setting for --with-intel-jitevents. Use "yes" or "no"]);;
1298 esac
1299
12951300 case $llvm_cv_os_type in
12961301 Linux|Win32|Cygwin|MingW) ;;
1297 *)
1298 AC_MSG_ERROR([
1299 Intel JIT API support is available on Linux and Windows only."]) ;;
1302 *) AC_MSG_ERROR([Intel JIT API support is available on Linux and Windows only.]);;
13001303 esac
13011304
1302 AC_SUBST(USE_INTEL_JITEVENTS, [1])
13031305 case "$llvm_cv_target_arch" in
1304 x86) llvm_intel_jitevents_archdir="lib32";;
1305 x86_64) llvm_intel_jitevents_archdir="lib64";;
1306 *) echo "Target architecture $llvm_cv_target_arch does not support Intel JIT Events API"
1307 exit -1;;
1306 x86|x86_64) ;;
1307 *) AC_MSG_ERROR([Target architecture $llvm_cv_target_arch does not support Intel JIT Events API.]);;
13081308 esac
1309 INTEL_JITEVENTS_INCDIR="/opt/intel/vtune_amplifier_xe_2011/include"
1310 INTEL_JITEVENTS_LIBDIR="/opt/intel/vtune_amplifier_xe_2011/$llvm_intel_jitevents_archdir"
1311 case "$withval" in
1312 /* | [[A-Za-z]]:[[\\/]]*) INTEL_JITEVENTS_INCDIR=$withval/include
1313 INTEL_JITEVENTS_LIBDIR=$withval/$llvm_intel_jitevents_archdir ;;
1314 *) ;;
1315 esac
1316
1317 AC_SUBST(INTEL_JITEVENTS_INCDIR)
1318 AC_SUBST(INTEL_JITEVENTS_LIBDIR)
1319
1320 LIBS="$LIBS -L${INTEL_JITEVENTS_LIBDIR}"
1321 CPPFLAGS="$CPPFLAGS -I$INTEL_JITEVENTS_INCDIR"
1322
1323 AC_SEARCH_LIBS(iJIT_IsProfilingActive, jitprofiling, [], [
1324 echo "Error! Cannot find libjitprofiling.a. Please check path specified in flag --with-intel-jitevents"
1325 exit -1
1326 ])
1327 AC_CHECK_HEADER([jitprofiling.h], [], [
1328 echo "Error! Cannot find jitprofiling.h. Please check path specified in flag --with-intel-jitevents"
1329 exit -1
1330 ])
1331
13321309 ],
13331310 [
13341311 AC_SUBST(USE_INTEL_JITEVENTS, [0])
765765 USE_UDIS86
766766 USE_OPROFILE
767767 USE_INTEL_JITEVENTS
768 INTEL_JITEVENTS_INCDIR
769 INTEL_JITEVENTS_LIBDIR
770768 XML2CONFIG
771769 LIBXML2_LIBS
772770 LIBXML2_INC
14611459 --with-udis86= Use udis86 external x86 disassembler library
14621460 --with-oprofile=
14631461 Tell OProfile >= 0.9.4 how to symbolize JIT output
1464 --with-intel-jitevents=
1465 Specify location of run-time support library for
1466 Intel JIT API
1467 (default=/opt/intel/vtune_amplifier_xe_2011)
1462 --with-intel-jitevents Notify Intel JIT profiling API of generated code
1463
14681464
14691465 Some influential environment variables:
14701466 CC C compiler command
1031510311 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
1031610312 lt_status=$lt_dlunknown
1031710313 cat > conftest.$ac_ext <
10318 #line 10319 "configure"
10314 #line 10315 "configure"
1031910315 #include "confdefs.h"
1032010316
1032110317 #if HAVE_DLFCN_H
1357513571 # Check whether --with-intel-jitevents was given.
1357613572 if test "${with_intel_jitevents+set}" = set; then
1357713573 withval=$with_intel_jitevents;
13574 case "$withval" in
13575 yes) USE_INTEL_JITEVENTS=1
13576 ;;
13577 no) USE_INTEL_JITEVENTS=0
13578 ;;
13579 *) { { echo "$as_me:$LINENO: error: Invalid setting for --with-intel-jitevents. Use \"yes\" or \"no\"" >&5
13580 echo "$as_me: error: Invalid setting for --with-intel-jitevents. Use \"yes\" or \"no\"" >&2;}
13581 { (exit 1); exit 1; }; };;
13582 esac
13583
1357813584 case $llvm_cv_os_type in
1357913585 Linux|Win32|Cygwin|MingW) ;;
13580 *)
13581 { { echo "$as_me:$LINENO: error:
13582 Intel JIT API support is available on Linux and Windows only.\"" >&5
13583 echo "$as_me: error:
13584 Intel JIT API support is available on Linux and Windows only.\"" >&2;}
13585 { (exit 1); exit 1; }; } ;;
13586 *) { { echo "$as_me:$LINENO: error: Intel JIT API support is available on Linux and Windows only." >&5
13587 echo "$as_me: error: Intel JIT API support is available on Linux and Windows only." >&2;}
13588 { (exit 1); exit 1; }; };;
1358613589 esac
1358713590
13588 USE_INTEL_JITEVENTS=1
13589
1359013591 case "$llvm_cv_target_arch" in
13591 x86) llvm_intel_jitevents_archdir="lib32";;
13592 x86_64) llvm_intel_jitevents_archdir="lib64";;
13593 *) echo "Target architecture $llvm_cv_target_arch does not support Intel JIT Events API"
13594 exit -1;;
13592 x86|x86_64) ;;
13593 *) { { echo "$as_me:$LINENO: error: Target architecture $llvm_cv_target_arch does not support Intel JIT Events API." >&5
13594 echo "$as_me: error: Target architecture $llvm_cv_target_arch does not support Intel JIT Events API." >&2;}
13595 { (exit 1); exit 1; }; };;
1359513596 esac
13596 INTEL_JITEVENTS_INCDIR="/opt/intel/vtune_amplifier_xe_2011/include"
13597 INTEL_JITEVENTS_LIBDIR="/opt/intel/vtune_amplifier_xe_2011/$llvm_intel_jitevents_archdir"
13598 case "$withval" in
13599 /* | [A-Za-z]:[\\/]*) INTEL_JITEVENTS_INCDIR=$withval/include
13600 INTEL_JITEVENTS_LIBDIR=$withval/$llvm_intel_jitevents_archdir ;;
13601 *) ;;
13602 esac
13603
13604
13605
13606
13607 LIBS="$LIBS -L${INTEL_JITEVENTS_LIBDIR}"
13608 CPPFLAGS="$CPPFLAGS -I$INTEL_JITEVENTS_INCDIR"
13609
13610 { echo "$as_me:$LINENO: checking for library containing iJIT_IsProfilingActive" >&5
13611 echo $ECHO_N "checking for library containing iJIT_IsProfilingActive... $ECHO_C" >&6; }
13612 if test "${ac_cv_search_iJIT_IsProfilingActive+set}" = set; then
13613 echo $ECHO_N "(cached) $ECHO_C" >&6
13614 else
13615 ac_func_search_save_LIBS=$LIBS
13616 cat >conftest.$ac_ext <<_ACEOF
13617 /* confdefs.h. */
13618 _ACEOF
13619 cat confdefs.h >>conftest.$ac_ext
13620 cat >>conftest.$ac_ext <<_ACEOF
13621 /* end confdefs.h. */
13622
13623 /* Override any GCC internal prototype to avoid an error.
13624 Use char because int might match the return type of a GCC
13625 builtin and then its argument prototype would still apply. */
13626 #ifdef __cplusplus
13627 extern "C"
13628 #endif
13629 char iJIT_IsProfilingActive ();
13630 int
13631 main ()
13632 {
13633 return iJIT_IsProfilingActive ();
13634 ;
13635 return 0;
13636 }
13637 _ACEOF
13638 for ac_lib in '' jitprofiling; do
13639 if test -z "$ac_lib"; then
13640 ac_res="none required"
13641 else
13642 ac_res=-l$ac_lib
13643 LIBS="-l$ac_lib $ac_func_search_save_LIBS"
13644 fi
13645 rm -f conftest.$ac_objext conftest$ac_exeext
13646 if { (ac_try="$ac_link"
13647 case "(($ac_try" in
13648 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
13649 *) ac_try_echo=$ac_try;;
13650 esac
13651 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
13652 (eval "$ac_link") 2>conftest.er1
13653 ac_status=$?
13654 grep -v '^ *+' conftest.er1 >conftest.err
13655 rm -f conftest.er1
13656 cat conftest.err >&5
13657 echo "$as_me:$LINENO: \$? = $ac_status" >&5
13658 (exit $ac_status); } &&
13659 { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
13660 { (case "(($ac_try" in
13661 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
13662 *) ac_try_echo=$ac_try;;
13663 esac
13664 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
13665 (eval "$ac_try") 2>&5
13666 ac_status=$?
13667 echo "$as_me:$LINENO: \$? = $ac_status" >&5
13668 (exit $ac_status); }; } &&
13669 { ac_try='test -s conftest$ac_exeext'
13670 { (case "(($ac_try" in
13671 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
13672 *) ac_try_echo=$ac_try;;
13673 esac
13674 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
13675 (eval "$ac_try") 2>&5
13676 ac_status=$?
13677 echo "$as_me:$LINENO: \$? = $ac_status" >&5
13678 (exit $ac_status); }; }; then
13679 ac_cv_search_iJIT_IsProfilingActive=$ac_res
13680 else
13681 echo "$as_me: failed program was:" >&5
13682 sed 's/^/| /' conftest.$ac_ext >&5
13683
13684
13685 fi
13686
13687 rm -f core conftest.err conftest.$ac_objext \
13688 conftest$ac_exeext
13689 if test "${ac_cv_search_iJIT_IsProfilingActive+set}" = set; then
13690 break
13691 fi
13692 done
13693 if test "${ac_cv_search_iJIT_IsProfilingActive+set}" = set; then
13694 :
13695 else
13696 ac_cv_search_iJIT_IsProfilingActive=no
13697 fi
13698 rm conftest.$ac_ext
13699 LIBS=$ac_func_search_save_LIBS
13700 fi
13701 { echo "$as_me:$LINENO: result: $ac_cv_search_iJIT_IsProfilingActive" >&5
13702 echo "${ECHO_T}$ac_cv_search_iJIT_IsProfilingActive" >&6; }
13703 ac_res=$ac_cv_search_iJIT_IsProfilingActive
13704 if test "$ac_res" != no; then
13705 test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
13706
13707 else
13708
13709 echo "Error! Cannot find libjitprofiling.a. Please check path specified in flag --with-intel-jitevents"
13710 exit -1
13711
13712 fi
13713
13714 if test "${ac_cv_header_jitprofiling_h+set}" = set; then
13715 { echo "$as_me:$LINENO: checking for jitprofiling.h" >&5
13716 echo $ECHO_N "checking for jitprofiling.h... $ECHO_C" >&6; }
13717 if test "${ac_cv_header_jitprofiling_h+set}" = set; then
13718 echo $ECHO_N "(cached) $ECHO_C" >&6
13719 fi
13720 { echo "$as_me:$LINENO: result: $ac_cv_header_jitprofiling_h" >&5
13721 echo "${ECHO_T}$ac_cv_header_jitprofiling_h" >&6; }
13722 else
13723 # Is the header compilable?
13724 { echo "$as_me:$LINENO: checking jitprofiling.h usability" >&5
13725 echo $ECHO_N "checking jitprofiling.h usability... $ECHO_C" >&6; }
13726 cat >conftest.$ac_ext <<_ACEOF
13727 /* confdefs.h. */
13728 _ACEOF
13729 cat confdefs.h >>conftest.$ac_ext
13730 cat >>conftest.$ac_ext <<_ACEOF
13731 /* end confdefs.h. */
13732 $ac_includes_default
13733 #include
13734 _ACEOF
13735 rm -f conftest.$ac_objext
13736 if { (ac_try="$ac_compile"
13737 case "(($ac_try" in
13738 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
13739 *) ac_try_echo=$ac_try;;
13740 esac
13741 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
13742 (eval "$ac_compile") 2>conftest.er1
13743 ac_status=$?
13744 grep -v '^ *+' conftest.er1 >conftest.err
13745 rm -f conftest.er1
13746 cat conftest.err >&5
13747 echo "$as_me:$LINENO: \$? = $ac_status" >&5
13748 (exit $ac_status); } &&
13749 { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
13750 { (case "(($ac_try" in
13751 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
13752 *) ac_try_echo=$ac_try;;
13753 esac
13754 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
13755 (eval "$ac_try") 2>&5
13756 ac_status=$?
13757 echo "$as_me:$LINENO: \$? = $ac_status" >&5
13758 (exit $ac_status); }; } &&
13759 { ac_try='test -s conftest.$ac_objext'
13760 { (case "(($ac_try" in
13761 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
13762 *) ac_try_echo=$ac_try;;
13763 esac
13764 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
13765 (eval "$ac_try") 2>&5
13766 ac_status=$?
13767 echo "$as_me:$LINENO: \$? = $ac_status" >&5
13768 (exit $ac_status); }; }; then
13769 ac_header_compiler=yes
13770 else
13771 echo "$as_me: failed program was:" >&5
13772 sed 's/^/| /' conftest.$ac_ext >&5
13773
13774 ac_header_compiler=no
13775 fi
13776
13777 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
13778 { echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
13779 echo "${ECHO_T}$ac_header_compiler" >&6; }
13780
13781 # Is the header present?
13782 { echo "$as_me:$LINENO: checking jitprofiling.h presence" >&5
13783 echo $ECHO_N "checking jitprofiling.h presence... $ECHO_C" >&6; }
13784 cat >conftest.$ac_ext <<_ACEOF
13785 /* confdefs.h. */
13786 _ACEOF
13787 cat confdefs.h >>conftest.$ac_ext
13788 cat >>conftest.$ac_ext <<_ACEOF
13789 /* end confdefs.h. */
13790 #include
13791 _ACEOF
13792 if { (ac_try="$ac_cpp conftest.$ac_ext"
13793 case "(($ac_try" in
13794 *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
13795 *) ac_try_echo=$ac_try;;
13796 esac
13797 eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
13798 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
13799 ac_status=$?
13800 grep -v '^ *+' conftest.er1 >conftest.err
13801 rm -f conftest.er1
13802 cat conftest.err >&5
13803 echo "$as_me:$LINENO: \$? = $ac_status" >&5
13804 (exit $ac_status); } >/dev/null; then
13805 if test -s conftest.err; then
13806 ac_cpp_err=$ac_c_preproc_warn_flag
13807 ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
13808 else
13809 ac_cpp_err=
13810 fi
13811 else
13812 ac_cpp_err=yes
13813 fi
13814 if test -z "$ac_cpp_err"; then
13815 ac_header_preproc=yes
13816 else
13817 echo "$as_me: failed program was:" >&5
13818 sed 's/^/| /' conftest.$ac_ext >&5
13819
13820 ac_header_preproc=no
13821 fi
13822
13823 rm -f conftest.err conftest.$ac_ext
13824 { echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
13825 echo "${ECHO_T}$ac_header_preproc" >&6; }
13826
13827 # So? What about this header?
13828 case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
13829 yes:no: )
13830 { echo "$as_me:$LINENO: WARNING: jitprofiling.h: accepted by the compiler, rejected by the preprocessor!" >&5
13831 echo "$as_me: WARNING: jitprofiling.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
13832 { echo "$as_me:$LINENO: WARNING: jitprofiling.h: proceeding with the compiler's result" >&5
13833 echo "$as_me: WARNING: jitprofiling.h: proceeding with the compiler's result" >&2;}
13834 ac_header_preproc=yes
13835 ;;
13836 no:yes:* )
13837 { echo "$as_me:$LINENO: WARNING: jitprofiling.h: present but cannot be compiled" >&5
13838 echo "$as_me: WARNING: jitprofiling.h: present but cannot be compiled" >&2;}
13839 { echo "$as_me:$LINENO: WARNING: jitprofiling.h: check for missing prerequisite headers?" >&5
13840 echo "$as_me: WARNING: jitprofiling.h: check for missing prerequisite headers?" >&2;}
13841 { echo "$as_me:$LINENO: WARNING: jitprofiling.h: see the Autoconf documentation" >&5
13842 echo "$as_me: WARNING: jitprofiling.h: see the Autoconf documentation" >&2;}
13843 { echo "$as_me:$LINENO: WARNING: jitprofiling.h: section \"Present But Cannot Be Compiled\"" >&5
13844 echo "$as_me: WARNING: jitprofiling.h: section \"Present But Cannot Be Compiled\"" >&2;}
13845 { echo "$as_me:$LINENO: WARNING: jitprofiling.h: proceeding with the preprocessor's result" >&5
13846 echo "$as_me: WARNING: jitprofiling.h: proceeding with the preprocessor's result" >&2;}
13847 { echo "$as_me:$LINENO: WARNING: jitprofiling.h: in the future, the compiler will take precedence" >&5
13848 echo "$as_me: WARNING: jitprofiling.h: in the future, the compiler will take precedence" >&2;}
13849 ( cat <<\_ASBOX
13850 ## ------------------------------------ ##
13851 ## Report this to http://llvm.org/bugs/ ##
13852 ## ------------------------------------ ##
13853 _ASBOX
13854 ) | sed "s/^/$as_me: WARNING: /" >&2
13855 ;;
13856 esac
13857 { echo "$as_me:$LINENO: checking for jitprofiling.h" >&5
13858 echo $ECHO_N "checking for jitprofiling.h... $ECHO_C" >&6; }
13859 if test "${ac_cv_header_jitprofiling_h+set}" = set; then
13860 echo $ECHO_N "(cached) $ECHO_C" >&6
13861 else
13862 ac_cv_header_jitprofiling_h=$ac_header_preproc
13863 fi
13864 { echo "$as_me:$LINENO: result: $ac_cv_header_jitprofiling_h" >&5
13865 echo "${ECHO_T}$ac_cv_header_jitprofiling_h" >&6; }
13866
13867 fi
13868 if test $ac_cv_header_jitprofiling_h = yes; then
13869 :
13870 else
13871
13872 echo "Error! Cannot find jitprofiling.h. Please check path specified in flag --with-intel-jitevents"
13873 exit -1
13874
13875 fi
13876
13877
13878
1387913597
1388013598 else
1388113599
2230722025 USE_UDIS86!$USE_UDIS86$ac_delim
2230822026 USE_OPROFILE!$USE_OPROFILE$ac_delim
2230922027 USE_INTEL_JITEVENTS!$USE_INTEL_JITEVENTS$ac_delim
22310 INTEL_JITEVENTS_INCDIR!$INTEL_JITEVENTS_INCDIR$ac_delim
22311 INTEL_JITEVENTS_LIBDIR!$INTEL_JITEVENTS_LIBDIR$ac_delim
2231222028 XML2CONFIG!$XML2CONFIG$ac_delim
2231322029 LIBXML2_LIBS!$LIBXML2_LIBS$ac_delim
2231422030 LIBXML2_INC!$LIBXML2_INC$ac_delim
2233722053 LTLIBOBJS!$LTLIBOBJS$ac_delim
2233822054 _ACEOF
2233922055
22340 if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 95; then
22056 if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 93; then
2234122057 break
2234222058 elif $ac_last_try; then
2234322059 { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
271271
272272 **LLVM_USE_INTEL_JITEVENTS**:BOOL
273273 Enable building support for Intel JIT Events API. Defaults to OFF
274
275 **LLVM_INTEL_JITEVENTS_DIR**:PATH
276 Path to installation of Intel(R) VTune(TM) Amplifier XE 2011, used to locate
277 the ``jitprofiling`` library. Default = ``%VTUNE_AMPLIFIER_XE_2011_DIR%``
278 (Windows) | ``/opt/intel/vtune_amplifier_xe_2011`` (Linux)
279274
280275 Executing the test suite
281276 ========================
+0
-102
include/llvm/ExecutionEngine/IntelJITEventsWrapper.h less more
None //===-- IntelJITEventsWrapper.h - Intel JIT Events API Wrapper --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a wrapper for the Intel JIT Events API. It allows for the
10 // implementation of the jitprofiling library to be swapped with an alternative
11 // implementation (for testing). To include this file, you must have the
12 // jitprofiling.h header available; it is available in Intel(R) VTune(TM)
13 // Amplifier XE 2011.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef INTEL_JIT_EVENTS_WRAPPER_H
18 #define INTEL_JIT_EVENTS_WRAPPER_H
19
20 #include
21
22 namespace llvm {
23
24 class IntelJITEventsWrapper {
25 // Function pointer types for testing implementation of Intel jitprofiling
26 // library
27 typedef int (*NotifyEventPtr)(iJIT_JVM_EVENT, void*);
28 typedef void (*RegisterCallbackExPtr)(void *, iJIT_ModeChangedEx );
29 typedef iJIT_IsProfilingActiveFlags (*IsProfilingActivePtr)(void);
30 typedef void (*FinalizeThreadPtr)(void);
31 typedef void (*FinalizeProcessPtr)(void);
32 typedef unsigned int (*GetNewMethodIDPtr)(void);
33
34 NotifyEventPtr NotifyEventFunc;
35 RegisterCallbackExPtr RegisterCallbackExFunc;
36 IsProfilingActivePtr IsProfilingActiveFunc;
37 FinalizeThreadPtr FinalizeThreadFunc;
38 FinalizeProcessPtr FinalizeProcessFunc;
39 GetNewMethodIDPtr GetNewMethodIDFunc;
40
41 public:
42 bool isAmplifierRunning() {
43 return iJIT_IsProfilingActive() == iJIT_SAMPLING_ON;
44 }
45
46 IntelJITEventsWrapper()
47 : NotifyEventFunc(::iJIT_NotifyEvent),
48 RegisterCallbackExFunc(::iJIT_RegisterCallbackEx),
49 IsProfilingActiveFunc(::iJIT_IsProfilingActive),
50 FinalizeThreadFunc(::FinalizeThread),
51 FinalizeProcessFunc(::FinalizeProcess),
52 GetNewMethodIDFunc(::iJIT_GetNewMethodID) {
53 }
54
55 IntelJITEventsWrapper(NotifyEventPtr NotifyEventImpl,
56 RegisterCallbackExPtr RegisterCallbackExImpl,
57 IsProfilingActivePtr IsProfilingActiveImpl,
58 FinalizeThreadPtr FinalizeThreadImpl,
59 FinalizeProcessPtr FinalizeProcessImpl,
60 GetNewMethodIDPtr GetNewMethodIDImpl)
61 : NotifyEventFunc(NotifyEventImpl),
62 RegisterCallbackExFunc(RegisterCallbackExImpl),
63 IsProfilingActiveFunc(IsProfilingActiveImpl),
64 FinalizeThreadFunc(FinalizeThreadImpl),
65 FinalizeProcessFunc(FinalizeProcessImpl),
66 GetNewMethodIDFunc(GetNewMethodIDImpl) {
67 }
68
69 // Sends an event anncouncing that a function has been emitted
70 // return values are event-specific. See Intel documentation for details.
71 int iJIT_NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {
72 if (!NotifyEventFunc)
73 return -1;
74 return NotifyEventFunc(EventType, EventSpecificData);
75 }
76
77 // Registers a callback function to receive notice of profiling state changes
78 void iJIT_RegisterCallbackEx(void *UserData,
79 iJIT_ModeChangedEx NewModeCallBackFuncEx) {
80 if (RegisterCallbackExFunc)
81 RegisterCallbackExFunc(UserData, NewModeCallBackFuncEx);
82 }
83
84 // Returns the current profiler mode
85 iJIT_IsProfilingActiveFlags iJIT_IsProfilingActive(void) {
86 if (!IsProfilingActiveFunc)
87 return iJIT_NOTHING_RUNNING;
88 return IsProfilingActiveFunc();
89 }
90
91 // Generates a locally unique method ID for use in code registration
92 unsigned int iJIT_GetNewMethodID(void) {
93 if (!GetNewMethodIDFunc)
94 return -1;
95 return GetNewMethodIDFunc();
96 }
97 };
98
99 } //namespace llvm
100
101 #endif //INTEL_JIT_EVENTS_WRAPPER_H
None
1 include_directories( ${LLVM_INTEL_JITEVENTS_INCDIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. )
2
3 set(system_libs
4 ${system_libs}
5 jitprofiling
6 )
0 include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. )
71
82 add_llvm_library(LLVMIntelJITEvents
93 IntelJITEventListener.cpp
4 jitprofiling.c
105 )
2121 #include "llvm/ADT/DenseMap.h"
2222 #include "llvm/ADT/OwningPtr.h"
2323 #include "llvm/CodeGen/MachineFunction.h"
24 #include "llvm/ExecutionEngine/IntelJITEventsWrapper.h"
2524 #include "llvm/Support/Debug.h"
2625 #include "llvm/Support/raw_ostream.h"
2726 #include "llvm/Support/Errno.h"
2827 #include "llvm/Support/ValueHandle.h"
2928 #include "EventListenerCommon.h"
29 #include "IntelJITEventsWrapper.h"
3030
3131 using namespace llvm;
3232 using namespace llvm::jitprofiling;
0 //===-- IntelJITEventsWrapper.h - Intel JIT Events API Wrapper --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a wrapper for the Intel JIT Events API. It allows for the
10 // implementation of the jitprofiling library to be swapped with an alternative
11 // implementation (for testing). To include this file, you must have the
12 // jitprofiling.h header available; it is available in Intel(R) VTune(TM)
13 // Amplifier XE 2011.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef INTEL_JIT_EVENTS_WRAPPER_H
18 #define INTEL_JIT_EVENTS_WRAPPER_H
19
20 #include "jitprofiling.h"
21
22 namespace llvm {
23
24 class IntelJITEventsWrapper {
25 // Function pointer types for testing implementation of Intel jitprofiling
26 // library
27 typedef int (*NotifyEventPtr)(iJIT_JVM_EVENT, void*);
28 typedef void (*RegisterCallbackExPtr)(void *, iJIT_ModeChangedEx );
29 typedef iJIT_IsProfilingActiveFlags (*IsProfilingActivePtr)(void);
30 typedef void (*FinalizeThreadPtr)(void);
31 typedef void (*FinalizeProcessPtr)(void);
32 typedef unsigned int (*GetNewMethodIDPtr)(void);
33
34 NotifyEventPtr NotifyEventFunc;
35 RegisterCallbackExPtr RegisterCallbackExFunc;
36 IsProfilingActivePtr IsProfilingActiveFunc;
37 FinalizeThreadPtr FinalizeThreadFunc;
38 FinalizeProcessPtr FinalizeProcessFunc;
39 GetNewMethodIDPtr GetNewMethodIDFunc;
40
41 public:
42 bool isAmplifierRunning() {
43 return iJIT_IsProfilingActive() == iJIT_SAMPLING_ON;
44 }
45
46 IntelJITEventsWrapper()
47 : NotifyEventFunc(::iJIT_NotifyEvent),
48 RegisterCallbackExFunc(::iJIT_RegisterCallbackEx),
49 IsProfilingActiveFunc(::iJIT_IsProfilingActive),
50 FinalizeThreadFunc(::FinalizeThread),
51 FinalizeProcessFunc(::FinalizeProcess),
52 GetNewMethodIDFunc(::iJIT_GetNewMethodID) {
53 }
54
55 IntelJITEventsWrapper(NotifyEventPtr NotifyEventImpl,
56 RegisterCallbackExPtr RegisterCallbackExImpl,
57 IsProfilingActivePtr IsProfilingActiveImpl,
58 FinalizeThreadPtr FinalizeThreadImpl,
59 FinalizeProcessPtr FinalizeProcessImpl,
60 GetNewMethodIDPtr GetNewMethodIDImpl)
61 : NotifyEventFunc(NotifyEventImpl),
62 RegisterCallbackExFunc(RegisterCallbackExImpl),
63 IsProfilingActiveFunc(IsProfilingActiveImpl),
64 FinalizeThreadFunc(FinalizeThreadImpl),
65 FinalizeProcessFunc(FinalizeProcessImpl),
66 GetNewMethodIDFunc(GetNewMethodIDImpl) {
67 }
68
69 // Sends an event anncouncing that a function has been emitted
70 // return values are event-specific. See Intel documentation for details.
71 int iJIT_NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {
72 if (!NotifyEventFunc)
73 return -1;
74 return NotifyEventFunc(EventType, EventSpecificData);
75 }
76
77 // Registers a callback function to receive notice of profiling state changes
78 void iJIT_RegisterCallbackEx(void *UserData,
79 iJIT_ModeChangedEx NewModeCallBackFuncEx) {
80 if (RegisterCallbackExFunc)
81 RegisterCallbackExFunc(UserData, NewModeCallBackFuncEx);
82 }
83
84 // Returns the current profiler mode
85 iJIT_IsProfilingActiveFlags iJIT_IsProfilingActive(void) {
86 if (!IsProfilingActiveFunc)
87 return iJIT_NOTHING_RUNNING;
88 return IsProfilingActiveFunc();
89 }
90
91 // Generates a locally unique method ID for use in code registration
92 unsigned int iJIT_GetNewMethodID(void) {
93 if (!GetNewMethodIDFunc)
94 return -1;
95 return GetNewMethodIDFunc();
96 }
97 };
98
99 } //namespace llvm
100
101 #endif //INTEL_JIT_EVENTS_WRAPPER_H
1010
1111 include $(LEVEL)/Makefile.config
1212
13 SOURCES := IntelJITEventListener.cpp
14 CPPFLAGS += -I$(INTEL_JITEVENTS_INCDIR) -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
13 SOURCES := IntelJITEventListener.cpp \
14 jitprofiling.c
15 CPPFLAGS += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
1516
1617 include $(LLVM_SRC_ROOT)/Makefile.rules
0 /*===-- ittnotify_config.h - JIT Profiling API internal config-----*- C -*-===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file is distributed under the University of Illinois Open Source
5 * License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===*
8 *
9 * This file provides Intel(R) Performance Analyzer JIT (Just-In-Time)
10 * Profiling API internal config.
11 *
12 *===----------------------------------------------------------------------===*/
13 #ifndef _ITTNOTIFY_CONFIG_H_
14 #define _ITTNOTIFY_CONFIG_H_
15
16 /** @cond exclude_from_documentation */
17 #ifndef ITT_OS_WIN
18 # define ITT_OS_WIN 1
19 #endif /* ITT_OS_WIN */
20
21 #ifndef ITT_OS_LINUX
22 # define ITT_OS_LINUX 2
23 #endif /* ITT_OS_LINUX */
24
25 #ifndef ITT_OS_MAC
26 # define ITT_OS_MAC 3
27 #endif /* ITT_OS_MAC */
28
29 #ifndef ITT_OS
30 # if defined WIN32 || defined _WIN32
31 # define ITT_OS ITT_OS_WIN
32 # elif defined( __APPLE__ ) && defined( __MACH__ )
33 # define ITT_OS ITT_OS_MAC
34 # else
35 # define ITT_OS ITT_OS_LINUX
36 # endif
37 #endif /* ITT_OS */
38
39 #ifndef ITT_PLATFORM_WIN
40 # define ITT_PLATFORM_WIN 1
41 #endif /* ITT_PLATFORM_WIN */
42
43 #ifndef ITT_PLATFORM_POSIX
44 # define ITT_PLATFORM_POSIX 2
45 #endif /* ITT_PLATFORM_POSIX */
46
47 #ifndef ITT_PLATFORM
48 # if ITT_OS==ITT_OS_WIN
49 # define ITT_PLATFORM ITT_PLATFORM_WIN
50 # else
51 # define ITT_PLATFORM ITT_PLATFORM_POSIX
52 # endif /* _WIN32 */
53 #endif /* ITT_PLATFORM */
54
55 #if defined(_UNICODE) && !defined(UNICODE)
56 #define UNICODE
57 #endif
58
59 #include
60 #if ITT_PLATFORM==ITT_PLATFORM_WIN
61 #include
62 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
63 #include
64 #if defined(UNICODE) || defined(_UNICODE)
65 #include
66 #endif /* UNICODE || _UNICODE */
67 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
68
69 #ifndef CDECL
70 # if ITT_PLATFORM==ITT_PLATFORM_WIN
71 # define CDECL __cdecl
72 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
73 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
74 # define CDECL /* not actual on x86_64 platform */
75 # else /* _M_X64 || _M_AMD64 || __x86_64__ */
76 # define CDECL __attribute__ ((cdecl))
77 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
78 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
79 #endif /* CDECL */
80
81 #ifndef STDCALL
82 # if ITT_PLATFORM==ITT_PLATFORM_WIN
83 # define STDCALL __stdcall
84 # else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
85 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
86 # define STDCALL /* not supported on x86_64 platform */
87 # else /* _M_X64 || _M_AMD64 || __x86_64__ */
88 # define STDCALL __attribute__ ((stdcall))
89 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
90 # endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
91 #endif /* STDCALL */
92
93 #define ITTAPI CDECL
94 #define LIBITTAPI CDECL
95
96 /* TODO: Temporary for compatibility! */
97 #define ITTAPI_CALL CDECL
98 #define LIBITTAPI_CALL CDECL
99
100 #if ITT_PLATFORM==ITT_PLATFORM_WIN
101 /* use __forceinline (VC++ specific) */
102 #define ITT_INLINE __forceinline
103 #define ITT_INLINE_ATTRIBUTE /* nothing */
104 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
105 /*
106 * Generally, functions are not inlined unless optimization is specified.
107 * For functions declared inline, this attribute inlines the function even
108 * if no optimization level was specified.
109 */
110 #ifdef __STRICT_ANSI__
111 #define ITT_INLINE static
112 #else /* __STRICT_ANSI__ */
113 #define ITT_INLINE static inline
114 #endif /* __STRICT_ANSI__ */
115 #define ITT_INLINE_ATTRIBUTE __attribute__ ((always_inline))
116 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
117 /** @endcond */
118
119 #ifndef ITT_ARCH_IA32
120 # define ITT_ARCH_IA32 1
121 #endif /* ITT_ARCH_IA32 */
122
123 #ifndef ITT_ARCH_IA32E
124 # define ITT_ARCH_IA32E 2
125 #endif /* ITT_ARCH_IA32E */
126
127 #ifndef ITT_ARCH_IA64
128 # define ITT_ARCH_IA64 3
129 #endif /* ITT_ARCH_IA64 */
130
131 #ifndef ITT_ARCH
132 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
133 # define ITT_ARCH ITT_ARCH_IA32E
134 # elif defined _M_IA64 || defined __ia64
135 # define ITT_ARCH ITT_ARCH_IA64
136 # else
137 # define ITT_ARCH ITT_ARCH_IA32
138 # endif
139 #endif
140
141 #ifdef __cplusplus
142 # define ITT_EXTERN_C extern "C"
143 #else
144 # define ITT_EXTERN_C /* nothing */
145 #endif /* __cplusplus */
146
147 #define ITT_TO_STR_AUX(x) #x
148 #define ITT_TO_STR(x) ITT_TO_STR_AUX(x)
149
150 #define __ITT_BUILD_ASSERT(expr, suffix) do { \
151 static char __itt_build_check_##suffix[(expr) ? 1 : -1]; \
152 __itt_build_check_##suffix[0] = 0; \
153 } while(0)
154 #define _ITT_BUILD_ASSERT(expr, suffix) __ITT_BUILD_ASSERT((expr), suffix)
155 #define ITT_BUILD_ASSERT(expr) _ITT_BUILD_ASSERT((expr), __LINE__)
156
157 #define ITT_MAGIC { 0xED, 0xAB, 0xAB, 0xEC, 0x0D, 0xEE, 0xDA, 0x30 }
158
159 /* Replace with snapshot date YYYYMMDD for promotion build. */
160 #define API_VERSION_BUILD 20111111
161
162 #ifndef API_VERSION_NUM
163 #define API_VERSION_NUM 0.0.0
164 #endif /* API_VERSION_NUM */
165
166 #define API_VERSION "ITT-API-Version " ITT_TO_STR(API_VERSION_NUM) \
167 " (" ITT_TO_STR(API_VERSION_BUILD) ")"
168
169 /* OS communication functions */
170 #if ITT_PLATFORM==ITT_PLATFORM_WIN
171 #include
172 typedef HMODULE lib_t;
173 typedef DWORD TIDT;
174 typedef CRITICAL_SECTION mutex_t;
175 #define MUTEX_INITIALIZER { 0 }
176 #define strong_alias(name, aliasname) /* empty for Windows */
177 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
178 #include
179 #if defined(UNICODE) || defined(_UNICODE)
180 #include
181 #endif /* UNICODE */
182 #ifndef _GNU_SOURCE
183 #define _GNU_SOURCE 1 /* need for PTHREAD_MUTEX_RECURSIVE */
184 #endif /* _GNU_SOURCE */
185 #include
186 typedef void* lib_t;
187 typedef pthread_t TIDT;
188 typedef pthread_mutex_t mutex_t;
189 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
190 #define _strong_alias(name, aliasname) \
191 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
192 #define strong_alias(name, aliasname) _strong_alias(name, aliasname)
193 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
194
195 #if ITT_PLATFORM==ITT_PLATFORM_WIN
196 #define __itt_get_proc(lib, name) GetProcAddress(lib, name)
197 #define __itt_mutex_init(mutex) InitializeCriticalSection(mutex)
198 #define __itt_mutex_lock(mutex) EnterCriticalSection(mutex)
199 #define __itt_mutex_unlock(mutex) LeaveCriticalSection(mutex)
200 #define __itt_load_lib(name) LoadLibraryA(name)
201 #define __itt_unload_lib(handle) FreeLibrary(handle)
202 #define __itt_system_error() (int)GetLastError()
203 #define __itt_fstrcmp(s1, s2) lstrcmpA(s1, s2)
204 #define __itt_fstrlen(s) lstrlenA(s)
205 #define __itt_fstrcpyn(s1, s2, l) lstrcpynA(s1, s2, l)
206 #define __itt_fstrdup(s) _strdup(s)
207 #define __itt_thread_id() GetCurrentThreadId()
208 #define __itt_thread_yield() SwitchToThread()
209 #ifndef ITT_SIMPLE_INIT
210 ITT_INLINE long
211 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
212 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
213 {
214 return InterlockedIncrement(ptr);
215 }
216 #endif /* ITT_SIMPLE_INIT */
217 #else /* ITT_PLATFORM!=ITT_PLATFORM_WIN */
218 #define __itt_get_proc(lib, name) dlsym(lib, name)
219 #define __itt_mutex_init(mutex) {\
220 pthread_mutexattr_t mutex_attr; \
221 int error_code = pthread_mutexattr_init(&mutex_attr); \
222 if (error_code) \
223 __itt_report_error(__itt_error_system, "pthread_mutexattr_init", \
224 error_code); \
225 error_code = pthread_mutexattr_settype(&mutex_attr, \
226 PTHREAD_MUTEX_RECURSIVE); \
227 if (error_code) \
228 __itt_report_error(__itt_error_system, "pthread_mutexattr_settype", \
229 error_code); \
230 error_code = pthread_mutex_init(mutex, &mutex_attr); \
231 if (error_code) \
232 __itt_report_error(__itt_error_system, "pthread_mutex_init", \
233 error_code); \
234 error_code = pthread_mutexattr_destroy(&mutex_attr); \
235 if (error_code) \
236 __itt_report_error(__itt_error_system, "pthread_mutexattr_destroy", \
237 error_code); \
238 }
239 #define __itt_mutex_lock(mutex) pthread_mutex_lock(mutex)
240 #define __itt_mutex_unlock(mutex) pthread_mutex_unlock(mutex)
241 #define __itt_load_lib(name) dlopen(name, RTLD_LAZY)
242 #define __itt_unload_lib(handle) dlclose(handle)
243 #define __itt_system_error() errno
244 #define __itt_fstrcmp(s1, s2) strcmp(s1, s2)
245 #define __itt_fstrlen(s) strlen(s)
246 #define __itt_fstrcpyn(s1, s2, l) strncpy(s1, s2, l)
247 #define __itt_fstrdup(s) strdup(s)
248 #define __itt_thread_id() pthread_self()
249 #define __itt_thread_yield() sched_yield()
250 #if ITT_ARCH==ITT_ARCH_IA64
251 #ifdef __INTEL_COMPILER
252 #define __TBB_machine_fetchadd4(addr, val) __fetchadd4_acq((void *)addr, val)
253 #else /* __INTEL_COMPILER */
254 /* TODO: Add Support for not Intel compilers for IA64 */
255 #endif /* __INTEL_COMPILER */
256 #else /* ITT_ARCH!=ITT_ARCH_IA64 */
257 ITT_INLINE long
258 __TBB_machine_fetchadd4(volatile void* ptr, long addend) ITT_INLINE_ATTRIBUTE;
259 ITT_INLINE long __TBB_machine_fetchadd4(volatile void* ptr, long addend)
260 {
261 long result;
262 __asm__ __volatile__("lock\nxadd %0,%1"
263 : "=r"(result),"=m"(*(long*)ptr)
264 : "0"(addend), "m"(*(long*)ptr)
265 : "memory");
266 return result;
267 }
268 #endif /* ITT_ARCH==ITT_ARCH_IA64 */
269 #ifndef ITT_SIMPLE_INIT
270 ITT_INLINE long
271 __itt_interlocked_increment(volatile long* ptr) ITT_INLINE_ATTRIBUTE;
272 ITT_INLINE long __itt_interlocked_increment(volatile long* ptr)
273 {
274 return __TBB_machine_fetchadd4(ptr, 1) + 1L;
275 }
276 #endif /* ITT_SIMPLE_INIT */
277 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
278
279 typedef enum {
280 __itt_collection_normal = 0,
281 __itt_collection_paused = 1
282 } __itt_collection_state;
283
284 typedef enum {
285 __itt_thread_normal = 0,
286 __itt_thread_ignored = 1
287 } __itt_thread_state;
288
289 #pragma pack(push, 8)
290
291 typedef struct ___itt_thread_info
292 {
293 const char* nameA; /*!< Copy of original name in ASCII. */
294 #if defined(UNICODE) || defined(_UNICODE)
295 const wchar_t* nameW; /*!< Copy of original name in UNICODE. */
296 #else /* UNICODE || _UNICODE */
297 void* nameW;
298 #endif /* UNICODE || _UNICODE */
299 TIDT tid;
300 __itt_thread_state state; /*!< Thread state (paused or normal) */
301 int extra1; /*!< Reserved to the runtime */
302 void* extra2; /*!< Reserved to the runtime */
303 struct ___itt_thread_info* next;
304 } __itt_thread_info;
305
306 #include "ittnotify_types.h" /* For __itt_group_id definition */
307
308 typedef struct ___itt_api_info_20101001
309 {
310 const char* name;
311 void** func_ptr;
312 void* init_func;
313 __itt_group_id group;
314 } __itt_api_info_20101001;
315
316 typedef struct ___itt_api_info
317 {
318 const char* name;
319 void** func_ptr;
320 void* init_func;
321 void* null_func;
322 __itt_group_id group;
323 } __itt_api_info;
324
325 struct ___itt_domain;
326 struct ___itt_string_handle;
327
328 typedef struct ___itt_global
329 {
330 unsigned char magic[8];
331 unsigned long version_major;
332 unsigned long version_minor;
333 unsigned long version_build;
334 volatile long api_initialized;
335 volatile long mutex_initialized;
336 volatile long atomic_counter;
337 mutex_t mutex;
338 lib_t lib;
339 void* error_handler;
340 const char** dll_path_ptr;
341 __itt_api_info* api_list_ptr;
342 struct ___itt_global* next;
343 /* Joinable structures below */
344 __itt_thread_info* thread_list;
345 struct ___itt_domain* domain_list;
346 struct ___itt_string_handle* string_list;
347 __itt_collection_state state;
348 } __itt_global;
349
350 #pragma pack(pop)
351
352 #define NEW_THREAD_INFO_W(gptr,h,h_tail,t,s,n) { \
353 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
354 if (h != NULL) { \
355 h->tid = t; \
356 h->nameA = NULL; \
357 h->nameW = n ? _wcsdup(n) : NULL; \
358 h->state = s; \
359 h->extra1 = 0; /* reserved */ \
360 h->extra2 = NULL; /* reserved */ \
361 h->next = NULL; \
362 if (h_tail == NULL) \
363 (gptr)->thread_list = h; \
364 else \
365 h_tail->next = h; \
366 } \
367 }
368
369 #define NEW_THREAD_INFO_A(gptr,h,h_tail,t,s,n) { \
370 h = (__itt_thread_info*)malloc(sizeof(__itt_thread_info)); \
371 if (h != NULL) { \
372 h->tid = t; \
373 h->nameA = n ? __itt_fstrdup(n) : NULL; \
374 h->nameW = NULL; \
375 h->state = s; \
376 h->extra1 = 0; /* reserved */ \
377 h->extra2 = NULL; /* reserved */ \
378 h->next = NULL; \
379 if (h_tail == NULL) \
380 (gptr)->thread_list = h; \
381 else \
382 h_tail->next = h; \
383 } \
384 }
385
386 #define NEW_DOMAIN_W(gptr,h,h_tail,name) { \
387 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
388 if (h != NULL) { \
389 h->flags = 0; /* domain is disabled by default */ \
390 h->nameA = NULL; \
391 h->nameW = name ? _wcsdup(name) : NULL; \
392 h->extra1 = 0; /* reserved */ \
393 h->extra2 = NULL; /* reserved */ \
394 h->next = NULL; \
395 if (h_tail == NULL) \
396 (gptr)->domain_list = h; \
397 else \
398 h_tail->next = h; \
399 } \
400 }
401
402 #define NEW_DOMAIN_A(gptr,h,h_tail,name) { \
403 h = (__itt_domain*)malloc(sizeof(__itt_domain)); \
404 if (h != NULL) { \
405 h->flags = 0; /* domain is disabled by default */ \
406 h->nameA = name ? __itt_fstrdup(name) : NULL; \
407 h->nameW = NULL; \
408 h->extra1 = 0; /* reserved */ \
409 h->extra2 = NULL; /* reserved */ \
410 h->next = NULL; \
411 if (h_tail == NULL) \
412 (gptr)->domain_list = h; \
413 else \
414 h_tail->next = h; \
415 } \
416 }
417
418 #define NEW_STRING_HANDLE_W(gptr,h,h_tail,name) { \
419 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
420 if (h != NULL) { \
421 h->strA = NULL; \
422 h->strW = name ? _wcsdup(name) : NULL; \
423 h->extra1 = 0; /* reserved */ \
424 h->extra2 = NULL; /* reserved */ \
425 h->next = NULL; \
426 if (h_tail == NULL) \
427 (gptr)->string_list = h; \
428 else \
429 h_tail->next = h; \
430 } \
431 }
432
433 #define NEW_STRING_HANDLE_A(gptr,h,h_tail,name) { \
434 h = (__itt_string_handle*)malloc(sizeof(__itt_string_handle)); \
435 if (h != NULL) { \
436 h->strA = name ? __itt_fstrdup(name) : NULL; \
437 h->strW = NULL; \
438 h->extra1 = 0; /* reserved */ \
439 h->extra2 = NULL; /* reserved */ \
440 h->next = NULL; \
441 if (h_tail == NULL) \
442 (gptr)->string_list = h; \
443 else \
444 h_tail->next = h; \
445 } \
446 }
447
448 #endif /* _ITTNOTIFY_CONFIG_H_ */
0 //===-- ittnotify_types.h - Intel(R) Performance Analyzer JIT (Just-In-Time) Profiling API internal types. ---------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef _ITTNOTIFY_TYPES_H_
9 #define _ITTNOTIFY_TYPES_H_
10
11 typedef enum ___itt_group_id
12 {
13 __itt_group_none = 0,
14 __itt_group_legacy = 1<<0,
15 __itt_group_control = 1<<1,
16 __itt_group_thread = 1<<2,
17 __itt_group_mark = 1<<3,
18 __itt_group_sync = 1<<4,
19 __itt_group_fsync = 1<<5,
20 __itt_group_jit = 1<<6,
21 __itt_group_model = 1<<7,
22 __itt_group_splitter_min = 1<<7,
23 __itt_group_counter = 1<<8,
24 __itt_group_frame = 1<<9,
25 __itt_group_stitch = 1<<10,
26 __itt_group_heap = 1<<11,
27 __itt_group_splitter_max = 1<<12,
28 __itt_group_structure = 1<<12,
29 __itt_group_suppress = 1<<13,
30 __itt_group_all = -1
31 } __itt_group_id;
32
33 #pragma pack(push, 8)
34
35 typedef struct ___itt_group_list
36 {
37 __itt_group_id id;
38 const char* name;
39 } __itt_group_list;
40
41 #pragma pack(pop)
42
43 #define ITT_GROUP_LIST(varname) \
44 static __itt_group_list varname[] = { \
45 { __itt_group_all, "all" }, \
46 { __itt_group_control, "control" }, \
47 { __itt_group_thread, "thread" }, \
48 { __itt_group_mark, "mark" }, \
49 { __itt_group_sync, "sync" }, \
50 { __itt_group_fsync, "fsync" }, \
51 { __itt_group_jit, "jit" }, \
52 { __itt_group_model, "model" }, \
53 { __itt_group_counter, "counter" }, \
54 { __itt_group_frame, "frame" }, \
55 { __itt_group_stitch, "stitch" }, \
56 { __itt_group_heap, "heap" }, \
57 { __itt_group_structure, "structure" }, \
58 { __itt_group_suppress, "suppress" }, \
59 { __itt_group_none, NULL } \
60 }
61
62 #endif /* _ITTNOTIFY_TYPES_H_ */
0 /*===-- jitprofiling.c - JIT (Just-In-Time) Profiling API----------*- C -*-===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file is distributed under the University of Illinois Open Source
5 * License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===*
8 *
9 * This file provides Intel(R) Performance Analyzer JIT (Just-In-Time)
10 * Profiling API implementation.
11 *
12 *===----------------------------------------------------------------------===*/
13 #include "ittnotify_config.h"
14
15 #if ITT_PLATFORM==ITT_PLATFORM_WIN
16 #include
17 #pragma optimize("", off)
18 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
19 #include
20 #include
21 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
22 #include
23 #include
24
25 #include "jitprofiling.h"
26
27 static const char rcsid[] = "\n@(#) $Revision: 243501 $\n";
28
29 #define DLL_ENVIRONMENT_VAR "VS_PROFILER"
30
31 #ifndef NEW_DLL_ENVIRONMENT_VAR
32 #if ITT_ARCH==ITT_ARCH_IA32
33 #define NEW_DLL_ENVIRONMENT_VAR "INTEL_JIT_PROFILER32"
34 #else
35 #define NEW_DLL_ENVIRONMENT_VAR "INTEL_JIT_PROFILER64"
36 #endif
37 #endif /* NEW_DLL_ENVIRONMENT_VAR */
38
39 #if ITT_PLATFORM==ITT_PLATFORM_WIN
40 #define DEFAULT_DLLNAME "JitPI.dll"
41 HINSTANCE m_libHandle = NULL;
42 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
43 #define DEFAULT_DLLNAME "libJitPI.so"
44 void* m_libHandle = NULL;
45 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
46
47 /* default location of JIT profiling agent on Android */
48 #define ANDROID_JIT_AGENT_PATH "/data/intel/libittnotify.so"
49
50 /* the function pointers */
51 typedef unsigned int(*TPInitialize)(void);
52 static TPInitialize FUNC_Initialize=NULL;
53
54 typedef unsigned int(*TPNotify)(unsigned int, void*);
55 static TPNotify FUNC_NotifyEvent=NULL;
56
57 static iJIT_IsProfilingActiveFlags executionMode = iJIT_NOTHING_RUNNING;
58
59 /* end collector dll part. */
60
61 /* loadiJIT_Funcs() : this function is called just in the beginning
62 * and is responsible to load the functions from BistroJavaCollector.dll
63 * result:
64 * on success: the functions loads, iJIT_DLL_is_missing=0, return value = 1
65 * on failure: the functions are NULL, iJIT_DLL_is_missing=1, return value = 0
66 */
67 static int loadiJIT_Funcs(void);
68
69 /* global representing whether the BistroJavaCollector can't be loaded */
70 static int iJIT_DLL_is_missing = 0;
71
72 /* Virtual stack - the struct is used as a virtual stack for each thread.
73 * Every thread initializes with a stack of size INIT_TOP_STACK.
74 * Every method entry decreases from the current stack point,
75 * and when a thread stack reaches its top of stack (return from the global
76 * function), the top of stack and the current stack increase. Notice that
77 * when returning from a function the stack pointer is the address of
78 * the function return.
79 */
80 #if ITT_PLATFORM==ITT_PLATFORM_WIN
81 static DWORD threadLocalStorageHandle = 0;
82 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
83 static pthread_key_t threadLocalStorageHandle = (pthread_key_t)0;
84 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
85
86 #define INIT_TOP_Stack 10000
87
88 typedef struct
89 {
90 unsigned int TopStack;
91 unsigned int CurrentStack;
92 } ThreadStack, *pThreadStack;
93
94 /* end of virtual stack. */
95
96 /*
97 * The function for reporting virtual-machine related events to VTune.
98 * Note: when reporting iJVM_EVENT_TYPE_ENTER_NIDS, there is no need to fill
99 * in the stack_id field in the iJIT_Method_NIDS structure, as VTune fills it.
100 * The return value in iJVM_EVENT_TYPE_ENTER_NIDS &&
101 * iJVM_EVENT_TYPE_LEAVE_NIDS events will be 0 in case of failure.
102 * in iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED event
103 * it will be -1 if EventSpecificData == 0 otherwise it will be 0.
104 */
105
106 ITT_EXTERN_C int JITAPI
107 iJIT_NotifyEvent(iJIT_JVM_EVENT event_type, void *EventSpecificData)
108 {
109 int ReturnValue;
110
111 /*
112 * This section is for debugging outside of VTune.
113 * It creates the environment variables that indicates call graph mode.
114 * If running outside of VTune remove the remark.
115 *
116 *
117 * static int firstTime = 1;
118 * char DoCallGraph[12] = "DoCallGraph";
119 * if (firstTime)
120 * {
121 * firstTime = 0;
122 * SetEnvironmentVariable( "BISTRO_COLLECTORS_DO_CALLGRAPH", DoCallGraph);
123 * }
124 *
125 * end of section.
126 */
127
128 /* initialization part - the functions have not been loaded yet. This part
129 * will load the functions, and check if we are in Call Graph mode.
130 * (for special treatment).
131 */
132 if (!FUNC_NotifyEvent)
133 {
134 if (iJIT_DLL_is_missing)
135 return 0;
136
137 /* load the Function from the DLL */
138 if (!loadiJIT_Funcs())
139 return 0;
140
141 /* Call Graph initialization. */
142 }
143
144 /* If the event is method entry/exit, check that in the current mode
145 * VTune is allowed to receive it
146 */
147 if ((event_type == iJVM_EVENT_TYPE_ENTER_NIDS ||
148 event_type == iJVM_EVENT_TYPE_LEAVE_NIDS) &&
149 (executionMode != iJIT_CALLGRAPH_ON))
150 {
151 return 0;
152 }
153 /* This section is performed when method enter event occurs.
154 * It updates the virtual stack, or creates it if this is the first
155 * method entry in the thread. The stack pointer is decreased.
156 */
157 if (event_type == iJVM_EVENT_TYPE_ENTER_NIDS)
158 {
159 #if ITT_PLATFORM==ITT_PLATFORM_WIN
160 pThreadStack threadStack =
161 (pThreadStack)TlsGetValue (threadLocalStorageHandle);
162 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
163 pThreadStack threadStack =
164 (pThreadStack)pthread_getspecific(threadLocalStorageHandle);
165 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
166
167 /* check for use of reserved method IDs */
168 if ( ((piJIT_Method_NIDS) EventSpecificData)->method_id <= 999 )
169 return 0;
170
171 if (!threadStack)
172 {
173 /* initialize the stack. */
174 threadStack = (pThreadStack) calloc (sizeof(ThreadStack), 1);
175 threadStack->TopStack = INIT_TOP_Stack;
176 threadStack->CurrentStack = INIT_TOP_Stack;
177 #if ITT_PLATFORM==ITT_PLATFORM_WIN
178 TlsSetValue(threadLocalStorageHandle,(void*)threadStack);
179 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
180 pthread_setspecific(threadLocalStorageHandle,(void*)threadStack);
181 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
182 }
183
184 /* decrease the stack. */
185 ((piJIT_Method_NIDS) EventSpecificData)->stack_id =
186 (threadStack->CurrentStack)--;
187 }
188
189 /* This section is performed when method leave event occurs
190 * It updates the virtual stack.
191 * Increases the stack pointer.
192 * If the stack pointer reached the top (left the global function)
193 * increase the pointer and the top pointer.
194 */
195 if (event_type == iJVM_EVENT_TYPE_LEAVE_NIDS)
196 {
197 #if ITT_PLATFORM==ITT_PLATFORM_WIN
198 pThreadStack threadStack =
199 (pThreadStack)TlsGetValue (threadLocalStorageHandle);
200 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
201 pThreadStack threadStack =
202 (pThreadStack)pthread_getspecific(threadLocalStorageHandle);
203 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
204
205 /* check for use of reserved method IDs */
206 if ( ((piJIT_Method_NIDS) EventSpecificData)->method_id <= 999 )
207 return 0;
208
209 if (!threadStack)
210 {
211 /* Error: first report in this thread is method exit */
212 exit (1);
213 }
214
215 ((piJIT_Method_NIDS) EventSpecificData)->stack_id =
216 ++(threadStack->CurrentStack) + 1;
217
218 if (((piJIT_Method_NIDS) EventSpecificData)->stack_id
219 > threadStack->TopStack)
220 ((piJIT_Method_NIDS) EventSpecificData)->stack_id =
221 (unsigned int)-1;
222 }
223
224 if (event_type == iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED)
225 {
226 /* check for use of reserved method IDs */
227 if ( ((piJIT_Method_Load) EventSpecificData)->method_id <= 999 )
228 return 0;
229 }
230
231 ReturnValue = (int)FUNC_NotifyEvent(event_type, EventSpecificData);
232
233 return ReturnValue;
234 }
235
236 /* The new mode call back routine */
237 ITT_EXTERN_C void JITAPI
238 iJIT_RegisterCallbackEx(void *userdata, iJIT_ModeChangedEx
239 NewModeCallBackFuncEx)
240 {
241 /* is it already missing... or the load of functions from the DLL failed */
242 if (iJIT_DLL_is_missing || !loadiJIT_Funcs())
243 {
244 /* then do not bother with notifications */
245 NewModeCallBackFuncEx(userdata, iJIT_NO_NOTIFICATIONS);
246 /* Error: could not load JIT functions. */
247 return;
248 }
249 /* nothing to do with the callback */
250 }
251
252 /*
253 * This function allows the user to query in which mode, if at all,
254 *VTune is running
255 */
256 ITT_EXTERN_C iJIT_IsProfilingActiveFlags JITAPI iJIT_IsProfilingActive()
257 {
258 if (!iJIT_DLL_is_missing)
259 {
260 loadiJIT_Funcs();
261 }
262
263 return executionMode;
264 }
265
266 /* this function loads the collector dll (BistroJavaCollector)
267 * and the relevant functions.
268 * on success: all functions load, iJIT_DLL_is_missing = 0, return value = 1
269 * on failure: all functions are NULL, iJIT_DLL_is_missing = 1, return value = 0
270 */
271 static int loadiJIT_Funcs()
272 {
273 static int bDllWasLoaded = 0;
274 char *dllName = (char*)rcsid; /* !! Just to avoid unused code elimination */
275 #if ITT_PLATFORM==ITT_PLATFORM_WIN
276 DWORD dNameLength = 0;
277 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
278
279 if(bDllWasLoaded)
280 {
281 /* dll was already loaded, no need to do it for the second time */
282 return 1;
283 }
284
285 /* Assumes that the DLL will not be found */
286 iJIT_DLL_is_missing = 1;
287 FUNC_NotifyEvent = NULL;
288
289 if (m_libHandle)
290 {
291 #if ITT_PLATFORM==ITT_PLATFORM_WIN
292 FreeLibrary(m_libHandle);
293 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
294 dlclose(m_libHandle);
295 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
296 m_libHandle = NULL;
297 }
298
299 /* Try to get the dll name from the environment */
300 #if ITT_PLATFORM==ITT_PLATFORM_WIN
301 dNameLength = GetEnvironmentVariableA(NEW_DLL_ENVIRONMENT_VAR, NULL, 0);
302 if (dNameLength)
303 {
304 DWORD envret = 0;
305 dllName = (char*)malloc(sizeof(char) * (dNameLength + 1));
306 envret = GetEnvironmentVariableA(NEW_DLL_ENVIRONMENT_VAR,
307 dllName, dNameLength);
308 if (envret)
309 {
310 /* Try to load the dll from the PATH... */
311 m_libHandle = LoadLibraryExA(dllName,
312 NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
313 }
314 free(dllName);
315 } else {
316 /* Try to use old VS_PROFILER variable */
317 dNameLength = GetEnvironmentVariableA(DLL_ENVIRONMENT_VAR, NULL, 0);
318 if (dNameLength)
319 {
320 DWORD envret = 0;
321 dllName = (char*)malloc(sizeof(char) * (dNameLength + 1));
322 envret = GetEnvironmentVariableA(DLL_ENVIRONMENT_VAR,
323 dllName, dNameLength);
324 if (envret)
325 {
326 /* Try to load the dll from the PATH... */
327 m_libHandle = LoadLibraryA(dllName);
328 }
329 free(dllName);
330 }
331 }
332 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
333 dllName = getenv(NEW_DLL_ENVIRONMENT_VAR);
334 if (!dllName)
335 dllName = getenv(DLL_ENVIRONMENT_VAR);
336 #ifdef ANDROID
337 if (!dllName)
338 dllName = ANDROID_JIT_AGENT_PATH;
339 #endif
340 if (dllName)
341 {
342 /* Try to load the dll from the PATH... */
343 m_libHandle = dlopen(dllName, RTLD_LAZY);
344 }
345 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
346
347 if (!m_libHandle)
348 {
349 #if ITT_PLATFORM==ITT_PLATFORM_WIN
350 m_libHandle = LoadLibraryA(DEFAULT_DLLNAME);
351 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
352 m_libHandle = dlopen(DEFAULT_DLLNAME, RTLD_LAZY);
353 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
354 }
355
356 /* if the dll wasn't loaded - exit. */
357 if (!m_libHandle)
358 {
359 iJIT_DLL_is_missing = 1; /* don't try to initialize
360 * JIT agent the second time
361 */
362 return 0;
363 }
364
365 #if ITT_PLATFORM==ITT_PLATFORM_WIN
366 FUNC_NotifyEvent = (TPNotify)GetProcAddress(m_libHandle, "NotifyEvent");
367 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
368 FUNC_NotifyEvent = (TPNotify)dlsym(m_libHandle, "NotifyEvent");
369 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
370 if (!FUNC_NotifyEvent)
371 {
372 FUNC_Initialize = NULL;
373 return 0;
374 }
375
376 #if ITT_PLATFORM==ITT_PLATFORM_WIN
377 FUNC_Initialize = (TPInitialize)GetProcAddress(m_libHandle, "Initialize");
378 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
379 FUNC_Initialize = (TPInitialize)dlsym(m_libHandle, "Initialize");
380 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
381 if (!FUNC_Initialize)
382 {
383 FUNC_NotifyEvent = NULL;
384 return 0;
385 }
386
387 executionMode = (iJIT_IsProfilingActiveFlags)FUNC_Initialize();
388
389 bDllWasLoaded = 1;
390 iJIT_DLL_is_missing = 0; /* DLL is ok. */
391
392 /*
393 * Call Graph mode: init the thread local storage
394 * (need to store the virtual stack there).
395 */
396 if ( executionMode == iJIT_CALLGRAPH_ON )
397 {
398 /* Allocate a thread local storage slot for the thread "stack" */
399 if (!threadLocalStorageHandle)
400 #if ITT_PLATFORM==ITT_PLATFORM_WIN
401 threadLocalStorageHandle = TlsAlloc();
402 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
403 pthread_key_create(&threadLocalStorageHandle, NULL);
404 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
405 }
406
407 return 1;
408 }
409
410 /*
411 * This function should be called by the user whenever a thread ends,
412 * to free the thread "virtual stack" storage
413 */
414 ITT_EXTERN_C void JITAPI FinalizeThread()
415 {
416 if (threadLocalStorageHandle)
417 {
418 #if ITT_PLATFORM==ITT_PLATFORM_WIN
419 pThreadStack threadStack =
420 (pThreadStack)TlsGetValue (threadLocalStorageHandle);
421 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
422 pThreadStack threadStack =
423 (pThreadStack)pthread_getspecific(threadLocalStorageHandle);
424 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
425 if (threadStack)
426 {
427 free (threadStack);
428 threadStack = NULL;
429 #if ITT_PLATFORM==ITT_PLATFORM_WIN
430 TlsSetValue (threadLocalStorageHandle, threadStack);
431 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
432 pthread_setspecific(threadLocalStorageHandle, threadStack);
433 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
434 }
435 }
436 }
437
438 /*
439 * This function should be called by the user when the process ends,
440 * to free the local storage index
441 */
442 ITT_EXTERN_C void JITAPI FinalizeProcess()
443 {
444 if (m_libHandle)
445 {
446 #if ITT_PLATFORM==ITT_PLATFORM_WIN
447 FreeLibrary(m_libHandle);
448 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
449 dlclose(m_libHandle);
450 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
451 m_libHandle = NULL;
452 }
453
454 if (threadLocalStorageHandle)
455 #if ITT_PLATFORM==ITT_PLATFORM_WIN
456 TlsFree (threadLocalStorageHandle);
457 #else /* ITT_PLATFORM==ITT_PLATFORM_WIN */
458 pthread_key_delete(threadLocalStorageHandle);
459 #endif /* ITT_PLATFORM==ITT_PLATFORM_WIN */
460 }
461
462 /*
463 * This function should be called by the user for any method once.
464 * The function will return a unique method ID, the user should maintain
465 * the ID for each method
466 */
467 ITT_EXTERN_C unsigned int JITAPI iJIT_GetNewMethodID()
468 {
469 static unsigned int methodID = 0x100000;
470
471 if (methodID == 0)
472 return 0; /* ERROR : this is not a valid value */
473
474 return methodID++;
475 }
0 /*===-- jitprofiling.h - JIT Profiling API-------------------------*- C -*-===*
1 *
2 * The LLVM Compiler Infrastructure
3 *
4 * This file is distributed under the University of Illinois Open Source
5 * License. See LICENSE.TXT for details.
6 *
7 *===----------------------------------------------------------------------===*
8 *
9 * This file provides Intel(R) Performance Analyzer JIT (Just-In-Time)
10 * Profiling API declaration.
11 *
12 *===----------------------------------------------------------------------===*/
13 #ifndef __JITPROFILING_H__
14 #define __JITPROFILING_H__
15
16 /*
17 * Various constants used by functions
18 */
19
20 /* event notification */
21 typedef enum iJIT_jvm_event
22 {
23
24 /* shutdown */
25
26 /*
27 * Program exiting EventSpecificData NA
28 */
29 iJVM_EVENT_TYPE_SHUTDOWN = 2,
30
31 /* JIT profiling */
32
33 /*
34 * issued after method code jitted into memory but before code is executed
35 * EventSpecificData is an iJIT_Method_Load
36 */
37 iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED=13,
38
39 /* issued before unload. Method code will no longer be executed, but code
40 * and info are still in memory. The VTune profiler may capture method
41 * code only at this point EventSpecificData is iJIT_Method_Id
42 */
43 iJVM_EVENT_TYPE_METHOD_UNLOAD_START,
44
45 /* Method Profiling */
46
47 /* method name, Id and stack is supplied
48 * issued when a method is about to be entered EventSpecificData is
49 * iJIT_Method_NIDS
50 */
51 iJVM_EVENT_TYPE_ENTER_NIDS = 19,
52
53 /* method name, Id and stack is supplied
54 * issued when a method is about to be left EventSpecificData is
55 * iJIT_Method_NIDS
56 */
57 iJVM_EVENT_TYPE_LEAVE_NIDS
58 } iJIT_JVM_EVENT;
59
60 typedef enum _iJIT_ModeFlags
61 {
62 /* No need to Notify VTune, since VTune is not running */
63 iJIT_NO_NOTIFICATIONS = 0x0000,
64
65 /* when turned on the jit must call
66 * iJIT_NotifyEvent
67 * (
68 * iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED,
69 * )
70 * for all the method already jitted
71 */
72 iJIT_BE_NOTIFY_ON_LOAD = 0x0001,
73
74 /* when turned on the jit must call
75 * iJIT_NotifyEvent
76 * (
77 * iJVM_EVENT_TYPE_METHOD_UNLOAD_FINISHED,
78 * ) for all the method that are unloaded
79 */
80 iJIT_BE_NOTIFY_ON_UNLOAD = 0x0002,
81
82 /* when turned on the jit must instrument all
83 * the currently jited code with calls on
84 * method entries
85 */
86 iJIT_BE_NOTIFY_ON_METHOD_ENTRY = 0x0004,
87
88 /* when turned on the jit must instrument all
89 * the currently jited code with calls
90 * on method exit
91 */
92 iJIT_BE_NOTIFY_ON_METHOD_EXIT = 0x0008
93
94 } iJIT_ModeFlags;
95
96
97 /* Flags used by iJIT_IsProfilingActive() */
98 typedef enum _iJIT_IsProfilingActiveFlags
99 {
100 /* No profiler is running. Currently not used */
101 iJIT_NOTHING_RUNNING = 0x0000,
102
103 /* Sampling is running. This is the default value
104 * returned by iJIT_IsProfilingActive()
105 */
106 iJIT_SAMPLING_ON = 0x0001,
107
108 /* Call Graph is running */
109 iJIT_CALLGRAPH_ON = 0x0002
110
111 } iJIT_IsProfilingActiveFlags;
112
113 /* Enumerator for the environment of methods*/
114 typedef enum _iJDEnvironmentType
115 {
116 iJDE_JittingAPI = 2
117 } iJDEnvironmentType;
118
119 /**********************************
120 * Data structures for the events *
121 **********************************/
122
123 /* structure for the events:
124 * iJVM_EVENT_TYPE_METHOD_UNLOAD_START
125 */
126
127 typedef struct _iJIT_Method_Id
128 {
129 /* Id of the method (same as the one passed in
130 * the iJIT_Method_Load struct
131 */
132 unsigned int method_id;
133
134 } *piJIT_Method_Id, iJIT_Method_Id;
135
136
137 /* structure for the events:
138 * iJVM_EVENT_TYPE_ENTER_NIDS,
139 * iJVM_EVENT_TYPE_LEAVE_NIDS,
140 * iJVM_EVENT_TYPE_EXCEPTION_OCCURRED_NIDS
141 */
142
143 typedef struct _iJIT_Method_NIDS
144 {
145 /* unique method ID */
146 unsigned int method_id;
147
148 /* NOTE: no need to fill this field, it's filled by VTune */
149 unsigned int stack_id;
150
151 /* method name (just the method, without the class) */
152 char* method_name;
153 } *piJIT_Method_NIDS, iJIT_Method_NIDS;
154
155 /* structures for the events:
156 * iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED
157 */
158
159 typedef struct _LineNumberInfo
160 {
161 /* x86 Offset from the begining of the method*/
162 unsigned int Offset;
163
164 /* source line number from the begining of the source file */
165 unsigned int LineNumber;
166
167 } *pLineNumberInfo, LineNumberInfo;
168
169 typedef struct _iJIT_Method_Load
170 {
171 /* unique method ID - can be any unique value, (except 0 - 999) */
172 unsigned int method_id;
173
174 /* method name (can be with or without the class and signature, in any case
175 * the class name will be added to it)
176 */
177 char* method_name;
178
179 /* virtual address of that method - This determines the method range for the
180 * iJVM_EVENT_TYPE_ENTER/LEAVE_METHOD_ADDR events
181 */
182 void* method_load_address;
183
184 /* Size in memory - Must be exact */
185 unsigned int method_size;
186
187 /* Line Table size in number of entries - Zero if none */
188 unsigned int line_number_size;
189
190 /* Pointer to the begining of the line numbers info array */
191 pLineNumberInfo line_number_table;
192
193 /* unique class ID */
194 unsigned int class_id;
195
196 /* class file name */
197 char* class_file_name;
198
199 /* source file name */
200 char* source_file_name;
201
202 /* bits supplied by the user for saving in the JIT file */
203 void* user_data;
204
205 /* the size of the user data buffer */
206 unsigned int user_data_size;
207
208 /* NOTE: no need to fill this field, it's filled by VTune */
209 iJDEnvironmentType env;
210
211 } *piJIT_Method_Load, iJIT_Method_Load;
212
213 /* API Functions */
214 #ifdef __cplusplus
215 extern "C" {
216 #endif
217
218 #ifndef CDECL
219 # if defined WIN32 || defined _WIN32
220 # define CDECL __cdecl
221 # else /* defined WIN32 || defined _WIN32 */
222 # if defined _M_X64 || defined _M_AMD64 || defined __x86_64__
223 # define CDECL /* not actual on x86_64 platform */
224 # else /* _M_X64 || _M_AMD64 || __x86_64__ */
225 # define CDECL __attribute__ ((cdecl))
226 # endif /* _M_X64 || _M_AMD64 || __x86_64__ */
227 # endif /* defined WIN32 || defined _WIN32 */
228 #endif /* CDECL */
229
230 #define JITAPI CDECL
231
232 /* called when the settings are changed with new settings */
233 typedef void (*iJIT_ModeChangedEx)(void *UserData, iJIT_ModeFlags Flags);
234
235 int JITAPI iJIT_NotifyEvent(iJIT_JVM_EVENT event_type, void *EventSpecificData);
236
237 /* The new mode call back routine */
238 void JITAPI iJIT_RegisterCallbackEx(void *userdata,
239 iJIT_ModeChangedEx NewModeCallBackFuncEx);
240
241 iJIT_IsProfilingActiveFlags JITAPI iJIT_IsProfilingActive(void);
242
243 void JITAPI FinalizeThread(void);
244
245 void JITAPI FinalizeProcess(void);
246
247 unsigned int JITAPI iJIT_GetNewMethodID(void);
248
249 #ifdef __cplusplus
250 }
251 #endif
252
253 #endif /* __JITPROFILING_H__ */
None
1 link_directories( ${LLVM_INTEL_JITEVENTS_LIBDIR} )
2
31 set(LLVM_LINK_COMPONENTS mcjit jit interpreter nativecodegen bitreader asmparser selectiondag)
42
1313 )
1414
1515 if( LLVM_USE_INTEL_JITEVENTS )
16 include_directories( ${LLVM_INTEL_JITEVENTS_INCDIR} )
17 link_directories( ${LLVM_INTEL_JITEVENTS_LIBDIR} )
1816 set(ProfileTestSources
1917 IntelJITEventListenerTest.cpp
2018 )
1010
1111 using namespace llvm;
1212
13 #include "llvm/ExecutionEngine/IntelJITEventsWrapper.h"
13 // Because we want to keep the implementation details of the Intel API used to
14 // communicate with Amplifier out of the public header files, the header below
15 // is included from the source tree instead.
16 #include "../../../lib/ExecutionEngine/IntelJITEvents/IntelJITEventsWrapper.h"
1417
1518 #include
1619 #include