Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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_TRACE_PROCESSOR_SCHED_TRACKER_H_ |
| 18 | #define SRC_TRACE_PROCESSOR_SCHED_TRACKER_H_ |
| 19 | |
| 20 | #include <array> |
| 21 | |
Primiano Tucci | 2da5d2e | 2018-08-10 14:23:31 +0100 | [diff] [blame^] | 22 | #include "perfetto/base/string_view.h" |
Hector Dearman | c833993 | 2018-08-10 11:22:46 +0100 | [diff] [blame] | 23 | #include "perfetto/base/utils.h" |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 24 | #include "src/trace_processor/trace_storage.h" |
| 25 | |
| 26 | namespace perfetto { |
| 27 | namespace trace_processor { |
| 28 | |
| 29 | class TraceProcessorContext; |
| 30 | |
| 31 | // TODO:(b/111252261): The processing of cpu freq events and calculation |
| 32 | // of cycles is still to be implemented here. |
| 33 | |
| 34 | // This class takes sched events from the trace and processes them to store |
| 35 | // as sched slices. |
| 36 | class SchedTracker { |
| 37 | public: |
| 38 | explicit SchedTracker(TraceProcessorContext*); |
| 39 | SchedTracker(const SchedTracker&) = delete; |
| 40 | SchedTracker& operator=(const SchedTracker&) = delete; |
| 41 | virtual ~SchedTracker(); |
| 42 | |
| 43 | struct SchedSwitchEvent { |
| 44 | uint64_t timestamp = 0; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 45 | uint32_t prev_pid = 0; |
| 46 | uint32_t prev_state = 0; |
| 47 | uint32_t next_pid = 0; |
| 48 | |
| 49 | bool valid() const { return timestamp != 0; } |
| 50 | }; |
| 51 | |
| 52 | // This method is called when a sched switch event is seen in the trace. |
| 53 | virtual void PushSchedSwitch(uint32_t cpu, |
| 54 | uint64_t timestamp, |
| 55 | uint32_t prev_pid, |
| 56 | uint32_t prev_state, |
Primiano Tucci | 2da5d2e | 2018-08-10 14:23:31 +0100 | [diff] [blame^] | 57 | base::StringView prev_comm, |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 58 | uint32_t next_pid); |
| 59 | |
| 60 | private: |
| 61 | // Store the previous sched event to calculate the duration before storing it. |
Hector Dearman | c833993 | 2018-08-10 11:22:46 +0100 | [diff] [blame] | 62 | std::array<SchedSwitchEvent, base::kMaxCpus> last_sched_per_cpu_; |
Isabelle Taylor | a0a2297 | 2018-08-03 12:06:12 +0100 | [diff] [blame] | 63 | |
| 64 | TraceProcessorContext* const context_; |
| 65 | }; |
| 66 | } // namespace trace_processor |
| 67 | } // namespace perfetto |
| 68 | |
| 69 | #endif // SRC_TRACE_PROCESSOR_SCHED_TRACKER_H_ |