Hector Dearman | 3639700 | 2018-03-20 18:42:08 +0000 | [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 | #include <sched.h> |
| 18 | #include <sys/stat.h> |
| 19 | #include <sys/types.h> |
| 20 | #include <unistd.h> |
| 21 | |
| 22 | #include "perfetto/base/logging.h" |
| 23 | #include "perfetto/base/time.h" |
| 24 | |
| 25 | // Skippy is a program that produces a visually identifiable stepping pattern |
| 26 | // in the systrace UI that is useful for debugging dropped or corrupted data. |
| 27 | |
| 28 | namespace perfetto { |
| 29 | namespace { |
| 30 | |
| 31 | void SetAffinity(size_t cpu) { |
| 32 | cpu_set_t set{}; |
| 33 | CPU_SET(cpu, &set); |
| 34 | PERFETTO_CHECK( |
| 35 | sched_setaffinity(0 /* calling process */, sizeof(cpu_set_t), &set) == 0); |
| 36 | } |
| 37 | |
Primiano Tucci | 3cbb10a | 2018-04-10 17:52:40 +0100 | [diff] [blame] | 38 | int SkippyMain() { |
Hector Dearman | 3639700 | 2018-03-20 18:42:08 +0000 | [diff] [blame] | 39 | static size_t num_cpus = static_cast<size_t>(sysconf(_SC_NPROCESSORS_CONF)); |
| 40 | size_t cpu = 0; |
| 41 | base::TimeMillis last = base::GetWallTimeMs(); |
| 42 | |
| 43 | SetAffinity(cpu); |
| 44 | |
| 45 | for (;;) { |
| 46 | base::TimeMillis now = base::GetWallTimeMs(); |
| 47 | if ((now - last) < base::TimeMillis(100)) |
| 48 | continue; |
| 49 | last = now; |
| 50 | cpu = (cpu + 1) % num_cpus; |
| 51 | SetAffinity(cpu); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | } // namespace |
| 56 | } // namespace perfetto |
| 57 | |
Primiano Tucci | 3cbb10a | 2018-04-10 17:52:40 +0100 | [diff] [blame] | 58 | int main() { |
| 59 | return perfetto::SkippyMain(); |
Hector Dearman | 3639700 | 2018-03-20 18:42:08 +0000 | [diff] [blame] | 60 | } |