1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2012 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
32 #include "readahead-common.h"
34 unsigned arg_files_max = 16*1024;
35 off_t arg_file_size_max = READAHEAD_FILE_SIZE_MAX;
36 usec_t arg_timeout = 2*USEC_PER_MINUTE;
38 static int help(void) {
40 printf("%s [OPTIONS...] collect [DIRECTORY]\n\n"
41 "Collect read-ahead data on early boot.\n\n"
42 " -h --help Show this help\n"
43 " --max-files=INT Maximum number of files to read ahead\n"
44 " --file-size-max=BYTES Maximum size of files to read ahead\n"
45 " --timeout=USEC Maximum time to spend collecting data\n\n\n",
46 program_invocation_short_name);
48 printf("%s [OPTIONS...] replay [DIRECTORY]\n\n"
49 "Replay collected read-ahead data on early boot.\n\n"
50 " -h --help Show this help\n"
51 " --file-size-max=BYTES Maximum size of files to read ahead\n\n\n",
52 program_invocation_short_name);
54 printf("%s [OPTIONS...] analyze [PACK FILE]\n\n"
55 "Analyze collected read-ahead data.\n\n"
56 " -h --help Show this help\n",
57 program_invocation_short_name);
62 static int parse_argv(int argc, char *argv[]) {
65 ARG_FILES_MAX = 0x100,
70 static const struct option options[] = {
71 { "help", no_argument, NULL, 'h' },
72 { "files-max", required_argument, NULL, ARG_FILES_MAX },
73 { "file-size-max", required_argument, NULL, ARG_FILE_SIZE_MAX },
74 { "timeout", required_argument, NULL, ARG_TIMEOUT },
83 while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
92 if (safe_atou(optarg, &arg_files_max) < 0 || arg_files_max <= 0) {
93 log_error("Failed to parse maximum number of files %s.", optarg);
98 case ARG_FILE_SIZE_MAX: {
99 unsigned long long ull;
101 if (safe_atollu(optarg, &ull) < 0 || ull <= 0) {
102 log_error("Failed to parse maximum file size %s.", optarg);
106 arg_file_size_max = (off_t) ull;
111 if (parse_sec(optarg, &arg_timeout) < 0 || arg_timeout <= 0) {
112 log_error("Failed to parse timeout %s.", optarg);
122 log_error("Unknown option code %c", c);
127 if (optind != argc-1 &&
136 int main(int argc, char *argv[]) {
139 log_set_target(LOG_TARGET_SAFE);
140 log_parse_environment();
145 r = parse_argv(argc, argv);
147 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
149 if (streq(argv[optind], "collect"))
150 return main_collect(argv[optind+1]);
151 else if (streq(argv[optind], "replay"))
152 return main_replay(argv[optind+1]);
153 else if (streq(argv[optind], "analyze"))
154 return main_analyze(argv[optind+1]);
156 log_error("Unknown verb %s.", argv[optind]);