blob: ce059d4d4050341953c5a1fb6e52a97999df5881 [file] [log] [blame]
Isabelle Taylora0a22972018-08-03 12:06:12 +01001/*
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 Tucci2da5d2e2018-08-10 14:23:31 +010022#include "perfetto/base/string_view.h"
Hector Dearmanc8339932018-08-10 11:22:46 +010023#include "perfetto/base/utils.h"
Isabelle Taylora0a22972018-08-03 12:06:12 +010024#include "src/trace_processor/trace_storage.h"
25
26namespace perfetto {
27namespace trace_processor {
28
29class 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.
36class 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 Taylora0a22972018-08-03 12:06:12 +010045 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 Tucci2da5d2e2018-08-10 14:23:31 +010057 base::StringView prev_comm,
Isabelle Taylora0a22972018-08-03 12:06:12 +010058 uint32_t next_pid);
59
60 private:
61 // Store the previous sched event to calculate the duration before storing it.
Hector Dearmanc8339932018-08-10 11:22:46 +010062 std::array<SchedSwitchEvent, base::kMaxCpus> last_sched_per_cpu_;
Isabelle Taylora0a22972018-08-03 12:06:12 +010063
64 TraceProcessorContext* const context_;
65};
66} // namespace trace_processor
67} // namespace perfetto
68
69#endif // SRC_TRACE_PROCESSOR_SCHED_TRACKER_H_