测试实时进程

Posted Evan_ZGYF丶

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了测试实时进程相关的知识,希望对你有一定的参考价值。

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/prctl.h>
#include <assert.h>
#include <pthread.h>


int cpu_core()

	return 4;



int thread_rt( int *id)

char *a;
char name[10];
sprintf(name, "thread%d", *id);
printf("id%d:\\n", *id);

prctl(15, name);

a= malloc(0x1000000);
while(1)
	memset(a, 1, 0x1000000);
	//usleep(100);

return 0;



int main(int argc, char *argv[])

	struct sched_param tSchParam;
	pthread_attr_t tThreadAttr;
	pthread_t tHandle;
	int err;
	int i, core_num;
	   int max_priority;
    int min_priority;

	core_num = cpu_core();

	if(argc == 2) 
		sscanf(argv[1], "%d", &core_num);
	
	

	printf("core_num=%d\\n", core_num);

 
    max_priority = sched_get_priority_max(SCHED_FIFO);
    min_priority = sched_get_priority_min(SCHED_FIFO);
    printf("SCHED_FIFO max_priority = %d\\n", max_priority);
    printf("SCHED_FIFO min_priority = %d\\n", min_priority);
 
    max_priority = sched_get_priority_max(SCHED_RR);
    min_priority = sched_get_priority_min(SCHED_RR);
    printf("SCHED_RR max_priority = %d\\n", max_priority);
    printf("SCHED_RR min_priority = %d\\n", min_priority);
 
    max_priority = sched_get_priority_max(SCHED_OTHER);
    min_priority = sched_get_priority_min(SCHED_OTHER);
    printf("SCHED_OTHER max_priority = %d\\n", max_priority);
    printf("SCHED_OTHER min_priority = %d\\n", min_priority);

	pthread_attr_init(&tThreadAttr);
	printf("--- Set SCHED_RR policy\\n");
	err = pthread_attr_setinheritsched(&tThreadAttr, PTHREAD_EXPLICIT_SCHED);
	assert( !err );
	err = pthread_attr_setschedpolicy(&tThreadAttr, SCHED_RR);
	assert( !err );
	tSchParam.sched_priority = sched_get_priority_max(SCHED_RR);
	

	pthread_attr_setschedparam(&tThreadAttr, &tSchParam);
	pthread_attr_setdetachstate(&tThreadAttr, PTHREAD_CREATE_DETACHED );




	for(i=0; i < core_num; i++)
	
		err = pthread_create(&tHandle, &tThreadAttr, (void*)thread_rt, &i);
		sleep(1);
	
	
	while(1)
		sleep(1);
	



以上是关于测试实时进程的主要内容,如果未能解决你的问题,请参考以下文章

测试实时进程

测试实时进程

Linux进程实时可视化监控

性能测试 基于Python结合InfluxDB及Grafana图表实时监控Android系统和应用进程

C语言测试五

怎么测硬盘读写速度?