]> git.proxmox.com Git - pve-common.git/commitdiff
CpuSet: add helper to format/print cpu sets.
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 28 Oct 2016 04:56:55 +0000 (06:56 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 28 Oct 2016 04:56:55 +0000 (06:56 +0200)
src/PVE/CpuSet.pm

index ef660b5c52ca04d2fe6fc2b5de6d905790ba4232..4004bb3bab1a620f137068f279e03982447bf77e 100644 (file)
@@ -136,4 +136,35 @@ sub is_equal {
     return 1;
 }
 
     return 1;
 }
 
+sub short_string {
+    my ($self) = @_;
+
+    my @members = $self->members();
+
+    my $res = '';
+    my ($last, $next);
+    foreach my $cpu (@members) {
+       if (!defined($last)) {
+           $last = $next = $cpu;
+       } elsif (($next + 1) == $cpu) {
+           $next = $cpu;
+       } else {
+           $res .= ',' if length($res);
+           $res .= "$last-$next";
+           $last = $next = undef;
+       }
+    }
+
+    if (defined($last)) {
+       $res .= ',' if length($res);
+       if ($last != $next) {
+           $res .= "$last-$next";
+       } else {
+           $res .= "$last";
+       }
+    }
+
+    return $res;
+}
+
 1;
 1;