Skip to content

Commit a7a420c

Browse files
committed
threading: Set thread names for perf
1 parent 1643be5 commit a7a420c

6 files changed

Lines changed: 32 additions & 0 deletions

File tree

include/internal/libfreenect2/async_packet_processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class AsyncPacketProcessor : public PacketProcessor<PacketT>
125125
/** Asynchronously process a provided packet. */
126126
void execute()
127127
{
128+
this_thread::set_name(processor_->name());
128129
libfreenect2::unique_lock l(packet_mutex_);
129130

130131
while(!shutdown_)

include/internal/libfreenect2/depth_packet_processor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class OpenGLDepthPacketProcessor : public DepthPacketProcessor
130130
virtual void loadXZTables(const float *xtable, const float *ztable);
131131
virtual void loadLookupTable(const short *lut);
132132

133+
virtual const char *name() { return "OpenGL"; }
133134
virtual void process(const DepthPacket &packet);
134135
private:
135136
OpenGLDepthPacketProcessorImpl *impl_;
@@ -152,6 +153,7 @@ class CpuDepthPacketProcessor : public DepthPacketProcessor
152153
virtual void loadXZTables(const float *xtable, const float *ztable);
153154
virtual void loadLookupTable(const short *lut);
154155

156+
virtual const char *name() { return "CPU"; }
155157
virtual void process(const DepthPacket &packet);
156158
private:
157159
CpuDepthPacketProcessorImpl *impl_;
@@ -173,6 +175,7 @@ class OpenCLDepthPacketProcessor : public DepthPacketProcessor
173175
virtual void loadXZTables(const float *xtable, const float *ztable);
174176
virtual void loadLookupTable(const short *lut);
175177

178+
virtual const char *name() { return "OpenCL"; }
176179
virtual void process(const DepthPacket &packet);
177180
private:
178181
OpenCLDepthPacketProcessorImpl *impl_;
@@ -195,6 +198,7 @@ class CudaDepthPacketProcessor : public DepthPacketProcessor
195198
virtual void loadLookupTable(const short *lut);
196199

197200
virtual bool good();
201+
virtual const char *name() { return "CUDA"; }
198202

199203
virtual void process(const DepthPacket &packet);
200204
protected:

include/internal/libfreenect2/packet_processor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class PacketProcessor
5252

5353
virtual bool good() { return true; }
5454

55+
virtual const char *name() { return "a packet processor"; }
56+
5557
/**
5658
* A new packet has arrived, process it.
5759
* @param packet Packet to process.

include/internal/libfreenect2/rgb_packet_processor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class TurboJpegRgbPacketProcessor : public RgbPacketProcessor
8787
TurboJpegRgbPacketProcessor();
8888
virtual ~TurboJpegRgbPacketProcessor();
8989
virtual void process(const libfreenect2::RgbPacket &packet);
90+
virtual const char *name() { return "TurboJPEG"; }
9091
private:
9192
TurboJpegRgbPacketProcessorImpl *impl_; ///< Decoder implementation.
9293
};
@@ -101,6 +102,7 @@ class VTRgbPacketProcessor : public RgbPacketProcessor
101102
VTRgbPacketProcessor();
102103
virtual ~VTRgbPacketProcessor();
103104
virtual void process(const libfreenect2::RgbPacket &packet);
105+
virtual const char *name() { return "VideoToolbox"; }
104106
private:
105107
VTRgbPacketProcessorImpl *impl_;
106108
};
@@ -115,6 +117,7 @@ class VaapiRgbPacketProcessor : public RgbPacketProcessor
115117
VaapiRgbPacketProcessor();
116118
virtual ~VaapiRgbPacketProcessor();
117119
virtual bool good();
120+
virtual const char *name() { return "VAAPI"; }
118121
virtual void process(const libfreenect2::RgbPacket &packet);
119122
protected:
120123
virtual Allocator *getAllocator();
@@ -132,6 +135,7 @@ class TegraJpegRgbPacketProcessor : public RgbPacketProcessor
132135
TegraJpegRgbPacketProcessor();
133136
virtual ~TegraJpegRgbPacketProcessor();
134137
virtual bool good();
138+
virtual const char *name() { return "TegraJPEG"; }
135139
virtual void process(const libfreenect2::RgbPacket &packet);
136140
private:
137141
TegraJpegRgbPacketProcessorImpl *impl_;

include/internal/libfreenect2/threading.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,25 @@ using namespace tthread::this_thread;
9494

9595
#endif
9696

97+
#if defined(__linux__)
98+
#include <sys/prctl.h>
99+
#elif defined(__APPLE__)
100+
#include <pthread.h>
101+
#endif
102+
103+
namespace libfreenect2
104+
{
105+
namespace this_thread
106+
{
107+
static inline void set_name(const char *name)
108+
{
109+
#if defined(__linux__)
110+
prctl(PR_SET_NAME, name);
111+
#elif defined(__APPLE__)
112+
pthread_setname_np(name);
113+
#endif
114+
}
115+
}
116+
}
97117

98118
#endif /* THREADING_H_ */

src/event_loop.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void EventLoop::stop()
9191
/** Execute the job, until shut down. */
9292
void EventLoop::execute()
9393
{
94+
this_thread::set_name("USB");
9495
timeval t;
9596
t.tv_sec = 0;
9697
t.tv_usec = 100000;

0 commit comments

Comments
 (0)