-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cc
66 lines (51 loc) · 1.9 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ureadahead-diff/ureadahead_diff.h"
#include <base/logging.h>
#include <brillo/flag_helper.h>
namespace {
constexpr char help[] =
"Calculate difference of two ureadahead packs. Output is written into "
"three packs.\nCommon contains the same read operations from two source "
"packs. Difference packs\ncontain unique read operations for the "
"corresponding source pack.";
}
int main(int argc, char* argv[]) {
DEFINE_string(source1, "", "First source pack to process");
DEFINE_string(source2, "", "Second source pack to process");
DEFINE_string(common, "", "Common pack output name");
DEFINE_string(difference1, "", "Output difference for the first pack");
DEFINE_string(difference2, "", "Output difference for the second pack");
brillo::FlagHelper::Init(argc, argv, help);
if (FLAGS_source1.empty() || FLAGS_source2.empty() || FLAGS_common.empty() ||
FLAGS_difference1.empty() || FLAGS_difference2.empty()) {
LOG(ERROR) << "Not all arguments are provided";
return 1;
}
ureadahead_diff::Pack pack1;
ureadahead_diff::Pack pack2;
if (!pack1.Read(FLAGS_source1)) {
LOG(ERROR) << "Failed to read " << FLAGS_source1;
return 2;
}
if (!pack2.Read(FLAGS_source2)) {
LOG(ERROR) << "Failed to read " << FLAGS_source2;
return 3;
}
ureadahead_diff::Pack common;
ureadahead_diff::Pack::CalculateDifference(&pack1, &pack2, &common);
if (!common.Write(FLAGS_common)) {
LOG(ERROR) << "Failed to write " << FLAGS_common;
return 4;
}
if (!pack1.Write(FLAGS_difference1)) {
LOG(ERROR) << "Failed to write " << FLAGS_difference1;
return 5;
}
if (!pack2.Write(FLAGS_difference2)) {
LOG(ERROR) << "Failed to write " << FLAGS_difference2;
return 6;
}
return 0;
}