ThreadUtil.h 925 B

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