[x265-commits] [x265] prof: add support for thread names

Steve Borho steve at borho.org
Fri Jan 9 06:29:03 CET 2015


details:   http://hg.videolan.org/x265/rev/11394825d0bf
branches:  
changeset: 9058:11394825d0bf
user:      Steve Borho <steve at borho.org>
date:      Fri Jan 09 09:20:27 2015 +0530
description:
prof: add support for thread names
Subject: [x265] vtune: according to their docs, there is no need to check for NULL domain

details:   http://hg.videolan.org/x265/rev/909ad6eb551c
branches:  
changeset: 9059:909ad6eb551c
user:      Steve Borho <steve at borho.org>
date:      Fri Jan 09 10:25:15 2015 +0530
description:
vtune: according to their docs, there is no need to check for NULL domain
Subject: [x265] prof: expose vtune pause/resume

details:   http://hg.videolan.org/x265/rev/b491977000d6
branches:  
changeset: 9060:b491977000d6
user:      Steve Borho <steve at borho.org>
date:      Fri Jan 09 10:28:49 2015 +0530
description:
prof: expose vtune pause/resume
Subject: [x265] prof: instrument file reads

details:   http://hg.videolan.org/x265/rev/dcdf27466fb1
branches:  
changeset: 9061:dcdf27466fb1
user:      Steve Borho <steve at borho.org>
date:      Fri Jan 09 10:33:48 2015 +0530
description:
prof: instrument file reads
Subject: [x265] vtune: sprintf needs stdio.h

details:   http://hg.videolan.org/x265/rev/77938d3e3f09
branches:  
changeset: 9062:77938d3e3f09
user:      Steve Borho <steve at borho.org>
date:      Fri Jan 09 11:02:16 2015 +0530
description:
vtune: sprintf needs stdio.h

diffstat:

 source/common/common.h          |   9 +++++++++
 source/common/threadpool.cpp    |   2 ++
 source/encoder/frameencoder.cpp |   2 ++
 source/input/y4m.cpp            |   1 +
 source/input/yuv.cpp            |   1 +
 source/profile/cpuEvents.h      |   1 +
 source/profile/vtune/vtune.cpp  |  21 +++++++++++++++------
 source/profile/vtune/vtune.h    |   5 +++--
 source/x265.cpp                 |   1 +
 9 files changed, 35 insertions(+), 8 deletions(-)

diffs (155 lines):

diff -r 08429f82d30f -r 77938d3e3f09 source/common/common.h
--- a/source/common/common.h	Fri Jan 09 08:55:58 2015 +0530
+++ b/source/common/common.h	Fri Jan 09 11:02:16 2015 +0530
@@ -44,14 +44,23 @@
 #if ENABLE_PPA
 #include "profile/PPA/ppa.h"
 #define ProfileScopeEvent(x) PPAScopeEvent(x)
+#define THREAD_NAME(n,i)
 #define PROFILE_INIT()       PPA_INIT()
+#define PROFILE_PAUSE()
+#define PROFILE_RESUME()
 #elif ENABLE_VTUNE
 #include "profile/vtune/vtune.h"
 #define ProfileScopeEvent(x) VTuneScopeEvent _vtuneTask(x)
+#define THREAD_NAME(n,i)     vtuneSetThreadName(n, i)
 #define PROFILE_INIT()       vtuneInit()
+#define PROFILE_PAUSE()      __itt_pause()
+#define PROFILE_RESUME()     __itt_resume()
 #else
 #define ProfileScopeEvent(x)
+#define THREAD_NAME(n,i)
 #define PROFILE_INIT()
+#define PROFILE_PAUSE()
+#define PROFILE_RESUME()
 #endif
 
 #define FENC_STRIDE 64
diff -r 08429f82d30f -r 77938d3e3f09 source/common/threadpool.cpp
--- a/source/common/threadpool.cpp	Fri Jan 09 08:55:58 2015 +0530
+++ b/source/common/threadpool.cpp	Fri Jan 09 11:02:16 2015 +0530
@@ -137,6 +137,8 @@ public:
 
 void PoolThread::threadMain()
 {
+    THREAD_NAME("Worker", m_id);
+
 #if _WIN32
     SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
 #else
diff -r 08429f82d30f -r 77938d3e3f09 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Fri Jan 09 08:55:58 2015 +0530
+++ b/source/encoder/frameencoder.cpp	Fri Jan 09 11:02:16 2015 +0530
@@ -215,6 +215,8 @@ bool FrameEncoder::startCompressFrame(Fr
 
 void FrameEncoder::threadMain()
 {
+    THREAD_NAME("Frame", m_frameEncoderID);
+
     // worker thread routine for FrameEncoder
     do
     {
diff -r 08429f82d30f -r 77938d3e3f09 source/input/y4m.cpp
--- a/source/input/y4m.cpp	Fri Jan 09 08:55:58 2015 +0530
+++ b/source/input/y4m.cpp	Fri Jan 09 11:02:16 2015 +0530
@@ -419,6 +419,7 @@ bool Y4MInput::populateFrameQueue()
             return false;
     }
 
+    ProfileScopeEvent(frameRead);
     ifs->read(buf[written % QUEUE_SIZE], framesize);
     if (ifs->good())
     {
diff -r 08429f82d30f -r 77938d3e3f09 source/input/yuv.cpp
--- a/source/input/yuv.cpp	Fri Jan 09 08:55:58 2015 +0530
+++ b/source/input/yuv.cpp	Fri Jan 09 11:02:16 2015 +0530
@@ -193,6 +193,7 @@ bool YUVInput::populateFrameQueue()
             return false;
     }
 
+    ProfileScopeEvent(frameRead);
     ifs->read(buf[written % QUEUE_SIZE], framesize);
     if (ifs->good())
     {
diff -r 08429f82d30f -r 77938d3e3f09 source/profile/cpuEvents.h
--- a/source/profile/cpuEvents.h	Fri Jan 09 08:55:58 2015 +0530
+++ b/source/profile/cpuEvents.h	Fri Jan 09 11:02:16 2015 +0530
@@ -1,3 +1,4 @@
+CPU_EVENT(frameRead)
 CPU_EVENT(bitstreamWrite)
 CPU_EVENT(frameThread)
 CPU_EVENT(encodeCTU)
diff -r 08429f82d30f -r 77938d3e3f09 source/profile/vtune/vtune.cpp
--- a/source/profile/vtune/vtune.cpp	Fri Jan 09 08:55:58 2015 +0530
+++ b/source/profile/vtune/vtune.cpp	Fri Jan 09 11:02:16 2015 +0530
@@ -22,8 +22,9 @@
  *****************************************************************************/
 
 #include "vtune.h"
+#include <stdio.h>
 
-namespace x265 {
+namespace {
 
 #define CPU_EVENT(x) #x
 const char *stringNames[] =
@@ -33,17 +34,25 @@ const char *stringNames[] =
 };
 #undef CPU_EVENT
 
+}
+
+namespace x265 {
+
 __itt_domain* domain;
 __itt_string_handle* taskHandle[NUM_VTUNE_TASKS];
 
 void vtuneInit()
 {
     domain = __itt_domain_create("x265");
-    if (domain)
-    {
-        for (size_t i = 0; i < sizeof(stringNames) / sizeof(const char *); i++)
-            taskHandle[i] = __itt_string_handle_create(stringNames[i]);
-    }
+    for (size_t i = 0; i < sizeof(stringNames) / sizeof(const char *); i++)
+        taskHandle[i] = __itt_string_handle_create(stringNames[i]);
+}
+
+void vtuneSetThreadName(const char *name, int id)
+{
+    char threadname[128];
+    sprintf(threadname, "%s %d", name, id);
+    __itt_thread_set_name(threadname);
 }
 
 }
diff -r 08429f82d30f -r 77938d3e3f09 source/profile/vtune/vtune.h
--- a/source/profile/vtune/vtune.h	Fri Jan 09 08:55:58 2015 +0530
+++ b/source/profile/vtune/vtune.h	Fri Jan 09 11:02:16 2015 +0530
@@ -41,11 +41,12 @@ extern __itt_string_handle* taskHandle[N
 
 struct VTuneScopeEvent
 {
-    VTuneScopeEvent(int e) { if (domain) __itt_task_begin(domain, __itt_null, __itt_null, taskHandle[e]); }
-    ~VTuneScopeEvent()     { if (domain) __itt_task_end(domain); }
+    VTuneScopeEvent(int e) { __itt_task_begin(domain, __itt_null, __itt_null, taskHandle[e]); }
+    ~VTuneScopeEvent()     { __itt_task_end(domain); }
 };
 
 void vtuneInit();
+void vtuneSetThreadName(const char *name, int id);
 
 }
 
diff -r 08429f82d30f -r 77938d3e3f09 source/x265.cpp
--- a/source/x265.cpp	Fri Jan 09 08:55:58 2015 +0530
+++ b/source/x265.cpp	Fri Jan 09 11:02:16 2015 +0530
@@ -808,6 +808,7 @@ int main(int argc, char **argv)
     VLDSetReportOptions(VLD_OPT_REPORT_TO_DEBUGGER | VLD_OPT_REPORT_TO_FILE, L"x265_leaks.txt");
 #endif
     PROFILE_INIT();
+    THREAD_NAME("API", 0);
 
     x265_param *param = x265_param_alloc();
     CLIOptions cliopt;


More information about the x265-commits mailing list