HP-UX 11i v3 Memory Management Subsystem

25
/* Get a maximum of BURST pst_locality structures */
count = pstat_getlocality ( pstl, sizeof(struct pst_locality),
BURST, idx );
while ( count > 0 ) {
for ( i=0 ; i<count ; i++ ) {
/* Keep running totals for later */
total += pstl[i].psl_total_pages;
free += pstl[i].psl_free_pages;
floating_free += pstl[i].psl_floating_free_pages;
/* Convert integers into strings */
pages_to_str ( pstl[i].psl_total_pages, total_str );
pages_to_str ( pstl[i].psl_free_pages, free_str );
pages_to_str ( pstl[i].psl_floating_free_pages, ffree_str );
pages_to_str ( (pstl[i].psl_total_pages -
pstl[i].psl_free_pages), used_str );
printf ( "%6d%6lld%7lld%7s%6u%10s%10s%10s%10s\n",
(idx+i),
pstl[i].psl_ldom_id,
pstl[i].psl_physical_id,
((pstl[i].psl_flags & PSL_INTERLEAVED) ?
"ILM": (pstl[i].psl_cpus ? "C{S}LM":"BLM")),
(int)(pstl[i].psl_cpus),
total_str, free_str, ffree_str, used_str );
}
idx += count;
/*
* Get (at most) the next BURST pst_locality
* structures, starting at idx
*/
count = pstat_getlocality ( pstl,
sizeof(struct pst_locality),
BURST, idx );
}
if ( count < 0 ) {
perror ( "pstat_getlocality" );
exit(1);
}
if ( idx == 1 ) {
/* Don't print totals if there's one locality */
printf ( "\n" );
return;
}
/* Convert integer totals into strings */
pages_to_str ( total, total_str );
pages_to_str ( free, free_str );
pages_to_str ( floating_free, ffree_str );
pages_to_str ( total-free, used_str );
/* Print totals */
printf ( "%6s%6s%7s%7s%6s%10s%10s%10s%10s\n",
"", "", "", "", "", "-----", "-----", "-----", "-----" );
printf ( "%6s%6s%7s%7s%6s%10s%10s%10s%10s\n\n",
"", "", "", "", "", total_str, free_str, ffree_str, used_str );
}
/*
* Given a pid, display its per-locality physical memory usage.
*/
void
pid_locinfo ( pid_t pid )
{
int count, i=0;
struct pst_proc_locality ppl;
char total_str[STRSZ], shared_str[STRSZ];
char private_str[STRSZ], weighted_str[STRSZ];
uint64_t total=0, shared=0, private=0, weighted=0;
/*
* With this interface, information on only one locality
* can be returned at a time. This will get the first:
*/
count = pstat_getproclocality ( &ppl,
sizeof(struct pst_proc_locality), pid, i );
printf ( " --- Per-process locality info for pid %d: ---\n",
pid );
printf ( "%6s%10s%10s%10s%10s\n",
"idx", "total", "shared", "private", "weighted" );
while ( count == 1 ) {
total += ppl.ppl_rss_total;
shared += ppl.ppl_rss_shared;
private += ppl.ppl_rss_private;
weighted += ppl.ppl_rss_weighted;
pages_to_str ( ppl.ppl_rss_total, total_str );
pages_to_str ( ppl.ppl_rss_shared, shared_str );
pages_to_str ( ppl.ppl_rss_private, private_str );
pages_to_str ( ppl.ppl_rss_weighted, weighted_str );