[x265] [PATCH] add support for VTune profiling with task indicators

Steve Borho steve at borho.org
Thu Jan 8 12:14:34 CET 2015


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1420714131 -19800
#      Thu Jan 08 16:18:51 2015 +0530
# Node ID a04704062b6be9ecfbeca00a9d8e1d83ace2f20c
# Parent  4659aa3e33bf3cd3a98e8581973eafc30a707caf
add support for VTune profiling with task indicators

diff -r 4659aa3e33bf -r a04704062b6b source/CMakeLists.txt
--- a/source/CMakeLists.txt	Thu Jan 08 14:58:35 2015 +0530
+++ b/source/CMakeLists.txt	Thu Jan 08 16:18:51 2015 +0530
@@ -56,10 +56,10 @@
 endif()
 
 if(UNIX)
-    SET(PLATFORM_LIBS pthread)
+    list(APPEND PLATFORM_LIBS pthread)
     find_library(LIBRT rt)
     if(LIBRT)
-        set(PLATFORM_LIBS ${PLATFORM_LIBS} rt)
+        list(APPEND PLATFORM_LIBS rt)
     endif()
 endif(UNIX)
 
@@ -201,19 +201,33 @@
 if(ENABLE_PPA)
     add_definitions(-DENABLE_PPA)
     add_subdirectory(PPA)
-    SET(PLATFORM_LIBS ${PLATFORM_LIBS} PPA)
+    list(APPEND PLATFORM_LIBS PPA)
     if(UNIX)
-        SET(PLATFORM_LIBS ${PLATFORM_LIBS} dl)
+        list(APPEND PLATFORM_LIBS dl)
     endif(UNIX)
 endif(ENABLE_PPA)
 
+option(ENABLE_VTUNE "Enable Vtune profiling instrumentation" OFF)
+if(ENABLE_VTUNE)
+    add_definitions(-DENABLE_VTUNE)
+    add_subdirectory(vtune)
+    list(APPEND PLATFORM_LIBS vtune)
+    include_directories($ENV{VTUNE_AMPLIFIER_XE_2015_DIR}/include)
+    link_directories($ENV{VTUNE_AMPLIFIER_XE_2015_DIR}/lib64)
+    if(WIN32)
+        list(APPEND PLATFORM_LIBS libittnotify.lib)
+    else()
+        list(APPEND PLATFORM_LIBS libittnotify.a dl)
+    endif()
+endif(ENABLE_VTUNE)
+
 if (WIN32)
     # Visual leak detector
     find_package(VLD QUIET)
     if(VLD_FOUND)
         add_definitions(-DHAVE_VLD)
         include_directories(${VLD_INCLUDE_DIRS})
-        set(PLATFORM_LIBS ${PLATFORM_LIBS} ${VLD_LIBRARIES})
+        list(APPEND PLATFORM_LIBS ${VLD_LIBRARIES})
         link_directories(${VLD_LIBRARY_DIRS})
     endif()
     option(WINXP_SUPPORT "Make binaries compatible with Windows XP" OFF)
diff -r 4659aa3e33bf -r a04704062b6b source/common/common.h
--- a/source/common/common.h	Thu Jan 08 14:58:35 2015 +0530
+++ b/source/common/common.h	Thu Jan 08 16:18:51 2015 +0530
@@ -45,6 +45,11 @@
 #include "PPA/ppa.h"
 #define ProfileScopeEvent(x) PPAScopeEvent(x)
 #define PROFILE_INIT()       PPA_INIT()
+#elif ENABLE_VTUNE
+#include "ittnotify.h"
+#include "vtune/vtune.h"
+#define ProfileScopeEvent(x) VTuneScopeEvent _vtuneTask(x)
+#define PROFILE_INIT()       vtuneInit()
 #else
 #define ProfileScopeEvent(x)
 #define PROFILE_INIT()
diff -r 4659aa3e33bf -r a04704062b6b source/vtune/CMakeLists.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/vtune/CMakeLists.txt	Thu Jan 08 16:18:51 2015 +0530
@@ -0,0 +1,2 @@
+include_directories(.. ../common $ENV{VTUNE_AMPLIFIER_XE_2015_DIR}/include)
+add_library(vtune vtune.h ../PPA/ppaCPUEvents.h vtune.cpp)
diff -r 4659aa3e33bf -r a04704062b6b source/vtune/vtune.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/vtune/vtune.cpp	Thu Jan 08 16:18:51 2015 +0530
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Copyright (C) 2015 x265 project
+ *
+ * Authors: Steve Borho <steve at borho.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., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at license @ x265.com.
+ *****************************************************************************/
+
+#include "common.h"
+#include "vtune.h"
+
+namespace x265 {
+
+#define PPA_REGISTER_CPU_EVENT(x) #x
+const char *stringNames[] =
+{
+#include "PPA/ppaCPUEvents.h"
+    ""
+};
+#undef PPA_REGISTER_CPU_EVENT
+
+__itt_domain* domain;
+__itt_string_handle* taskHandle[NUM_VTUNE_TASKS];
+
+void vtuneInit()
+{
+    domain = __itt_domain_create("x265");
+    if (domain)
+    {
+        for (int i = 0; i < sizeof(stringNames) / sizeof(const char *); i++)
+            taskHandle[i] = __itt_string_handle_create(stringNames[i]);
+    }
+}
+
+}
diff -r 4659aa3e33bf -r a04704062b6b source/vtune/vtune.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/vtune/vtune.h	Thu Jan 08 16:18:51 2015 +0530
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * Copyright (C) 2015 x265 project
+ *
+ * Authors: Steve Borho <steve at borho.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., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at license @ x265.com.
+ *****************************************************************************/
+
+#ifndef VTUNE_H
+#define VTUNE_H
+
+namespace x265 {
+
+/* Use PPA CPU event list header to define VTune tasks */
+#define PPA_REGISTER_CPU_EVENT(x) x,
+enum VTuneTasksEnum
+{
+#include "PPA/ppaCPUEvents.h"
+    NUM_VTUNE_TASKS
+};
+#undef PPA_REGISTER_CPU_EVENT
+
+extern __itt_domain* domain;
+extern __itt_string_handle* taskHandle[NUM_VTUNE_TASKS];
+
+struct VTuneScopeEvent
+{
+    VTuneScopeEvent(int e) { if (domain) __itt_task_begin(domain, __itt_null, __itt_null, taskHandle[e]); }
+    ~VTuneScopeEvent()     { if (domain) __itt_task_end(domain); }
+};
+
+void vtuneInit();
+
+}
+
+#endif


More information about the x265-devel mailing list