Print swapper task details.
[virt-mem.git] / ps / virt_ps.ml
1 (* Memory info for virtual domains.
2    (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
3    http://libvirt.org/
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *)
19
20 open Printf
21
22 open Virt_mem_gettext.Gettext
23 open Virt_mem_utils
24 open Virt_mem_types
25
26
27 let run debug ({ domname = domname; mem = mem }, ksymmap, utsname) =
28   try
29     let kernel_version =
30       match utsname with
31       | None ->
32           eprintf (f_"%s: could not guess kernel version\n") domname;
33           raise Exit
34       | Some { kernel_release = v } -> v in
35
36     if not (Kernel_task_struct.known kernel_version) then (
37       eprintf (f_"%s: %s: unknown kernel version
38 Try a newer version of virt-mem, or if the guest is not from a
39 supported Linux distribution, see this page about adding support:
40   http://et.redhat.com/~rjones/virt-mem/faq.html\n") domname kernel_version;
41       raise Exit
42     );
43
44     let init_task =
45       let addr =
46         try Ksymmap.find "init_task" ksymmap
47         with Not_found ->
48           eprintf (f_"%s: could not find init_task in kernel image\n") domname;
49           raise Exit in
50       let addr =
51         (Virt_mem_mmap.unsafe_typed_addr_of_addr addr :
52            [ `task_struct ] Virt_mem_mmap.typed_addr) in
53       Kernel_task_struct.get kernel_version mem addr in
54
55     printf "comm = %S prio = %Ld state = %Ld static_prio = %Ld tasks'next = %Lx\n"
56       init_task.Kernel_task_struct.comm
57       init_task.Kernel_task_struct.prio
58       init_task.Kernel_task_struct.state
59       init_task.Kernel_task_struct.static_prio
60       (Virt_mem_mmap.unsafe_addr_of_typed_addr init_task.Kernel_task_struct.tasks'next);
61
62   with Exit -> ()
63
64 let summary = s_"list processes in virtual machine"
65 let description = s_"\
66 virt-ps prints a process listing for virtual machines running under
67 libvirt."
68
69 let () = Virt_mem.register "ps" summary description ~run