📄 timer.c
字号:
#include <stdio.h>#include <sys/time.h>#include <signal.h>struct timeval tpstart,tpend;float timeuse;static timer_count = 0;void prompt_info(int signo){ time_t t = time(NULL); /* [1] 2 seconds turned, print something */ printf("[%d] prompt_info called\n", ++timer_count); /* [2] get current time and print it */ ctime(&t); printf(" current time %s", ctime(&t)); /* [3] stop get time, and print it */ gettimeofday(&tpend,NULL); timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec; timeuse/=1000000; printf(" Used Time:%f\n",timeuse); } void init_sigaction(void){ struct sigaction act; act.sa_handler=prompt_info; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGPROF,&act,NULL); /* begin get the time */ gettimeofday(&tpstart,NULL);}void init_time(){ struct itimerval value; value.it_value.tv_sec=2; value.it_value.tv_usec=0; value.it_interval=value.it_value; setitimer(ITIMER_PROF,&value,NULL);}/* * timer application code * compile : * $arm-elf-gcc -Wl,-elf2flt -o timer timer.c * $cp timer /tftpboot/examples * run in target: * #cd /var * #ftp 192.168.1.180 * ftp>bin * ftp>cd /tftpboot/examples * ftp>get timer * ftp>by * #./timer */int main(int argc, char **argv){ init_sigaction(); init_time(); while(1); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -