I wrote it and got it working this afternoon. If anyone wants to take a look and perhaps give me some feedback, I have attached the source.
The format is likely quite different than what you are used to, but this is our house style. You probably will have to tweak a path or two since it will not be compiling where it thinks it should be. -- +---------------------------------------------------------------+ | Dale Amon Immortal Data | | CEO Midland International Air and Space Port | | a...@vnl.com "Data Systems for Deep Space and Time" | +---------------------------------------------------------------+
#ifndef ZoneInfo_H #define ZoneInfo_H /*============================== ZoneInfo.h ================================ Filename: ZoneInfo.h 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 <Foundation/NSZone.h> /*==========================================================================*/ struct ZoneInfo { size_t total; size_t used; size_t free; }; struct ZoneInfo ZoneInfo (NSZone *zone); BOOL isMallocZone (NSZone *zone); void ZoneInfoPrint (NSZone *zone); void ZoneInfoPrintAll (NSZone *zone); size_t ZoneInfoTotal (NSZone *zone); size_t ZoneInfoUsed (NSZone *zone); size_t ZoneInfoFree (NSZone *zone); /*==========================================================================*/ /* CVS HISTORY */ /*==========================================================================*/ /* $Log: $ 20180308 Dale Amon <a...@immortaldata.net> Created ZoneInfo module. */ #endif
/*============================== 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 <malloc.h> #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<BOOL IsMallocZone (NSZone *zone)> True if zone is the default zone. =item B<size_t ZoneInfoFree (NSZone *zone)> Return the number of bytes free in either the default Malloc zone or a named zone. =item B<struct ZoneInfo ZoneInfo (NSZone *zone)> Returns a ZoneInfo struct with the total, used and free bytes in the allocation zone. =item B<void ZoneInfoPrint (NSZone *zone)> Print the size of the allocation zone in bytes and the number of bytes used and free. =item B<void ZoneInfoPrintAll (NSZone *zone)> 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<size_t ZoneInfoTotal (NSZone *zone)> Return the total number of bytes in either the default Malloc zone or a named zone. =item B<size_t ZoneInfoUsed (NSZone *zone)> 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 <dale.a...@immortaldata.net> =cut */ /*==========================================================================*/ /* CVS HISTORY */ /*==========================================================================*/ /* $Log: $ 20180308 Dale Amon <a...@immortaldata.net> Created ZoneInfo module. */
_______________________________________________ Discuss-gnustep mailing list Discuss-gnustep@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnustep