1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include "src/profiling/symbolizer/filesystem.h"
18
19 #if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
20
21 #include <Windows.h>
22
23 namespace perfetto {
24 namespace profiling {
25
WalkDirectories(std::vector<std::string> dirs,FileCallback fn)26 bool WalkDirectories(std::vector<std::string> dirs, FileCallback fn) {
27 std::vector<std::string> sub_dirs;
28 for (const std::string& dir : dirs) {
29 WIN32_FIND_DATAA file;
30 HANDLE fh = FindFirstFileA((dir + "\\*").c_str(), &file);
31 if (fh != INVALID_HANDLE_VALUE) {
32 do {
33 std::string file_path = dir + "\\" + file.cFileName;
34 if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
35 if (strcmp(file.cFileName, ".") != 0 &&
36 strcmp(file.cFileName, "..") != 0) {
37 sub_dirs.push_back(file_path);
38 }
39 } else {
40 ULARGE_INTEGER size;
41 size.HighPart = file.nFileSizeHigh;
42 size.LowPart = file.nFileSizeLow;
43 fn(file_path.c_str(), size.QuadPart);
44 }
45 } while (FindNextFileA(fh, &file));
46 }
47 FindClose(fh);
48 }
49 if (!sub_dirs.empty()) {
50 WalkDirectories(sub_dirs, fn);
51 }
52 return true;
53 }
54
55 } // namespace profiling
56 } // namespace perfetto
57
58 #endif // PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
59