forked from BB9z/RFKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RFPerformance.m
85 lines (70 loc) · 2.3 KB
/
RFPerformance.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#import "RFPerformance.h"
#import "dout.h"
// for Memory log
#import <mach/mach.h>
@interface RFPerformance () {
time_t timeBase;
}
@end
@implementation RFPerformance
@synthesize timeTable = _timeTable;
+ (RFPerformance *)sharedInstance {
static RFPerformance *sharedInstance = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (RFPerformance *)init {
self = [super init];
if (self) {
NSMutableDictionary *tmp = [[NSMutableDictionary alloc] initWithCapacity:20];
self.timeTable = tmp;
RF_RELEASE_OBJ(tmp)
timeBase = clock();
}
return self;
}
- (void)dealloc {
self.timeTable = nil;
RF_DEALLOC_OBJ(super)
}
- (time_t)addTimePoint:(NSString *)name {
time_t t = clock();
NSNumber * tmpTime = [[NSNumber alloc] initWithFloat:(t-timeBase)/(double)CLOCKS_PER_SEC];
if ((self.timeTable)[name]) {
dout(@"Warning: A time point with the same name already existed.");
}
(self.timeTable)[name] = tmpTime;
RF_RELEASE_OBJ(tmpTime);
return t;
}
- (float)timeBetween:(NSString *)name1 another:(NSString *)name2 {
float time1 = [(NSNumber *)(self.timeTable)[name1] floatValue];
float time2 = [(NSNumber *)(self.timeTable)[name2] floatValue];
float time = time1 - time2;
return fabsf(time);
}
+ (void)logMemoryInfo {
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
if (kernReturn == KERN_SUCCESS) {
NSLog(@"free: %lu\nactive: %lu\ninactive: %lu\nwire: %lu\nzero fill: %lu\nreactivations: %lu\npageins: %lu\npageouts: %lu\nfaults: %u\ncow_faults: %u\nlookups: %u\nhits: %u",
(unsigned long)vmStats.free_count * vm_page_size,
(unsigned long)vmStats.active_count * vm_page_size,
(unsigned long)vmStats.inactive_count * vm_page_size,
(unsigned long)vmStats.wire_count * vm_page_size,
(unsigned long)vmStats.zero_fill_count * vm_page_size,
(unsigned long)vmStats.reactivations * vm_page_size,
(unsigned long)vmStats.pageins * vm_page_size,
(unsigned long)vmStats.pageouts * vm_page_size,
vmStats.faults,
vmStats.cow_faults,
vmStats.lookups,
vmStats.hits
);
}
}
@end