Collect statistics about the system and the current process.
The gc flag indicates whether a garbage collection should be performed before collecting the stats. This is a fairly expensive operation, so it should be avoided if possible.
Returns an array with stats for the current process.
The stats, listed by index in the array, are:
0. New-space (small collection) GC count for the process
1. Allocated memory on the Toit heap of the process
2. Reserved memory on the Toit heap of the process
3. Process message count
4. Bytes allocated in object heap
5. Group ID
6. Process ID
7. Free memory in the system
8. Largest free area in the system
9. Full GC count for the process (including compacting GCs)
10. Full compacting GC count for the process
The "bytes allocated in the heap" tracks the total number of allocations, but doesn't deduct the sizes of objects that die. It is a way to follow the allocation pressure of the process. It corresponds to the value returned by bytes-allocated-delta. The "allocated memory" is the combined size of all live objects on the heap.
The "reserved memory" is the size of the heap.
By passing the optional list argument to be filled in, you can avoid causing an allocation, which may interfere with the tracking of allocations. But note that at some point the bytes-allocated number becomes so large that it needs a small allocation of its own.
Examples
print "There have been $(process-stats[STATS-INDEX-GC-COUNT]) GCs for this process"