Grant Park
Grant Park

Reputation: 1044

What is the "total count" metric in Android Studio's Memory Profiler?

I'm unable to find a description of this metric anywhere in the Android developer documentation. Here is a link to what I've most recently looked at: https://developer.android.com/studio/profile/memory-profiler

Here's what I think it is: the number of objects in the heap that have not been deallocated.

Please, if possible, provide a credible resource that supports your reasoning (e.g. a Google I/0 talk on Youtube with a minute-mark or some Android documentation).

EDIT: Here is a screenshot that includes the metric. enter image description here

Upvotes: 4

Views: 931

Answers (3)

Jake Lee
Jake Lee

Reputation: 7989

Total Count column

Total Count is defined as the total object count (see Android Studio source), specifically:

  new AttributeColumn<>(
    "Total Count",
    () -> new SimpleColumnRenderer<ClassifierSet>(
      value -> Integer.toString(value.getAdapter().getTotalObjectCount()),
      value -> null,
      SwingConstants.RIGHT),

This getTotalObjectCount() is defined as:

  public int getTotalObjectCount() {
    return mySnapshotObjectCount + myDeltaAllocations - myDeltaDeallocations;
  }

Incrementing methods

The mySnapshotObjectCount value is incremented inside addSnapshotInstanceObject, which has the helpful comment:

Add an instance to the baseline snapshot and update the accounting of the "total" values.

The myDeltaAllocations and myDeltaDeallocations values are incremented inside addDeltaInstanceInformation:

if (isAllocation) {
  myDeltaAllocations++;
}
else {
  myDeltaDeallocations++;
}

This is called inside partition, which contains the helpful comment:

Partitions InstanceObjects in snapshotInstances and myDeltaInstances according to the current ClassifierSet strategy. This will consume the instances from the input.

This snapshotInstance is the same one used to increment mySnapshotInstanceObjectCount, thus showing that all 3 values are very closely linked, are created when a partition (snapshot) is made, and all factor into the Total Count.


Final formula

So, the final answer is:

Total Count = Snapshot objects + New allocations - New deallocations
  • Snapshot objects = number of object instances allocated before the snapshot.
  • New allocations = number of allocations during snapshot.
  • New deallocations = number of deallocations during snapshot.

This definition of the equation matches what Axifive stated in another answer, and the linked video.

Upvotes: 2

Axifive
Axifive

Reputation: 1151

Yes this is the total number of instance, that has allocated before the selected period + memory allocation for the selected period (or as you says: number of objects(instances) in the heap that haven't been deallocated for the selected period)

You can see this here

On the Instance View, it can be seen that three int arrays were allocated at 1m, but not deallocated (for the selected period).

Upvotes: 0

Quantum
Quantum

Reputation: 23

Here's what I think it is: the number of objects in the heap that have not been deallocated.

You are right with your thinking but I cannot serve you with a public thread for that.

Upvotes: 0

Related Questions