2 * Copyright (C) 2015 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include <base/logging.h>
27 void PrintIndented(size_t indent, const char* fmt, ...) {
30 printf("%*s", static_cast<int>(indent * 2), "");
35 bool IsPowerOfTwo(uint64_t value) {
36 return (value != 0 && ((value & (value - 1)) == 0));
39 bool NextArgumentOrError(const std::vector<std::string>& args, size_t* pi) {
40 if (*pi + 1 == args.size()) {
41 LOG(ERROR) << "No argument following " << args[*pi] << " option. Try `simpleperf help "
49 void GetEntriesInDir(const std::string& dirpath, std::vector<std::string>* files,
50 std::vector<std::string>* subdirs) {
51 if (files != nullptr) {
54 if (subdirs != nullptr) {
57 DIR* dir = opendir(dirpath.c_str());
59 PLOG(DEBUG) << "can't open dir " << dirpath;
63 while ((entry = readdir(dir)) != nullptr) {
64 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
67 if (entry->d_type == DT_DIR) {
68 if (subdirs != nullptr) {
69 subdirs->push_back(entry->d_name);
72 if (files != nullptr) {
73 files->push_back(entry->d_name);