• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 #ifndef SRC_TRACED_PROBES_PACKAGES_LIST_PACKAGES_LIST_DATA_SOURCE_H_
18 #define SRC_TRACED_PROBES_PACKAGES_LIST_PACKAGES_LIST_DATA_SOURCE_H_
19 
20 #include <functional>
21 #include <memory>
22 #include <set>
23 
24 #include "perfetto/base/scoped_file.h"
25 #include "perfetto/base/task_runner.h"
26 #include "perfetto/trace/android/packages_list.pbzero.h"
27 #include "perfetto/tracing/core/basic_types.h"
28 #include "perfetto/tracing/core/data_source_config.h"
29 #include "perfetto/tracing/core/packages_list_config.h"
30 #include "src/traced/probes/probes_data_source.h"
31 
32 namespace perfetto {
33 
34 class TraceWriter;
35 
36 struct Package {
37   std::string name;
38   uint64_t uid = 0;
39   bool debuggable = false;
40   bool profileable_from_shell = false;
41   int64_t version_code = 0;
42 };
43 
44 bool ReadPackagesListLine(char* line, Package* package);
45 bool ParsePackagesListStream(protos::pbzero::PackagesList* packages_list,
46                              const base::ScopedFstream& fs,
47                              const std::set<std::string>& package_name_filter);
48 
49 class PackagesListDataSource : public ProbesDataSource {
50  public:
51   static constexpr int kTypeId = 7;
52   PackagesListDataSource(const DataSourceConfig& ds_config,
53                          TracingSessionID session_id,
54                          std::unique_ptr<TraceWriter> writer);
55   // ProbesDataSource implementation.
56   void Start() override;
57   void Flush(FlushRequestID, std::function<void()> callback) override;
58 
59   ~PackagesListDataSource() override;
60 
61  private:
62   // If empty, include all package names. std::set over std::unordered_set as
63   // this should be trivially small (or empty) in practice, and the latter uses
64   // ever so slightly more memory.
65   std::set<std::string> package_name_filter_;
66   std::unique_ptr<TraceWriter> writer_;
67 };
68 
69 }  // namespace perfetto
70 
71 #endif  // SRC_TRACED_PROBES_PACKAGES_LIST_PACKAGES_LIST_DATA_SOURCE_H_
72