Skip to content

Commit

Permalink
Add ELF arch as app metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Jongy committed Aug 6, 2023
1 parent 9a409ff commit e073a87
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
16 changes: 16 additions & 0 deletions gprofiler/metadata/application_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from threading import Event, Lock
from typing import Any, Dict, Optional

from granulate_utils.linux.elf import elf_arch_to_uname_arch, get_elf_arch
from granulate_utils.linux.process import is_process_running, process_exe, read_process_execfn
from psutil import NoSuchProcess, Process, ZombieProcess

Expand Down Expand Up @@ -87,4 +88,19 @@ def make_application_metadata(self, process: Process) -> Dict[str, Any]:
execfn = f"error: {e.__class__.__name__}"
md["execfn"] = execfn

try:
# take arch from the executed elf, not the host system, because (although unlikely) it's possible
# that the process runs a different, emulated architecture.
arch = (
"error: not supported on Windows"
if is_windows()
else elf_arch_to_uname_arch(get_elf_arch(f"/proc/{process.pid}/exe"))
)
except (NoSuchProcess, ZombieProcess):
raise # let caller handle
except Exception as e:
logger.exception("Exception while getting process exe architecture", pid=process.pid)
arch = f"error: {e.__class__.__name__}"
md["arch"] = arch

return md
2 changes: 1 addition & 1 deletion granulate-utils
7 changes: 7 additions & 0 deletions tests/test_app_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the AGPL3 License. See LICENSE.md in the project root for license information.
#
import json
import platform
from pathlib import Path
from typing import Dict, List

Expand Down Expand Up @@ -34,6 +35,7 @@
else "buildid:a04b9016e15a247fbc21c91260c13e17a458ed33",
"python_version": "Python 3.6.15",
"sys_maxunicode": None,
"arch": platform.machine(),
},
),
(
Expand All @@ -52,6 +54,7 @@
"ruby_version": "ruby 2.6.7p197 (2021-04-05 revision 67941) [aarch64-linux]"
if is_aarch64()
else "ruby 2.6.7p197 (2021-04-05 revision 67941) [x86_64-linux]",
"arch": platform.machine(),
},
),
(
Expand All @@ -67,6 +70,7 @@
"libjvm_elfid": "buildid:33a1021cade63f16e30726be4111f20c34444764"
if is_aarch64()
else "buildid:622795512a2c037aec4d7ca6da05527dae86e460",
"arch": platform.machine(),
"jvm_flags": [
{
"name": "CICompilerCount",
Expand Down Expand Up @@ -152,6 +156,7 @@
"link": "dynamic",
"libc": "glibc",
"stripped": False,
"arch": platform.machine(),
},
),
(
Expand All @@ -164,6 +169,7 @@
"node_version": "v10.24.1",
"link": "dynamic",
"libc": "glibc",
"arch": platform.machine(),
},
),
(
Expand All @@ -174,6 +180,7 @@
"dotnet_version": "6.0.302",
"exe": "/usr/share/dotnet/dotnet",
"execfn": "/usr/bin/dotnet",
"arch": platform.machine(),
},
),
],
Expand Down

0 comments on commit e073a87

Please sign in to comment.