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/>.
33 #include "readahead-common.h"
35 unsigned arg_files_max = 16*1024;
36 off_t arg_file_size_max = READAHEAD_FILE_SIZE_MAX;
37 usec_t arg_timeout = 2*USEC_PER_MINUTE;
39 static int help(void) {
41 printf("%s [OPTIONS...] collect [DIRECTORY]\n\n"
42 "Collect read-ahead data on early boot.\n\n"
43 " -h --help Show this help\n"
44 " --version Show package version\n"
45 " --max-files=INT Maximum number of files to read ahead\n"
46 " --file-size-max=BYTES Maximum size of files to read ahead\n"
47 " --timeout=USEC Maximum time to spend collecting data\n\n\n",
48 program_invocation_short_name);
50 printf("%s [OPTIONS...] replay [DIRECTORY]\n\n"
51 "Replay collected read-ahead data on early boot.\n\n"
52 " -h --help Show this help\n"
53 " --version Show package version\n"
54 " --file-size-max=BYTES Maximum size of files to read ahead\n\n\n",
55 program_invocation_short_name);
57 printf("%s [OPTIONS...] analyze [PACK FILE]\n\n"
58 "Analyze collected read-ahead data.\n\n"
59 " -h --help Show this help\n"
60 " --version Show package version\n",
61 program_invocation_short_name);
66 static int parse_argv(int argc, char *argv[]) {
75 static const struct option options[] = {
76 { "help", no_argument, NULL, 'h' },
77 { "version", no_argument, NULL, ARG_VERSION },
78 { "files-max", required_argument, NULL, ARG_FILES_MAX },
79 { "file-size-max", required_argument, NULL, ARG_FILE_SIZE_MAX },
80 { "timeout", required_argument, NULL, ARG_TIMEOUT },
89 while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) {
98 puts(SYSTEMD_FEATURES);
102 if (safe_atou(optarg, &arg_files_max) < 0 || arg_files_max <= 0) {
103 log_error("Failed to parse maximum number of files %s.", optarg);
108 case ARG_FILE_SIZE_MAX: {
109 unsigned long long ull;
111 if (safe_atollu(optarg, &ull) < 0 || ull <= 0) {
112 log_error("Failed to parse maximum file size %s.", optarg);
116 arg_file_size_max = (off_t) ull;
121 if (parse_sec(optarg, &arg_timeout) < 0 || arg_timeout <= 0) {
122 log_error("Failed to parse timeout %s.", optarg);
132 assert_not_reached("Unhandled option");
136 if (optind != argc-1 &&
145 int main(int argc, char *argv[]) {
148 log_set_target(LOG_TARGET_SAFE);
149 log_parse_environment();
154 r = parse_argv(argc, argv);
156 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
158 if (streq(argv[optind], "collect"))
159 return main_collect(argv[optind+1]);
160 else if (streq(argv[optind], "replay"))
161 return main_replay(argv[optind+1]);
162 else if (streq(argv[optind], "analyze"))
163 return main_analyze(argv[optind+1]);
165 log_error("Unknown verb %s.", argv[optind]);