Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dashboard/modules/reporter/reporter_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ async def GetProfilingStats(self, request, context):
duration = request.duration
profiling_file_path = os.path.join(ray.utils.get_ray_temp_dir(),
"{}_profiling.txt".format(pid))
sudo = "sudo" if ray.utils.get_user() != "root" else ""
process = subprocess.Popen(
"sudo $(which py-spy) record -o {} -p {} -d {} -f speedscope"
.format(profiling_file_path, pid, duration),
(f"{sudo} $(which py-spy) record -o {profiling_file_path} -p {pid}"
f" -d {duration} -f speedscope"),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
Expand Down
5 changes: 3 additions & 2 deletions python/ray/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def GetProfilingStats(self, request, context):
duration = request.duration
profiling_file_path = os.path.join(ray.utils.get_ray_temp_dir(),
f"{pid}_profiling.txt")
sudo = "sudo" if ray.utils.get_user() != "root" else ""
process = subprocess.Popen(
"sudo $(which py-spy) record -o {} -p {} -d {} -f speedscope"
.format(profiling_file_path, pid, duration),
(f"{sudo} $(which py-spy) record -o {profiling_file_path} -p {pid}"
f" -d {duration} -f speedscope"),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
Expand Down
13 changes: 13 additions & 0 deletions python/ray/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
import ray.ray_constants as ray_constants
import psutil

pwd = None
if sys.platform != "win32":
import pwd

logger = logging.getLogger(__name__)

# Linux can bind child processes' lifetimes to that of their parents via prctl.
Expand Down Expand Up @@ -780,3 +784,12 @@ def try_to_symlink(symlink_path, target_path):
os.symlink(target_path, symlink_path)
except OSError:
return


def get_user():
if pwd is None:
return ""
try:
return pwd.getpwuid(os.getuid()).pw_name
except Exception:
return ""