57 {
58 opterr = 0;
59 int long_index = 0;
60 const std::string short_opts = "hco:HO:";
61 static const struct option long_opts[] = {
62 {"help", no_argument, nullptr, 'h'},
63 {"cpuprofile", no_argument, nullptr, 'c'},
64 {"profile_filename", required_argument, nullptr, 'o'},
65 {"heapprofile", no_argument, nullptr, 'H'},
66 {"heapprofile_filename", required_argument, nullptr, 'O'},
67 {NULL, no_argument, nullptr, 0}};
68
69
70 std::string cmd("");
71 for (int i = 0; i < argc; ++i) {
72 cmd += argv[i];
73 cmd += " ";
74 }
75 AINFO <<
"command: " << cmd;
76
77 do {
78 int opt =
79 getopt_long(argc, argv, short_opts.c_str(), long_opts, &long_index);
80 if (opt == -1) {
81 break;
82 }
83 switch (opt) {
84 case 'c':
85 enable_cpuprofile_ = true;
86 break;
87 case 'o':
88 profile_filename_ = std::string(optarg);
89 break;
90 case 'H':
91 enable_heapprofile_ = true;
92 break;
93 case 'O':
94 heapprofile_filename_ = std::string(optarg);
95 break;
96 case 'h':
98 exit(0);
99 default:
100 break;
101 }
102 } while (true);
103
104 if (optind < argc) {
105 AINFO <<
"Found non-option ARGV-element \"" << argv[optind++] <<
"\"";
107 exit(1);
108 }
109}