thread_extra.cpp 726 B

123456789101112131415161718192021222324252627282930
  1. #include "thread_extra.h"
  2. #include <util/stream/str.h>
  3. #include <util/system/execpath.h>
  4. #include <util/system/platform.h>
  5. #include <util/system/thread.h>
  6. namespace {
  7. #ifdef _linux_
  8. TString GetExecName() {
  9. TString execPath = GetExecPath();
  10. size_t lastSlash = execPath.find_last_of('/');
  11. if (lastSlash == TString::npos) {
  12. return execPath;
  13. } else {
  14. return execPath.substr(lastSlash + 1);
  15. }
  16. }
  17. #endif
  18. }
  19. void SetCurrentThreadName(const char* name) {
  20. #ifdef _linux_
  21. TStringStream linuxName;
  22. linuxName << GetExecName() << "." << name;
  23. TThread::SetCurrentThreadName(linuxName.Str().data());
  24. #else
  25. TThread::SetCurrentThreadName(name);
  26. #endif
  27. }