11#include " proc.h"
2- #include " common.h"
3- #include " string.h"
42
53#include < yt/yt/core/logging/log.h>
64
2220#include < util/string/strip.h>
2321#include < util/string/vector.h>
2422
23+ #include < util/system/getpid.h>
2524#include < util/system/info.h>
2625#include < util/system/fs.h>
2726#include < util/system/fstat.h>
27+ #include < util/system/thread.h>
28+
2829#include < util/folder/iterator.h>
2930#include < util/folder/filelist.h>
3031
@@ -327,24 +328,12 @@ std::vector<int> GetPidsUnderParent(int targetPid)
327328
328329size_t GetCurrentProcessId ()
329330{
330- #if defined(_linux_)
331- return getpid ();
332- #else
333- YT_ABORT ();
334- #endif
331+ return GetPID ();
335332}
336333
337334size_t GetCurrentThreadId ()
338335{
339- #if defined(_linux_)
340- return static_cast <size_t >(::syscall (SYS_gettid));
341- #elif defined(_darwin_)
342- uint64_t tid;
343- YT_VERIFY (pthread_threadid_np (nullptr , &tid) == 0 );
344- return static_cast <size_t >(tid);
345- #else
346- return ::GetCurrentThreadId ();
347- #endif
336+ return TThread::CurrentThreadNumericId ();
348337}
349338
350339std::vector<size_t > GetCurrentProcessThreadIds ()
@@ -371,7 +360,7 @@ std::vector<size_t> GetCurrentProcessThreadIds()
371360
372361bool IsUserspaceThread (size_t tid)
373362{
374- #ifdef __linux__
363+ #if defined( __linux__)
375364 TFileInput file (Format (" /proc/%v/stat" , tid));
376365 auto statFields = SplitString (file.ReadLine (), " " );
377366 constexpr int StartStackIndex = 27 ;
@@ -383,23 +372,34 @@ bool IsUserspaceThread(size_t tid)
383372 return startStack != 0 ;
384373#else
385374 Y_UNUSED (tid);
386- return false ;
375+ return true ;
387376#endif
388377}
389378
390379std::string GetCurrentProcessName ()
391380{
392- #ifdef __linux__
381+ #if defined( __linux__)
393382 return std::string (Trim (TUnbufferedFileInput (" /proc/self/comm" ).ReadAll (), " \n " ));
383+ #elif defined(_win_)
384+ char path[MAX_PATH];
385+ DWORD length = ::GetModuleFileNameA (nullptr , path, MAX_PATH);
386+ if (length == 0 ) {
387+ return " (unknown)" ;
388+ }
389+ std::string fullPath (path, length);
390+ auto pos = fullPath.find_last_of (" \\ /" );
391+ return pos == std::string::npos ? fullPath : fullPath.substr (pos + 1 );
394392#else
395393 return " (unknown)" ;
396394#endif
397395}
398396
399397std::string GetCurrentProcessCommandLine ()
400398{
401- #ifdef __linux__
399+ #if defined( __linux__)
402400 return std::string (Trim (TUnbufferedFileInput (" /proc/self/cmdline" ).ReadAll (), " \n " ));
401+ #elif defined(_win_)
402+ return ::GetCommandLineA ();
403403#else
404404 return " (unknown)" ;
405405#endif
0 commit comments