add full debug to intel device

This commit is contained in:
Meliox 2026-06-13 17:56:23 +02:00
parent 30d99079a7
commit bfce5e7f0c
2 changed files with 98 additions and 44 deletions

View File

@ -20,26 +20,44 @@ our @EXPORT_OK = qw(
sub get_intel_gpu_devices { sub get_intel_gpu_devices {
my @devices = (); my @devices = ();
debug(__LINE__, "Getting Intel GPU devices"); if ($config{debug}{intel_mode} && -f $config{debug}{intel_devices_file}) {
if (open my $fh, '-|', 'intel_gpu_top -L') { debug(__LINE__, "Debug mode: reading Intel GPU devices from $config{debug}{intel_devices_file}");
while (<$fh>) { my $data = safe_read_json($config{debug}{intel_devices_file});
chomp; if ($data && ref $data eq 'ARRAY') {
# Parse: "card0 Intel Alderlake_n (Gen12) pci:vendor=8086,device=46D0,card=0" for my $dev (@$data) {
# or: "card0 Intel Alderlake_n (Gen12) pci:0000:00:02.0"
if (/^(card\d+)\s+(.+?)\s+(pci:[^\s]+)/) {
my ($card, $name, $path) = ($1, $2, $3);
push @devices, { push @devices, {
card => $card, card => $dev->{card},
name => $name, name => $dev->{name},
path => $path, path => $dev->{path},
drm_path => "/dev/dri/$card", drm_path => $dev->{drm_path},
}; };
debug(__LINE__, "Found Intel device: $card -> $name ($path)"); debug(__LINE__, "Found Intel device (debug): $dev->{card} -> $dev->{name} ($dev->{path})");
} }
} else {
debug(__LINE__, "Failed to parse debug file $config{debug}{intel_devices_file}");
} }
close $fh;
} else { } else {
debug(__LINE__, "Failed to run intel_gpu_top -L: $!"); debug(__LINE__, "Getting Intel GPU devices");
if (open my $fh, '-|', 'intel_gpu_top -L') {
while (<$fh>) {
chomp;
# Parse: "card0 Intel Alderlake_n (Gen12) pci:vendor=8086,device=46D0,card=0"
# or: "card0 Intel Alderlake_n (Gen12) pci:0000:00:02.0"
if (/^(card\d+)\s+(.+?)\s+(pci:[^\s]+)/) {
my ($card, $name, $path) = ($1, $2, $3);
push @devices, {
card => $card,
name => $name,
path => $path,
drm_path => "/dev/dri/$card",
};
debug(__LINE__, "Found Intel device: $card -> $name ($path)");
}
}
close $fh;
} else {
debug(__LINE__, "Failed to run intel_gpu_top -L: $!");
}
} }
return @devices; return @devices;
@ -132,46 +150,81 @@ sub collector_for_intel_device {
if defined $intel_gpu_top_pid && $intel_gpu_top_pid > 0; if defined $intel_gpu_top_pid && $intel_gpu_top_pid > 0;
}); });
debug(__LINE__, "About to open pipe to intel_gpu_top");
my $intel_pull_interval = $config{intervals}{data_pull} * 1000; # milliseconds
$intel_gpu_top_pid = open(my $fh, '-|',
"intel_gpu_top -d $drm_dev -s $intel_pull_interval -l 2>&1");
unless (defined $intel_gpu_top_pid && $intel_gpu_top_pid > 0) {
debug(__LINE__, "Failed to run intel_gpu_top for $drm_dev: $!");
exit 1;
}
debug(__LINE__, "Pipe opened successfully, PID=$intel_gpu_top_pid");
my $node_name = "node0"; my $node_name = "node0";
while (my $line = <$fh>) { if ($config{debug}{intel_mode} && -f $config{debug}{intel_output_file}) {
last if $shutdown; debug(__LINE__, "Debug mode: reading Intel GPU stats from $config{debug}{intel_output_file}");
chomp $line; while (!$shutdown) {
if (open my $fh, '<', $config{debug}{intel_output_file}) {
while (my $line = <$fh>) {
chomp $line;
next if $line =~ /MHz|IRQ|RC6|Power|RCS|BCS|VCS|VECS|req\s+act|^\s*$/;
next if $line =~ /MHz|IRQ|RC6|Power|RCS|BCS|VCS|VECS|req\s+act|^\s*$/; if ($line =~ /^\s*[\d\s\.]+$/) {
my $stats = _parse_intel_gpu_line($line);
if ($line =~ /^\s*[\d\s\.]+$/) { if ($stats) {
my $stats = _parse_intel_gpu_line($line); my $device_data = {
$node_name => {
name => $device->{name},
device_path => $device->{path},
drm_path => $device->{drm_path},
stats => $stats,
}
};
if ($stats) { safe_write_json($device_state_file, $device_data);
my $device_data = { update_intel_gpu_rrd($device->{card}, $stats);
$node_name => { }
name => $device->{name},
device_path => $device->{path},
drm_path => $device->{drm_path},
stats => $stats,
} }
}; }
close $fh;
} else {
debug(__LINE__, "Failed to open debug file $config{debug}{intel_output_file}: $!");
}
sleep $config{intervals}{data_pull} unless $shutdown;
}
} else {
debug(__LINE__, "About to open pipe to intel_gpu_top");
my $intel_pull_interval = $config{intervals}{data_pull} * 1000; # milliseconds
$intel_gpu_top_pid = open(my $fh, '-|',
"intel_gpu_top -d $drm_dev -s $intel_pull_interval -l 2>&1");
safe_write_json($device_state_file, $device_data); unless (defined $intel_gpu_top_pid && $intel_gpu_top_pid > 0) {
update_intel_gpu_rrd($device->{card}, $stats); debug(__LINE__, "Failed to run intel_gpu_top for $drm_dev: $!");
exit 1;
}
debug(__LINE__, "Pipe opened successfully, PID=$intel_gpu_top_pid");
while (my $line = <$fh>) {
last if $shutdown;
chomp $line;
next if $line =~ /MHz|IRQ|RC6|Power|RCS|BCS|VCS|VECS|req\s+act|^\s*$/;
if ($line =~ /^\s*[\d\s\.]+$/) {
my $stats = _parse_intel_gpu_line($line);
if ($stats) {
my $device_data = {
$node_name => {
name => $device->{name},
device_path => $device->{path},
drm_path => $device->{drm_path},
stats => $stats,
}
};
safe_write_json($device_state_file, $device_data);
update_intel_gpu_rrd($device->{card}, $stats);
}
} }
} }
close $fh;
} }
close $fh;
debug(__LINE__, "Collector for $device->{card} shutting down"); debug(__LINE__, "Collector for $device->{card} shutting down");
exit 0; exit 0;
} }

View File

@ -42,6 +42,7 @@ our %config = (
lm_sensors_output_file => '/tmp/sensors-output.json', lm_sensors_output_file => '/tmp/sensors-output.json',
intel_mode => 0, intel_mode => 0,
intel_devices_file => '/tmp/intel-gpu-devices.json', intel_devices_file => '/tmp/intel-gpu-devices.json',
intel_output_file => '/tmp/intel-gpu-output.json',
nvidia_mode => 0, nvidia_mode => 0,
nvidia_devices_file => '/tmp/nvidia-smi-devices.csv', nvidia_devices_file => '/tmp/nvidia-smi-devices.csv',
nvidia_output_file => '/tmp/nvidia-smi-output.csv', nvidia_output_file => '/tmp/nvidia-smi-output.csv',