qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Allow setting qemu process name
@ 2009-07-01  9:32 Andi Kleen
  2009-07-01 13:29 ` Anthony Liguori
  2009-07-23 11:47 ` Todd T. Fries
  0 siblings, 2 replies; 19+ messages in thread
From: Andi Kleen @ 2009-07-01  9:32 UTC (permalink / raw)
  To: qemu-devel


[this is a port of a old KVM userland patch I had; Avi back then suggested to 
submit it to qemu]

Set the Linux process name to the name argument specified with "-name". I find
this useful to see which guests are taking CPU time in top.

This doesn't affect ps, which checks argv[0], but rewriting the 
environment uses much more code, so I only used this simple way.

Signed-off-by: Andi Kleen <ak@linux.intel.com>

diff --git a/vl.c b/vl.c
index 7b7489c..584c48e 100644
--- a/vl.c
+++ b/vl.c
@@ -68,6 +68,7 @@
 #include <pty.h>
 #include <malloc.h>
 #include <linux/rtc.h>
+#include <sys/prctl.h>
 
 /* For the benefit of older linux systems which don't supply it,
    we use a local copy of hpet.h. */
@@ -526,6 +527,19 @@ void hw_error(const char *fmt, ...)
     va_end(ap);
     abort();
 }
+
+static void set_proc_name(const char *prefix, const char *s)
+{
+#ifdef __linux__
+   char name[16];
+   if (!s)
+       return;
+   /* Could rewrite argv[0] too, but that's a bit more complicated.
+      This simple way is enough for `top'. */
+    snprintf(name, sizeof name, "%s-%.10s", prefix, s);
+    prctl(PR_SET_NAME, name);
+#endif    	
+}
  
 /***************/
 /* ballooning */
@@ -6008,11 +6022,15 @@ int main(int argc, char **argv, char **envp)
     if (kvm_enabled()) {
         int ret;
 
+        set_proc_name("kvm", qemu_name);
+
         ret = kvm_init(smp_cpus);
         if (ret < 0) {
             fprintf(stderr, "failed to initialize KVM\n");
             exit(1);
         }
+    } else {
+        set_proc_name("qemu", qemu_name);
     }
 
     if (monitor_device) {
-- 
ak@linux.intel.com -- Speaking for myself only.

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2009-07-24  9:34 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-01  9:32 [Qemu-devel] [PATCH] Allow setting qemu process name Andi Kleen
2009-07-01 13:29 ` Anthony Liguori
2009-07-01 13:43   ` Andi Kleen
2009-07-01 13:57     ` Anthony Liguori
2009-07-01 14:06       ` Andi Kleen
2009-07-01 15:08         ` Avi Kivity
2009-07-01 16:27         ` Jamie Lokier
2009-07-01 15:07   ` Avi Kivity
2009-07-01 16:19     ` Luiz Capitulino
2009-07-01 16:27       ` Avi Kivity
2009-07-01 16:34         ` Luiz Capitulino
2009-07-01 16:43           ` Avi Kivity
2009-07-01 17:02             ` Jamie Lokier
2009-07-01 17:43     ` Stefan Weil
2009-07-23 11:47 ` Todd T. Fries
2009-07-23 12:01   ` Andi Kleen
2009-07-23 12:58     ` Todd T. Fries
2009-07-23 14:30       ` Andi Kleen
2009-07-24  9:34   ` Richard W.M. Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).