/* ** Copyright 2010 The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ /* Opens /proc/sched_stat and diff's the counters. Currently support version 15, modify parse() to support other versions */ #include #include #include #include #include #include #include #define MAX_CPU 2 struct cpu_stat { /* sched_yield() stats */ unsigned int yld_count; /* sched_yield() called */ /* schedule() stats */ unsigned int sched_switch; /* switched to expired queue and reused it */ unsigned int sched_count; /* schedule() called */ unsigned int sched_goidle; /* schedule() left the cpu idle */ /* try_to_wake_up() stats */ unsigned int ttwu_count; /* try_to_wake_up() called */ /* try_to_wake_up() called and found the process being awakened last ran on * the waking cpu */ unsigned int ttwu_local; /* latency stats */ unsigned long long cpu_time; /* time spent running by tasks (ms) */ unsigned long long run_delay; /* time spent waiting to run by tasks (ms) */ unsigned long pcount; /* number of tasks (not necessarily unique) given */ }; struct cpu_stat cpu_prev[MAX_CPU]; struct cpu_stat cpu_delta[MAX_CPU]; struct cpu_stat tmp; static const char *next_line(const char *b) { while (1) { switch (*b) { case '\n': return b + 1; case '\0': return NULL; } b++; } } static int print() { int i; printf("CPU yield() schedule() switch idle ttwu() local cpu_time wait_time timeslices\n"); for (i=0; i