• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SRC_TRACED_PROBES_INITIAL_DISPLAY_STATE_INITIAL_DISPLAY_STATE_DATA_SOURCE_H_
18 #define SRC_TRACED_PROBES_INITIAL_DISPLAY_STATE_INITIAL_DISPLAY_STATE_DATA_SOURCE_H_
19 
20 #include <memory>
21 
22 #include "perfetto/ext/base/optional.h"
23 #include "perfetto/ext/base/weak_ptr.h"
24 #include "perfetto/ext/tracing/core/trace_writer.h"
25 #include "src/traced/probes/probes_data_source.h"
26 
27 namespace perfetto {
28 
29 namespace base {
30 class TaskRunner;
31 }
32 
33 class InitialDisplayStateDataSource : public ProbesDataSource {
34  public:
35   static const ProbesDataSource::Descriptor descriptor;
36 
37   InitialDisplayStateDataSource(base::TaskRunner* task_runner,
38                                 const DataSourceConfig& ds_config,
39                                 TracingSessionID session_id,
40                                 std::unique_ptr<TraceWriter> writer);
41 
42   // ProbesDataSource implementation.
43   void Start() override;
44   void Flush(FlushRequestID, std::function<void()> callback) override;
45 
46   // Virtual for testing.
47   virtual const base::Optional<std::string> ReadProperty(
48       const std::string name);
49 
50  private:
51   void Tick();
52   base::WeakPtr<InitialDisplayStateDataSource> GetWeakPtr() const;
53   void WriteState();
54 
55   base::TaskRunner* const task_runner_;
56   std::unique_ptr<TraceWriter> writer_;
57   uint32_t poll_period_ms_ = 0;
58   base::WeakPtrFactory<InitialDisplayStateDataSource>
59       weak_factory_;  // Keep last.
60 };
61 
62 }  // namespace perfetto
63 
64 #endif  // SRC_TRACED_PROBES_INITIAL_DISPLAY_STATE_INITIAL_DISPLAY_STATE_DATA_SOURCE_H_
65