version 1.1, 2002/10/22 08:59:42 |
version 1.2, 2002/10/22 09:46:54 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/util/total_rusage.c,v 1.1 2002/10/22 08:59:42 noro Exp $ */ |
|
|
/* outputs total virtual memory size and total cputime consumed by |
/* outputs total virtual memory size and total cputime consumed by |
whole processes which have the specified process as their ancestor */ |
whole processes which have the specified process as their ancestor */ |
Line 23 struct proc_info { |
|
Line 23 struct proc_info { |
|
double time; /* second */ |
double time; /* second */ |
}; |
}; |
|
|
|
void total_resource(struct proc_info *pi,int n,int rootid,int *vsize,double *time); |
|
|
int compare_pi(struct proc_info *a, struct proc_info *b) |
int compare_pi(struct proc_info *a, struct proc_info *b) |
{ |
{ |
if ( a->pid < b->pid ) return 1; |
if ( a->pid < b->pid ) return 1; |
Line 34 main(int argc, char **argv) |
|
Line 36 main(int argc, char **argv) |
|
{ |
{ |
char *nlistf,*memf; |
char *nlistf,*memf; |
char errbuf[BUFSIZ]; |
char errbuf[BUFSIZ]; |
int rootid,n,i,j,pid,ppid; |
int rootid,n,i,j,pid,ppid,total_vsize; |
|
double total_time; |
kvm_t *kd; |
kvm_t *kd; |
struct kinfo_proc *kp; |
struct kinfo_proc *kp; |
struct proc_info *pi; |
struct proc_info *pi; |
Line 59 main(int argc, char **argv) |
|
Line 62 main(int argc, char **argv) |
|
} |
} |
qsort(pi,n,sizeof(struct proc_info), |
qsort(pi,n,sizeof(struct proc_info), |
(int (*)(const void *,const void *))compare_pi); |
(int (*)(const void *,const void *))compare_pi); |
|
total_resource(pi,n,rootid,&total_vsize,&total_time); |
|
printf("%d %f\n",total_vsize,total_time); |
|
} |
|
|
|
void total_resource(struct proc_info *pi,int n,int rootid,int *vsize,double *time) |
|
{ |
|
int vsize0,vsize1,i; |
|
double time0,time1; |
|
|
|
vsize0 = 0; |
|
time0 = 0; |
for ( i = 0; i < n; i++ ) { |
for ( i = 0; i < n; i++ ) { |
pid = pi[i].pid; |
if ( pi[i].ppid == rootid ) { |
if ( pid == rootid ) { |
if ( pi[i].pid ) { |
printf("%d %f\n",pi[i].vsize,pi[i].time); |
total_resource(pi,n,pi[i].pid,&vsize1,&time1); |
exit(0); |
vsize0 += vsize1; |
} else { |
time0 += time1; |
/* find the parent */ |
|
ppid = pi[i].ppid; |
|
for ( j = i+1; j < n; j++ ) |
|
if ( pi[j].pid == ppid ) |
|
break; |
|
if ( j < n ) { |
|
pi[j].vsize += pi[i].vsize; |
|
pi[j].time += pi[i].time; |
|
} |
} |
|
} else if ( pi[i].pid == rootid ) { |
|
vsize0 += pi[i].vsize; |
|
time0 += pi[i].time; |
} |
} |
} |
} |
|
*vsize = vsize0; |
|
*time = time0; |
} |
} |