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 SetAffinity(size_t cpu)31void 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 SkippyMain()38int SkippyMain() { 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 main()58int main() { 59 return perfetto::SkippyMain(); 60 } 61