https://github.com/yaowenxu/Workplace/blob/master/timer/getrusagetimer.c
关键结构体:
代码语言:javascript复制struct rusage {
struct timeval ru_utime; /* user time used */
struct timeval ru_stime; /* system time used */
long ru_maxrss; /* max resident set size */
long ru_ixrss; /* integral shared text memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims */
long ru_majflt; /* page faults */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* messages sent */
long ru_msgrcv; /* messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
};
程序:
代码语言:javascript复制/**
* Author: Yaowen Xu
* Github: https://github.com/yaowenxu
* Organization: 北航系统结构研究所
* Date: 2019-08-18 13:31:34
* LastEditTime: 2019-08-18 13:51:26
* Description: 使用系统 函数 getrusage 获取程序运行相关信息
* 此程序主要是关注与总时间和内核空间运行时间与用户
* 空间运行时间,使用此函数可大致对程序运行时间计算;
* 查看: 具体使用信息可以在控制台以 man getrusage 命令查看
*/
#include <stdio.h>
#include <math.h>
#include <sys/time.h>
#include <sys/resource.h>
int str2int(char* str){
char *p = str;
int sum = 0;
while (*p != '