Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions FirebasePerformance/Sources/FPRNanoPbUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,11 @@ firebase_perf_v1_GaugeMetric FPRGetGaugeMetric(NSArray *gaugeData, NSString *ses
memoryReadings[memoryReadingsCount].used_app_heap_memory_kb =
(int32_t)BYTES_TO_KB(gaugeData.heapUsed);
memoryReadings[memoryReadingsCount].has_used_app_heap_memory_kb = true;
memoryReadings[memoryReadingsCount].free_app_heap_memory_kb =
(int32_t)BYTES_TO_KB(gaugeData.heapAvailable);
memoryReadings[memoryReadingsCount].has_free_app_heap_memory_kb = true;
if (gaugeData.heapAvailable > 0) {
memoryReadings[memoryReadingsCount].free_app_heap_memory_kb =
(int32_t)BYTES_TO_KB(gaugeData.heapAvailable);
memoryReadings[memoryReadingsCount].has_free_app_heap_memory_kb = true;
}
memoryReadingsCount++;
}
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations.h"
#import "FirebasePerformance/Sources/FPRConsoleLogger.h"

#include <malloc/malloc.h>
#include <mach/mach.h>

@interface FPRMemoryGaugeCollector ()

Expand All @@ -37,10 +37,20 @@ @interface FPRMemoryGaugeCollector ()
FPRMemoryGaugeData *fprCollectMemoryMetric(void) {
NSDate *collectionTime = [NSDate date];

struct mstats ms = mstats();
// Reading task_info is safer to call from any thread, including during high throughput networking activity.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Do you mean that reading it is safer to call IT from any thread? Or is is safer than?

task_vm_info_data_t vmInfo;
mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
u_long usedBytes = 0;
u_long freeBytes = 0;

kern_return_t kr = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t)&vmInfo, &count);
if (kr == KERN_SUCCESS) {
// phys_footprint is the memory footprint used by Jetsam accounting.
usedBytes = (u_long)vmInfo.phys_footprint;
}
FPRMemoryGaugeData *gaugeData = [[FPRMemoryGaugeData alloc] initWithCollectionTime:collectionTime
heapUsed:ms.bytes_used
heapAvailable:ms.bytes_free];
heapUsed:usedBytes
heapAvailable:freeBytes];
return gaugeData;
}

Expand Down