ThreadUtil.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #if !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)
  2. /*
  3. * Copyright (c) Meta Platforms, Inc. and affiliates.
  4. * All rights reserved.
  5. *
  6. * This source code is licensed under the BSD-style license found in the
  7. * LICENSE file in the root directory of this source tree.
  8. */
  9. #pragma once
  10. #include <sys/stat.h>
  11. #include <cstdint>
  12. #include <string>
  13. #include <utility>
  14. #include <vector>
  15. namespace libkineto {
  16. int32_t systemThreadId(bool cache = true);
  17. int32_t threadId();
  18. bool setThreadName(const std::string& name);
  19. std::string getThreadName();
  20. int32_t pidNamespace(ino_t& ns);
  21. int32_t processId(bool cache = true);
  22. std::string processName(int32_t pid);
  23. // Return a list of pids and process names for the current process
  24. // and its parents.
  25. std::vector<std::pair<int32_t, std::string>> pidCommandPairsOfAncestors();
  26. // Resets all cached Thread local state, this must be done on
  27. // forks to prevent stale values from being retained.
  28. void resetTLS();
  29. } // namespace libkineto
  30. #else
  31. #error "This file should not be included when either TORCH_STABLE_ONLY or TORCH_TARGET_VERSION is defined."
  32. #endif // !defined(TORCH_STABLE_ONLY) && !defined(TORCH_TARGET_VERSION)