Skip to content

Commit

Permalink
PerformanceAnalyzer正式开源!现在发布Release1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
He Junqiu committed Jul 19, 2016
1 parent 665b679 commit b33643b
Show file tree
Hide file tree
Showing 73 changed files with 5,557 additions and 1,893 deletions.
449 changes: 449 additions & 0 deletions CHPerformanceAnalyzer/CHPerformanceAnalyzer.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// AppDelegate.h
// Demo
// CHPerformanceAnalyzer
//
// Created by hejunqiu on 16/4/6.
// Copyright © 2016年 che. All rights reserved.
// Created by hejunqiu on 16/7/18.
// Copyright © 2016年 CHE. All rights reserved.
//

#import <UIKit/UIKit.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// AppDelegate.m
// Demo
// CHPerformanceAnalyzer
//
// Created by hejunqiu on 16/4/6.
// Copyright © 2016年 che. All rights reserved.
// Created by hejunqiu on 16/7/18.
// Copyright © 2016年 CHE. All rights reserved.
//

#import "AppDelegate.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
}
],
"info" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,12 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// CHGlobalDefines.h
// CHPerformanceAnalyzer
//
// Created by hejunqiu on 16/7/18.
// Copyright © 2016年 CHE. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CHMetaMacro.h"

/* Fake */

@interface CHGlobalDefines : NSObject

@end

typedef NS_OPTIONS(NSUInteger, CHPerformanceAnalyzerShowType) {
CHPerformanceAnalyzerShowTypeCPU = 1,
CHPerformanceAnalyzerShowTypeMemory = 1 << 1,
CHPerformanceAnalyzerShowTypePageLoading = 1 << 2,
CHPerformanceAnalyzerShowTypeFPS = 1 << 3,
CHPerformanceAnalyzerShowTypeAll = CHPerformanceAnalyzerShowTypeCPU | CHPerformanceAnalyzerShowTypeMemory | CHPerformanceAnalyzerShowTypePageLoading | CHPerformanceAnalyzerShowTypeFPS
};

typedef NS_ENUM(uint8_t, CHInternalIndex) {
CHInternalIndexModule = 0x0,
CHInternalIndexCPU = 0x1,
CHInternalIndexMemory = 0x2,
CHInternalIndexPageLoading = 0x3,
CHInternalIndexFPS = 0x4,
CHInternalIndexCount
};

#define option_check(var, opt) (((var) & (opt))==opt)

FOUNDATION_EXTERN NSUInteger accurateInstanceMemoryReserved(id instance);
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// CHGlobalDefines.m
// CHPerformanceAnalyzer
//
// Created by hejunqiu on 16/7/18.
// Copyright © 2016年 CHE. All rights reserved.
//

#import "CHGlobalDefines.h"
#include <objc/runtime.h>
#include <malloc/malloc.h>

@implementation CHGlobalDefines

@end

union __save_count_ivar__ {
uint32_t count;
Ivar *p;
};

NSUInteger accurateInstanceMemoryReserved(id instance)
{
#define POINTER_SIZE sizeof(void*)
NSUInteger reserved = 0;
do {
if (!instance) {
reserved = POINTER_SIZE;
break;
}
if ([instance isMemberOfClass:[NSObject class]]) {
break;
}
void *c_instance = (__bridge void*)instance;
reserved = malloc_size(c_instance);
union __save_count_ivar__ u;
u.count = 0;
Class cls = [instance class];
Ivar *ivars = class_copyIvarList(cls, &u.count);
if (!ivars) { // NULL, but also calculate pointer size
reserved += POINTER_SIZE;
break;
}
Ivar *ivarsEnd = ivars + u.count;
u.p = ivars - 1;
while (++u.p < ivarsEnd) {
const char *type = ivar_getTypeEncoding(*u.p);
if (type[0] == '@') {
if (type[1] == '\"' && type[2] != '<') { // This is a delegate, avoid to recycle.
NSString *key = [NSString stringWithUTF8String:ivar_getName(*u.p)];
id value = [instance valueForKey:key];
reserved += accurateInstanceMemoryReserved(value);
}
} else if (type[0] == '^') { // get malloc size of C/C++ style pointer
const void *ptr = c_instance + ivar_getOffset(*u.p);
reserved += malloc_size(ptr);
}
}
free(ivars);
// check whether instance is array or dictionary or not.
if ([instance respondsToSelector:@selector(objectEnumerator)]) {
NSEnumerator *enumerator = [instance performSelector:@selector(objectEnumerator)];
id obj = enumerator.nextObject;
while (obj) {
reserved += accurateInstanceMemoryReserved(obj);
obj = enumerator.nextObject;
}
}
} while (0);
return reserved;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// CHObserveredPrivate.h
// CHPerformanceAnalyzer
//
// Created by hejunqiu on 16/7/18.
// Copyright © 2016年 CHE. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface CHObserveredPrivate : NSObject

@property (nonatomic, strong) NSString *className;
@property (nonatomic, strong) NSString *keyPath;
@property (nonatomic, weak) NSObject *observered;
@property (nonatomic) BOOL active;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// CHObserveredPrivate.m
// CHPerformanceAnalyzer
//
// Created by hejunqiu on 16/7/18.
// Copyright © 2016年 CHE. All rights reserved.
//

#import "CHObserveredPrivate.h"

@implementation CHObserveredPrivate

@end
Loading

0 comments on commit b33643b

Please sign in to comment.