IOCLASSCOUNT(8)
π IOCLASSCOUNT(8) β like, the whole manual, but make it make sense π
okay bestie, so this is ioclasscount from the System Manager's Manual, Darwin-flavored, and it is genuinely one of those tools that looks scary and then turns out to be your bestie for hunting leaks. sit down, grab a strawberry π, let's go.
β¨ NAME β¨
ioclasscount β that's her. that's the name. iconic, no notes. π
π¦ SYNOPSIS π¦
ioclasscount [--track] [--leaks] [--maps=PID] [--site=SITE] [--reset]
[--start] [--stop] [--exclude] [--size=BYTES]
[--capsize=BYTES] [--tag=tag] [--zsize=BYTES] [classname]
[...]
like yes she has a lot of flags. she's versatile. π
πΈ DESCRIPTION πΈ
So ioclasscount displays the instance counts of OSObject-based C++ classes in the kernel β and here's the lil twist that makes it spicy: each count gets incremented by the number of direct subclasses that have an instance count of at least 1.
Not me having to explain this with the classic example, but okay, the manpage does it and so will I:
Say IONetworkController is not directly instantiated, but its direct subclass IOEthernetController has any instances. Then IONetworkController's instance count will be at least 1. If another direct subclass such as IOFWController has any instances, then IONetworkController's instance count will be at least 2. and so on, forever, the math never stops, it's giving recursion energy π₯
and why, you ask? because this modification of instance counts prevents unloading of kexts defining superclasses that have no instances, but whose subclasses in other kexts have instances. lowkey genius, fr fr.
Now, the output rules, and they matter:
- If classes are specified, instance counts are printed as a comma-separated list in the order specified. your order, your rules π
- If no classes are specified, instance counts for all classes are printed, one per line of output and sorted by name. alphabetically slaying β¨
This information is useful for tracking leaks. π Instance counts can also be found in the root of the IORegistry in the "IOKitDiagnostics" property. so if you're the IORegistry type, she's there too π«Ά
π§ TRACKING π§
okay this part is the main character section, pay attention π
DEVELOPMENT or DEBUG kernels support collecting backtraces on IOMemoryDescriptor mapping and wiring of memory, and β when running with boot-arg io=0x00400000 β on object allocation and calls to IOMalloc*. With boot-arg io=0x02400000, capturing backtraces is enabled at startup. like, at boot. she's already working before you even showed up. π
The following operands are available:
--startβ start capturing allocations. go go go π--stopβ stop capturing allocations. okay we're done here β--resetβ reset any collected allocations. clean slate bestie π§Ό--trackβ display symbolicated allocation backtraces, with bytes allocated and number of calls accumulated per callsite, ordered by size. biggest first, always π--maps=pidβ display symbolicated backtraces for mappings created in the process with process id pid, with bytes mapped and address, ordered by size. And if pid is-1, all processes are displayed. everyone's invited π--site=siteβ when displaying backtraces, only those containing the string site are included. For example, site could be an address in the backtrace, a symbol name, or a module name. chef's choice π--leaksβ display symbolicated allocation backtraces for potential leaks, with bytes allocated and number of calls accumulated per callsite, ordered by size. and how does it know? leaks are detected by scanning kernel virtual memory for pointer references to an allocation; allocations with no references found are a potential leak. nobody's holding onto them, so like... they're free-floating. ghosted. π»--excludeβ if names are given, apply the command to all tracking categories excluding these names. yes, the reverse. the villain arc π€--size=nβ only report accumulated sizes>= nbytes. The default is1byte. tiny threshold, huge energy--capsize=nβ only capture allocations>= nbytes. The default is1byte. (capture β report, she's picky in two different places, and honestly? respect.) π--tag=tagβ only report allocations with the vm tag tag.--zsize=nβ only report allocations in the kalloc zone of sizenbytes.
β EXAMPLES β
Display instance counts for IOPCIDevice and AppleTestPCI:
/usr/sbin/ioclasscount IOPCIDevice AppleTestPCI
IOPCIDevice = 2, AppleTestPCI = 1
look at that comma-separated order-preserved output. ate. π
Start collecting backtraces for everything:
/usr/sbin/ioclasscount --start
Display backtraces and allocation sizes for everything:
/usr/sbin/ioclasscount --track
Display all backtraces and allocation sizes collected for OSData & OSSymbol:
/usr/sbin/ioclasscount --track OSData OSSymbol
Display all backtraces and allocation sizes collected except for OSSymbol, IOMalloc*, IOMemoryDescriptor mapping and wiring (names from IOKitDebug.h):
/usr/sbin/ioclasscount --track --exclude OSSymbol IOMalloc IOWire
the --exclude example is so satisfying, ngl ππ₯
π SEE ALSO π
ioalloccount(8), ioreg(8) β go read those too, bestie, they're the supporting cast and they understood the assignment π«Ά
lowkey reminder: this page is from Darwin, dated November 06, 2008 β yes she's been serving this information since 2008 and she has not lost a step. periodt. πβ¨ππ¦πΈπ
π¦ where this page comes from
- nixpkgs unstable: IOKitTools 125
- Copyright (c) 2000-2008 Apple Computer, Inc. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms