PFFFT: Use Abseil flags

PiperOrigin-RevId: 444790093
Change-Id: I01fdac7ff07a3ae65bec32cd20dba2c63841c9a7
This commit is contained in:
Christian Blichmann 2022-04-27 01:31:41 -07:00 committed by Copybara-Service
parent 6cbde854d6
commit 1a856e1932
2 changed files with 7 additions and 22 deletions

View File

@ -100,6 +100,8 @@ add_executable(pffft_sandboxed
main_pffft_sandboxed.cc main_pffft_sandboxed.cc
) )
target_link_libraries(pffft_sandboxed PRIVATE target_link_libraries(pffft_sandboxed PRIVATE
absl::flags
absl::flags_parse
sapi_contrib::pffft sapi_contrib::pffft
sapi::sapi sapi::sapi
) )

View File

@ -22,12 +22,10 @@
#include <glog/logging.h> #include <glog/logging.h>
#include "pffft_sapi.sapi.h" // NOLINT(build/include) #include "pffft_sapi.sapi.h" // NOLINT(build/include)
#include "sandboxed_api/util/flag.h" #include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "sandboxed_api/vars.h" #include "sandboxed_api/vars.h"
ABSL_DECLARE_FLAG(string, sandbox2_danger_danger_permit_all);
ABSL_DECLARE_FLAG(string, sandbox2_danger_danger_permit_all_and_log);
class PffftSapiSandbox : public PffftSandbox { class PffftSapiSandbox : public PffftSandbox {
public: public:
std::unique_ptr<sandbox2::Policy> ModifyPolicy(sandbox2::PolicyBuilder*) { std::unique_ptr<sandbox2::Policy> ModifyPolicy(sandbox2::PolicyBuilder*) {
@ -47,27 +45,14 @@ class PffftSapiSandbox : public PffftSandbox {
} }
}; };
// output_format flag determines whether the output shows information in detail ABSL_FLAG(bool, verbose_output, true, "Whether to display verbose output");
// or not. By default, the flag is set as 0, meaning an elaborate display
// (see ShowOutput method).
static bool ValidateFlag(const char* flagname, int32_t value) {
if (value >= 0 && value < 32768) {
return true;
}
LOG(ERROR) << "Invalid value for --" << flagname << ".";
return false;
}
DEFINE_int32(output_format, 0, "Value to specific the output format.");
DEFINE_validator(output_format, &ValidateFlag);
double UclockSec() { return static_cast<double>(clock()) / CLOCKS_PER_SEC; } double UclockSec() { return static_cast<double>(clock()) / CLOCKS_PER_SEC; }
void ShowOutput(const char* name, int n, int complex, float flops, float t0, void ShowOutput(const char* name, int n, int complex, float flops, float t0,
float t1, int max_iter) { float t1, int max_iter) {
float mflops = flops / 1e6 / (t1 - t0 + 1e-16); float mflops = flops / 1e6 / (t1 - t0 + 1e-16);
if (FLAGS_output_format) { if (absl::GetFlag(FLAGS_verbose_output)) {
if (flops != -1) { if (flops != -1) {
printf("|%9.0f ", mflops); printf("|%9.0f ", mflops);
} else { } else {
@ -193,11 +178,9 @@ absl::Status PffftMain() {
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// Initialize Google's logging library. absl::ParseCommandLine(argc, argv);
google::InitGoogleLogging(argv[0]); google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
if (absl::Status status = PffftMain(); !status.ok()) { if (absl::Status status = PffftMain(); !status.ok()) {
LOG(ERROR) << "Initialization failed: " << status.ToString(); LOG(ERROR) << "Initialization failed: " << status.ToString();
return EXIT_FAILURE; return EXIT_FAILURE;