/*============================== ZoneInfo.m ================================ Filename: ZoneInfo.m Description: Return key diagnostic info on any zone. Original Author: Dale M. Amon Revised by: $Author: amon $ Date: $Date: $ Version: $Revision: $ License: Copyright GPL, BSD and Immortal Data Inc. */ #import #import "shipslog/ZoneInfo.h" /*==========================================================================*/ struct ZoneInfo ZoneInfo (NSZone *zone) { struct ZoneInfo zi; if (isMallocZone (zone)) { struct mallinfo ms = mallinfo(); zi.total = (size_t) ms.arena; zi.used = (size_t) ms.uordblks; zi.free = (size_t) ms.fordblks; } else { struct NSZoneStats zs = NSZoneStats (zone); zi.total = zs.bytes_total; zi.used = zs.bytes_used; zi.free = zs.bytes_free; } return zi; } /*--------------------------------------------------------------------------*/ size_t ZoneInfoTotal (NSZone *zone) { if (isMallocZone (zone)) { struct mallinfo ms = mallinfo(); return ((size_t) ms.arena); } else { struct NSZoneStats zs = NSZoneStats (zone); return (zs.bytes_total); } } /*--------------------------------------------------------------------------*/ size_t ZoneInfoUsed (NSZone *zone) { if (isMallocZone (zone)) { struct mallinfo ms = mallinfo(); return ((size_t) ms.uordblks); } else { struct NSZoneStats zs = NSZoneStats (zone); return (zs.bytes_used); } } /*--------------------------------------------------------------------------*/ size_t ZoneInfoFree (NSZone *zone) { if (isMallocZone (zone)) { struct mallinfo ms = mallinfo(); return ((size_t) ms.fordblks); } else { struct NSZoneStats zs = NSZoneStats (zone); return (zs.bytes_free); } } /*--------------------------------------------------------------------------*/ BOOL isMallocZone (NSZone *zone) { return (zone == NSDefaultMallocZone()); } /*--------------------------------------------------------------------------*/ void ZoneInfoPrint (NSZone *zone) { if (isMallocZone (zone)) { struct mallinfo ms = mallinfo(); printf ("\ \nZone Storage Info\n\ Total = %10d bytes\n\ Used = %10d bytes\n\ Free = %10d bytes\n", ms.arena, ms.uordblks, ms.fordblks); } else { struct NSZoneStats zs = NSZoneStats (zone); printf ("\ \nZone Storage Info\n\ Total = %10d bytes\n\ Used = %10d bytes\n\ Free = %10d bytes\n", (int) zs.bytes_total, (int) zs.bytes_used, (int) zs.bytes_free); } } /*--------------------------------------------------------------------------*/ void ZoneInfoPrintAll (NSZone *zone) { if (isMallocZone (zone)) { struct mallinfo ms = mallinfo(); printf ("\ \nMalloc Zone\n\ arena = %10d bytes\n\ ordblks = %10d blocks\n\ smblks = %10d blocks\n\ hblkhd = %10d bytes\n\ usmblks = %10d bytes\n\ fsmblks = %10d bytes\n\ uordblks = %10d bytes\n\ fordblks = %10d bytes\n\ keepcost = %10d bytes\n", ms.arena, ms.ordblks, ms.smblks, ms.hblkhd, ms.usmblks, ms.fsmblks, ms.uordblks, ms.fordblks, ms.keepcost); } else { struct NSZoneStats zs = NSZoneStats (zone); printf ("\ \nNSZone\n\ bytes_total = %10d bytes\n\ chunks_used = %10d blocks\n\ bytes_used = %10d bytes\n\ chunks_free = %10d blocks\n\ bytes_free = %10d bytes\n", (int) zs.bytes_total, (int) zs.chunks_used, (int) zs.bytes_used, (int) zs.chunks_free, (int) zs.bytes_free); } } /*--------------------------------------------------------------------------*/ /*==========================================================================*/ /* POD DOCUMENTATION */ /*==========================================================================*/ /* You may extract and format the documention section with the 'perldoc' cmd. =head1 NAME ZoneInfo.m - Return key diagnostic info on any zone. =head1 SYNOPSIS #import "shipslog/ZoneInfo.h" NSZoneInfo zi; NSZone *zone; size_t n; BOOL flg; zi = ZoneInfo (zone); n = ZoneInfoTotal (zone); n = ZoneInfoUsed (zone); n = ZoneInfoFree (zone); flg = IsMallocZone (zone); ZoneInfoPrint (zone); ZoneInfoPrintAll (zone); =head1 Inheritance Not Applicable. =head1 Description Return key diagnostic info on any zone. =head1 Examples None. =head1 Class Variables Not Applicable. =head1 Instance Variables Not Applicable. =head1 Class Methods Not Applicable. =head1 Instance Methods Not Applicable. =head1 Functions =over 4 =item B True if zone is the default zone. =item B Return the number of bytes free in either the default Malloc zone or a named zone. =item B Returns a ZoneInfo struct with the total, used and free bytes in the allocation zone. =item B Print the size of the allocation zone in bytes and the number of bytes used and free. =item B Print all of the available info on the zone. This info will be different depending on whether zone is the default zone or a named zone. =item B Return the total number of bytes in either the default Malloc zone or a named zone. =item B Return the number of bytes used in either the default Malloc zone or a named zone. =back =head1 Private Class Method Not Applicable. =head1 Private Instance Methods Not Applicable. =head1 Errors and Warnings None. =head1 KNOWN BUGS See TODO. =head1 SEE ALSO NSZone.3 if it existed... =head1 AUTHOR Dale Amon =cut */ /*==========================================================================*/ /* CVS HISTORY */ /*==========================================================================*/ /* $Log: $ 20180308 Dale Amon Created ZoneInfo module. */