Port numa_prefix to python2 [ci skip]

This commit is contained in:
Abraham Gonzalez
2020-08-24 11:04:28 -07:00
committed by GitHub
parent 2168813da0
commit 543136db8c

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env perl #!/usr/bin/env python
#============================================================================ #============================================================================
# - really simple script, which just prints out the numactl cmd to # - really simple script, which just prints out the numactl cmd to
@@ -23,45 +23,54 @@
# 1: 20 10 # 1: 20 10
#============================================================================ #============================================================================
use strict; import subprocess
use warnings; import re
import sys
my $path = `which numactl`; which_proc = subprocess.Popen(["which", "numactl"], stdout=subprocess.PIPE)
if(length($path) > 0) { out, err = which_proc.communicate()
my ($head_line, @rest) = map {chomp; $_} `numactl -H`;
if($head_line =~ /available: (\d+) nodes/) { if out != "":
my $node_count = $1; numactl_proc = subprocess.Popen(["numactl", "-H"], stdout=subprocess.PIPE)
my $best_node_id = undef out, err = numactl_proc.communicate()
my $best_cpus = undef;
my $best_free_size = undef; lines = out.split("\n")
line_idx = 0
head_line = lines[line_idx]
line_idx += 1
node_match = re.match(r"^ *available: +(\d+) nodes", head_line)
if node_match:
avail_nodes = node_match.group(1)
best_node_id = ""
best_cpus = ""
best_free_size = 0
# loop through available nodes, selecting the node with the most free mem # loop through available nodes, selecting the node with the most free mem
foreach my $num (1..$node_count) { for i in avail_nodes:
my $cpus_line = shift(@rest); cpu_line = lines[line_idx]
my $mem_size_line = shift(@rest); mem_size_line = lines[line_idx + 1]
my $mem_free_line = shift(@rest); mem_free_line = lines[line_idx + 2]
line_idx += 3
if($cpus_line =~ /node (\d+) cpus: (\d.*\d)$/) { cpu_match = re.match(r"^ *node (\d+) cpus: (\d.*\d)$", cpu_line)
my ($node_id, $cpus) = ($1, $2); if cpu_match:
$cpus =~ s/\s+/,/g; node_id = cpu_match.group(1)
cpus = cpu_match.group(2).replace(" ", ",")
if($mem_free_line =~ /node $node_id free: (\d+) \S+$/) { mem_free_match = re.match(r"^ *node " + node_id + " free: (\d+) \S+$", mem_free_line)
my $free_size = $1; if mem_free_match:
if(!defined($best_free_size) || ($free_size > $best_free_size)) { free_size = mem_free_match.group(1)
$best_node_id = $node_id; if int(free_size) > int(best_free_size):
$best_cpus = $cpus; best_node_id = node_id
$best_free_size = $free_size; best_cpus = cpus
} best_free_size = free_size
} else { else:
die("malformed mem-free line: $mem_free_line\n"); sys.exit("[ERROR] Malformed mem free line: " + mem_free_line)
}
} else { else:
die("malformed cpus line: $cpus_line\n"); sys.exit("[ERROR] Malformed cpus line: " + cpu_line)
}
} sys.stdout.write("numactl -m " + best_node_id + " -C " + best_cpus + " --")
print("numactl -m $best_node_id -C $best_cpus --"); else:
} else { sys.exit("[ERROR] Malformed head line: " + head_line)
die("malformed head line: $head_line\n");
}
}