-
Notifications
You must be signed in to change notification settings - Fork 389
/
WdtFlags.cpp
80 lines (69 loc) · 2.5 KB
/
WdtFlags.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "WdtFlags.h"
#include "WdtOptions.h"
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <iostream>
#include "Protocol.h"
#include "WdtFlags.cpp.inc"
WDT_FLAG_DEFINITION(
string, WDT_FLAG_SYM(option_type),
facebook::wdt::WdtOptions::FLASH_OPTION_TYPE,
"WDT option type. Options are initialized to different values "
"depending on the type. Individual options can still be changed using "
"specific flags. Use -" WDT_FLAG_STR(print_options) " to see values")
namespace facebook {
namespace wdt {
const std::string FLAGS_PREFIX = WDT_TOSTR(WDT_LONG_PREFIX);
// Internal utilities
std::string getOptionNameFromFlagName(const std::string &flagName) {
#ifndef STANDALONE_APP
// extra wdt_ prefix is added in this case
if (flagName.compare(0, FLAGS_PREFIX.size(), FLAGS_PREFIX) == 0) {
// flagname begins with wdt_
return flagName.substr(FLAGS_PREFIX.size());
}
#endif
return flagName;
}
// getFlagNameFromOptionName is WDT_FLAG_STR()
std::set<std::string> getUserSpecifiedOptions() {
std::set<std::string> userSpecifiedFlags;
std::vector<google::CommandLineFlagInfo> allFlags;
google::GetAllFlags(&allFlags);
for (const auto &flag : allFlags) {
if (!flag.is_default) {
// is_default is false if the flag has been specified in the cmd line.
// Even if the value specified is same as the default value, this boolean
// is still marked as false. If the flag is directly like
// FLAGS_num_ports=1, is_default won't change. But, if it set using
// SetCommandLineOption, this will change.
userSpecifiedFlags.emplace(getOptionNameFromFlagName(flag.name));
}
}
return userSpecifiedFlags;
}
void WdtFlags::initializeFromFlags() {
LOG(INFO) << "Running WDT " << Protocol::getFullVersion();
#define ASSIGN_OPT
#include "WdtFlags.cpp.inc" //nolint
#undef ASSIGN_OPT
std::set<std::string> userSpecifiedFlags = getUserSpecifiedOptions();
WdtOptions::getMutable().modifyOptions(WDT_FLAG_VAR(option_type),
userSpecifiedFlags);
}
void WdtFlags::printOptions(std::ostream &out) {
out << "Options current value:" << std::endl;
#define PRINT_OPT
#include "WdtFlags.cpp.inc" //nolint
#undef PRINT_OPT
}
}
}