Closed KJ7LNW closed 1 year ago
Yes I would be interested in this. First make sure the code ports over to Dool (should be simple). Once we have proof of concept running on Dool we can figure out where to place it. I'm thinking a plug-in?
Here is a working patch.
How would you fold it in as a plugin so it gets used by options like --top-bio
and --top-cpu
?
diff --git a/dool b/dool
index bfd97cf..7f8b661 100755
--- a/dool
+++ b/dool
@@ -2106,6 +2106,12 @@ def basename(name):
return os.path.basename(name)
return name
+def index_containing_substring(the_list, substring):
+ for i, s in enumerate(the_list):
+ if substring in s:
+ return i
+ return -1
+
def getnamebypid(pid, name):
"Return the name of a process by taking best guesses and exclusion"
ret = None
@@ -2123,6 +2129,14 @@ def getnamebypid(pid, name):
if ret.startswith('-'):
ret = basename(cmdline[-2])
if ret.startswith('-'): raise
+ if "qemu" in cmdline[0]:
+ idx = index_containing_substring(cmdline, '-name')
+ if idx >= 0:
+ # Match "foo" from "guest=foo,otherstuff=bar", or match "foo"
+ # for older libvirts that do not have var=val formatted
+ # content.
+ m = re.match("(?:^[^=]+=)?([^,]+)", cmdline[idx+1])
+ ret = m.group(1)
if not ret: raise
except:
ret = basename(name)
What hypervisor are you running that this matches against? I'm running Proxmox and I see qemu
processes like so:
root 52293 58.1 1.9 12817400 10557092 ? Sl Apr12 122227:05 /usr/bin/kvm -id 213 -name TestDHCPServer,debug-threads=on -no-shutdown...
Interesting. We are using vanilla libvirt+KVM on Oracle Linux 9. It looks like this:
/usr/libexec/qemu-kvm -name guest=test.ewheeler.net,debug-threads=on ...
Maybe this should be the regex:
>>> print(re.match("^(?:guest=)?([^,=]+)", "foo,bar=baz").group(1))
foo
>>> print(re.match("^(?:guest=)?([^,=]+)", "guest=foo,bar=baz").group(1))
foo
>>> print(re.match("^(?:guest=)?([^,=]+)", "foo").group(1))
foo
Checkout the code I'm working on in #48. It's a slightly modified version of what you had.
That looks great! Should self.width
be configurable?
@KJ7LNW I'm not sure the best approach to the width. I toyed around with the idea of calculating the longest process name and using that. That doesn't work if your process name is ls
but your longest process is 40 chars long. You'll end up with a lot of extra whitespace. I'm inclined to just leave it hardcoded at 20 for now until someone can come up with a better idea.
Does the code in #48 capture the name for you? If it works for you I'll land the PR.
I went ahead and landed the code in #48. Give it a test and if it doesn't work let me know.
I'm prepping for a new release by the end of the work.
SUMMARY
Return the VM name in calls to
getnamebypid
ISSUE TYPE
About 10 years ago I wrote a simple patch for Dag's dstat to show the virtual machine name in the
most-expensive
process column. We only ever used this internally.I have not yet looked at
dool
code to see if this patch is even compatible, because first I want to ask if this is something that would be of interest.If so:
OS / ENVIRONMENT
Linux