Port numa_prefix to python2 [ci skip]
This commit is contained in:
@@ -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;
|
|
||||||
|
|
||||||
# loop through available nodes, selecting the node with the most free mem
|
lines = out.split("\n")
|
||||||
foreach my $num (1..$node_count) {
|
line_idx = 0
|
||||||
my $cpus_line = shift(@rest);
|
|
||||||
my $mem_size_line = shift(@rest);
|
|
||||||
my $mem_free_line = shift(@rest);
|
|
||||||
|
|
||||||
if($cpus_line =~ /node (\d+) cpus: (\d.*\d)$/) {
|
head_line = lines[line_idx]
|
||||||
my ($node_id, $cpus) = ($1, $2);
|
line_idx += 1
|
||||||
$cpus =~ s/\s+/,/g;
|
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
|
||||||
|
|
||||||
if($mem_free_line =~ /node $node_id free: (\d+) \S+$/) {
|
# loop through available nodes, selecting the node with the most free mem
|
||||||
my $free_size = $1;
|
for i in avail_nodes:
|
||||||
if(!defined($best_free_size) || ($free_size > $best_free_size)) {
|
cpu_line = lines[line_idx]
|
||||||
$best_node_id = $node_id;
|
mem_size_line = lines[line_idx + 1]
|
||||||
$best_cpus = $cpus;
|
mem_free_line = lines[line_idx + 2]
|
||||||
$best_free_size = $free_size;
|
line_idx += 3
|
||||||
}
|
|
||||||
} else {
|
cpu_match = re.match(r"^ *node (\d+) cpus: (\d.*\d)$", cpu_line)
|
||||||
die("malformed mem-free line: $mem_free_line\n");
|
if cpu_match:
|
||||||
}
|
node_id = cpu_match.group(1)
|
||||||
} else {
|
cpus = cpu_match.group(2).replace(" ", ",")
|
||||||
die("malformed cpus line: $cpus_line\n");
|
|
||||||
}
|
mem_free_match = re.match(r"^ *node " + node_id + " free: (\d+) \S+$", mem_free_line)
|
||||||
}
|
if mem_free_match:
|
||||||
print("numactl -m $best_node_id -C $best_cpus --");
|
free_size = mem_free_match.group(1)
|
||||||
} else {
|
if int(free_size) > int(best_free_size):
|
||||||
die("malformed head line: $head_line\n");
|
best_node_id = node_id
|
||||||
}
|
best_cpus = cpus
|
||||||
}
|
best_free_size = free_size
|
||||||
|
else:
|
||||||
|
sys.exit("[ERROR] Malformed mem free line: " + mem_free_line)
|
||||||
|
|
||||||
|
else:
|
||||||
|
sys.exit("[ERROR] Malformed cpus line: " + cpu_line)
|
||||||
|
|
||||||
|
sys.stdout.write("numactl -m " + best_node_id + " -C " + best_cpus + " --")
|
||||||
|
else:
|
||||||
|
sys.exit("[ERROR] Malformed head line: " + head_line)
|
||||||
|
|||||||
Reference in New Issue
Block a user