xref: /aosp_15_r20/external/perfetto/src/profiling/symbolizer/filesystem_posix.cc (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1*6dbdd20aSAndroid Build Coastguard Worker /*
2*6dbdd20aSAndroid Build Coastguard Worker  * Copyright (C) 2020 The Android Open Source Project
3*6dbdd20aSAndroid Build Coastguard Worker  *
4*6dbdd20aSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*6dbdd20aSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*6dbdd20aSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*6dbdd20aSAndroid Build Coastguard Worker  *
8*6dbdd20aSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*6dbdd20aSAndroid Build Coastguard Worker  *
10*6dbdd20aSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*6dbdd20aSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*6dbdd20aSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*6dbdd20aSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*6dbdd20aSAndroid Build Coastguard Worker  * limitations under the License.
15*6dbdd20aSAndroid Build Coastguard Worker  */
16*6dbdd20aSAndroid Build Coastguard Worker 
17*6dbdd20aSAndroid Build Coastguard Worker #include "src/profiling/symbolizer/filesystem.h"
18*6dbdd20aSAndroid Build Coastguard Worker 
19*6dbdd20aSAndroid Build Coastguard Worker #include "perfetto/base/build_config.h"
20*6dbdd20aSAndroid Build Coastguard Worker 
21*6dbdd20aSAndroid Build Coastguard Worker #if !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
22*6dbdd20aSAndroid Build Coastguard Worker #if PERFETTO_BUILDFLAG(PERFETTO_LOCAL_SYMBOLIZER)
23*6dbdd20aSAndroid Build Coastguard Worker #include <fts.h>
24*6dbdd20aSAndroid Build Coastguard Worker #include <sys/stat.h>
25*6dbdd20aSAndroid Build Coastguard Worker #endif
26*6dbdd20aSAndroid Build Coastguard Worker 
27*6dbdd20aSAndroid Build Coastguard Worker #include <string>
28*6dbdd20aSAndroid Build Coastguard Worker 
29*6dbdd20aSAndroid Build Coastguard Worker #include "perfetto/ext/base/file_utils.h"
30*6dbdd20aSAndroid Build Coastguard Worker 
31*6dbdd20aSAndroid Build Coastguard Worker namespace perfetto {
32*6dbdd20aSAndroid Build Coastguard Worker namespace profiling {
33*6dbdd20aSAndroid Build Coastguard Worker #if PERFETTO_BUILDFLAG(PERFETTO_LOCAL_SYMBOLIZER)
WalkDirectories(std::vector<std::string> dirs,FileCallback fn)34*6dbdd20aSAndroid Build Coastguard Worker bool WalkDirectories(std::vector<std::string> dirs, FileCallback fn) {
35*6dbdd20aSAndroid Build Coastguard Worker   std::vector<char*> dir_cstrs;
36*6dbdd20aSAndroid Build Coastguard Worker   dir_cstrs.reserve(dirs.size());
37*6dbdd20aSAndroid Build Coastguard Worker   for (std::string& dir : dirs)
38*6dbdd20aSAndroid Build Coastguard Worker     dir_cstrs.emplace_back(&dir[0]);
39*6dbdd20aSAndroid Build Coastguard Worker   dir_cstrs.push_back(nullptr);
40*6dbdd20aSAndroid Build Coastguard Worker   base::ScopedResource<FTS*, fts_close, nullptr> fts(
41*6dbdd20aSAndroid Build Coastguard Worker       fts_open(&dir_cstrs[0], FTS_LOGICAL | FTS_NOCHDIR, nullptr));
42*6dbdd20aSAndroid Build Coastguard Worker   if (!fts) {
43*6dbdd20aSAndroid Build Coastguard Worker     PERFETTO_PLOG("fts_open");
44*6dbdd20aSAndroid Build Coastguard Worker     return false;
45*6dbdd20aSAndroid Build Coastguard Worker   }
46*6dbdd20aSAndroid Build Coastguard Worker   FTSENT* ent;
47*6dbdd20aSAndroid Build Coastguard Worker   while ((ent = fts_read(*fts))) {
48*6dbdd20aSAndroid Build Coastguard Worker     if (ent->fts_info & FTS_F)
49*6dbdd20aSAndroid Build Coastguard Worker       fn(ent->fts_path, static_cast<size_t>(ent->fts_statp->st_size));
50*6dbdd20aSAndroid Build Coastguard Worker   }
51*6dbdd20aSAndroid Build Coastguard Worker   return true;
52*6dbdd20aSAndroid Build Coastguard Worker }
53*6dbdd20aSAndroid Build Coastguard Worker 
54*6dbdd20aSAndroid Build Coastguard Worker #else
55*6dbdd20aSAndroid Build Coastguard Worker bool WalkDirectories(std::vector<std::string>, FileCallback) {
56*6dbdd20aSAndroid Build Coastguard Worker   return false;
57*6dbdd20aSAndroid Build Coastguard Worker }
58*6dbdd20aSAndroid Build Coastguard Worker #endif
59*6dbdd20aSAndroid Build Coastguard Worker 
60*6dbdd20aSAndroid Build Coastguard Worker }  // namespace profiling
61*6dbdd20aSAndroid Build Coastguard Worker }  // namespace perfetto
62*6dbdd20aSAndroid Build Coastguard Worker 
63*6dbdd20aSAndroid Build Coastguard Worker #endif  // !PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
64