The Android Open Source Project | e16cb84 | 2009-03-03 19:32:58 -0800 | [diff] [blame] | 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> |
Elliott Hughes | 8678c6f | 2015-01-29 21:26:35 -0800 | [diff] [blame] | 20 | #include <sys/time.h> |
The Android Open Source Project | e16cb84 | 2009-03-03 19:32:58 -0800 | [diff] [blame] | 21 | #include <sys/uio.h> |
| 22 | #include <unistd.h> |
| 23 | |
| 24 | int main(int argc, char **argv) { |
| 25 | int i; |
| 26 | |
| 27 | struct timeval tv1; |
| 28 | struct timeval tv2; |
| 29 | long max = 0; |
| 30 | long avg = 0; |
| 31 | |
| 32 | for(i = 1; ; i++) { |
| 33 | gettimeofday(&tv1, NULL); |
| 34 | usleep(1000); |
| 35 | gettimeofday(&tv2, NULL); |
| 36 | |
| 37 | long usec = (tv2.tv_sec - tv1.tv_sec) * 1000000 + tv2.tv_usec - tv1.tv_usec; |
| 38 | avg += usec; |
| 39 | |
| 40 | if (usec > max) max = usec; |
| 41 | if (!(i % 1000)) { |
| 42 | avg /= 1000; |
| 43 | printf("max %ld\tavg %ld\n", max, avg); |
| 44 | max = 0; |
| 45 | avg = 0; |
| 46 | } |
| 47 | } |
| 48 | return 0; |
| 49 | } |