1 (* Memory info command for virtual domains.
2 (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
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.
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.
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.
19 Implements 'virt-mem capture' command.
25 open Virt_mem_gettext.Gettext
27 (* This will contain what is passed by the user as '-o' option. *)
28 let output_filename = ref ""
30 (* Early argument check. *)
32 (* -o flag must have been specified. *)
33 let output_filename = !output_filename in
34 if output_filename = "" then (
35 prerr_endline (s_"virt-mem capture: '-o memoryimage' option is required");
39 (* Capture the images before kernel symbol analysis is attempted.
40 * Just save them to the output file(s).
42 let rec beforeksyms debug = function
45 (s_"virt-mem capture: warning: no kernel images were captured")
47 (* Single image is saved to output_filename. *)
48 save_image image !output_filename
50 (* Multiple images are saved to output_filename.ID where ID
51 * is the domain ID (if known) or a mangled domain name.
54 fun ((domid, domname, _, _) as image) ->
56 !output_filename ^ "." ^
58 | Some id -> string_of_int id
61 | ('a'..'z'|'A'..'Z'|'0'..'9'|'_' as c) -> String.make 1 c
64 String.replace_chars f domname in
65 save_image image filename
68 and save_image (_, domname, arch, mmap) filename =
69 printf (f_"virt-mem capture: saving kernel image from %s to filename %s\n")
74 let summary = s_"capture memory image for post-mortem analysis"
75 let description = s_"Capture a memory image to a file for later post-mortem
76 analysis. Use the '-o memoryimage' option to specify the
79 Other tools can load the memory image using the '-t' option."
82 "-o", Arg.Set_string output_filename,
83 "memoryimage " ^s_"Set output filename"
88 ~external_cmd:false ~extra_args
89 ~argcheck ~beforeksyms
90 "capture" summary description