当前位置: 代码迷 >> AIX >> 在AIX6.1和GCC4.2下面使用libperfstat.h出现有关问题
  详细解决方案

在AIX6.1和GCC4.2下面使用libperfstat.h出现有关问题

热度:7702   发布时间:2013-02-26 00:00:00.0
在AIX6.1和GCC4.2下面使用libperfstat.h出现问题
gcc aixcpu.c -o acpu -lperfstat
In file included from /usr/include/sys/corral.h:25,
  from /usr/include/libperfstat.h:28,
  from aixcpu.c:10:
/usr/include/netinet/in6_var.h:65: error: array type has incomplete element type

不过AIX自己的xlc是没问题的,上面的编译命令只要把gcc换成cc就可以通过。
上网搜了一些,都没明确说怎么解决。这里有ibm的人么,能帮着出个主意么?

不行就得周一联系ibm support了。


/*
** Samples, created by Qin BaoJun, to get the cpu status information 
** libperfstat.a 
** http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/perfstat_cputot.htm 
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libperfstat.h>

void dispcpu(perfstat_cpu_t *);
void dispcputotal(perfstat_cpu_total_t *);

int main(int argc, char **argv) {
int retcode, i;
perfstat_id_t *id;
perfstat_cpu_t *cpu;
perfstat_cpu_total_t *cputotal;

/* Get the system cpu information, actually is the average information */
cputotal = (perfstat_cpu_total_t *)malloc(sizeof(perfstat_cpu_total_t));
memset(cputotal, 0, sizeof(perfstat_cpu_total_t));
retcode = perfstat_cpu_total(NULL, cputotal, sizeof(perfstat_cpu_total_t), 1);

if (retcode == -1) {
printf("Failed to execute perfstat_cpu_total\n");
exit(1);
}

/* display */
printf("<============ CPU average information ============>\n");
dispcputotal(cputotal);

/* Get the indivadul cpu information */
id = (perfstat_id_t *)malloc(sizeof(perfstat_id_t));
strcpy(id->name, """");

cpu = (perfstat_cpu_t *)malloc(4*sizeof(perfstat_cpu_t));
memset(cpu, 0, 4*sizeof(perfstat_cpu_t));

retcode = perfstat_cpu(id, cpu, sizeof(perfstat_cpu_t), 4);
if (retcode < 0) {
printf("error number : %d, errno : %d\n", retcode, errno);
exit(0);
}

/* Just display */
printf("\n<======== Individual CPU information ========>\n");
for (i=0; i<retcode; i++, cpu++) {
printf("<======== Individual CPU %d information =======>\n",i);
dispcpu(cpu);
}

/* free the allocated memory */
free(id);
free(cpu);
free(cputotal);

return 0;
}

void dispcputotal(perfstat_cpu_total_t *pt) {
printf("CPU description: %s\nactived cpu : %d, configured cpu : %d, cpu frequency : %lluMhz\n", pt->description, pt->ncpus, pt->ncpus_cfg, pt->processorHZ/1000000);
printf("CPU user time : %llu\n", pt->user);
printf("CPU sys time : %llu\n", pt->sys);
printf("CPU idle time : %llu\n", pt->idle);
printf("CPU wait time : %llu\n", pt->wait);
printf("Context switch : %llu\n", pt->pswitch);
printf("System call : %llu\n", pt->syscall);
printf("System reading : %llu\n", pt->sysread);
printf("System write : %llu\n", pt->syswrite);
printf("System forks : %llu\n", pt->sysfork);
printf("Number of bytes read by system : %llu\n", pt->readch);
printf("Number of bytes written by system : %llu\n", pt->writech);

}

void dispcpu(perfstat_cpu_t *cpu) {
printf("CPU name : %s\n", cpu->name);
printf("CPU user time : %llu\n", cpu->user);
printf("CPU sys time : %llu\n", cpu->sys);
printf("CPU idle time : %llu\n", cpu->idle);
printf("CPU wait time : %llu\n", cpu->wait);
printf("Context switch : %llu\n", cpu->pswitch);
printf("System call : %llu\n", cpu->syscall);
printf("System reading : %llu\n", cpu->sysread);