The following test set: fix: Bug for getrusage return incorrect ru_maxrss fix: Bug for getrusage(RUSAGE_CHILDREN) return parent info (POSTK_DEBUG_TEMP_FIX_72) fix: Bug for getrusage often return incorrect ru_stime Change-Id: I6734b1e34565d5d2715f9901a04ba5b6f0278032 Refs: #1032 Refs: #1033 Refs: #1034
93 lines
1.4 KiB
C
93 lines
1.4 KiB
C
#ifndef __TEST_RUSAGE_H__
|
|
#define __TEST_RUSAGE_H__
|
|
|
|
#include <stdio.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <sys/resource.h>
|
|
#include <errno.h>
|
|
#include <signal.h>
|
|
|
|
#define ONE_SEC 1000000
|
|
#define M_BYTE 1024 * 1024
|
|
|
|
#ifdef __x86_64__
|
|
#define cpu_pause() \
|
|
({ \
|
|
__asm__ __volatile__("pause" ::: "memory"); \
|
|
})
|
|
#elif defined(__aarch64__)
|
|
#define cpu_pause() \
|
|
({ \
|
|
__asm__ __volatile__("yield" ::: "memory"); \
|
|
})
|
|
#else
|
|
#error "cpu_pause() not implemented."
|
|
#endif
|
|
|
|
int sig_count;
|
|
|
|
long get_rusage_utime(struct rusage *usage)
|
|
{
|
|
if (!usage) {
|
|
return -1;
|
|
}
|
|
|
|
return (usage->ru_utime.tv_sec * ONE_SEC) + usage->ru_utime.tv_usec;
|
|
}
|
|
|
|
long get_rusage_stime(struct rusage *usage)
|
|
{
|
|
if (!usage) {
|
|
return -1;
|
|
}
|
|
|
|
return (usage->ru_stime.tv_sec * ONE_SEC) + usage->ru_stime.tv_usec;
|
|
}
|
|
|
|
long get_rusage_maxrss(struct rusage *usage)
|
|
{
|
|
if (!usage) {
|
|
return -1;
|
|
}
|
|
|
|
return usage->ru_maxrss;
|
|
}
|
|
|
|
void alrm_handler(int sig)
|
|
{
|
|
sig_count = 1;
|
|
}
|
|
|
|
void add_utime(int sec)
|
|
{
|
|
int rc;
|
|
struct sigaction sa;
|
|
|
|
/* flag clear */
|
|
sig_count = 0;
|
|
|
|
/* set sighandler */
|
|
sa.sa_handler = alrm_handler;
|
|
rc = sigaction(SIGALRM, &sa, NULL);
|
|
|
|
alarm(sec);
|
|
|
|
while (!sig_count) {
|
|
cpu_pause();
|
|
}
|
|
}
|
|
|
|
void add_stime(int sec)
|
|
{
|
|
int fd;
|
|
|
|
fd = open("/dev/test_rusage", O_RDWR);
|
|
ioctl(fd, sec, NULL);
|
|
close(fd);
|
|
}
|
|
|
|
#endif /*__TEST_RUSAGE_H__*/
|