schedtest.c revision d4ccd3f41f4a68276887e88d4618cc93e221361b
1/*
2** Copyright 2008 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 <stdlib.h>
18#include <stdio.h>
19#include <errno.h>
20#include <sys/uio.h>
21#include <unistd.h>
22
23int main(int argc, char **argv) {
24    int i;
25
26    struct timeval tv1;
27    struct timeval tv2;
28    long max = 0;
29    long avg = 0;
30
31    for(i = 1; ; i++) {
32        gettimeofday(&tv1, NULL);
33        usleep(1000);
34        gettimeofday(&tv2, NULL);
35
36        long usec = (tv2.tv_sec - tv1.tv_sec) * 1000000 + tv2.tv_usec - tv1.tv_usec;
37        avg += usec;
38
39        if (usec > max) max = usec;
40        if (!(i % 1000)) {
41            avg /= 1000;
42            printf("max %ld\tavg %ld\n", max, avg);
43            max = 0;
44            avg = 0;
45        }
46    }
47    return 0;
48}
49