-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PerformanceAnalyzer正式开源!现在发布Release1.0.1
- Loading branch information
He Junqiu
committed
Jul 19, 2016
1 parent
665b679
commit b33643b
Showing
73 changed files
with
5,557 additions
and
1,893 deletions.
There are no files selected for viewing
449 changes: 449 additions & 0 deletions
449
CHPerformanceAnalyzer/CHPerformanceAnalyzer.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ject.xcworkspace/contents.xcworkspacedata → ...ject.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
Demo/Demo/AppDelegate.h → ...lyzer/CHPerformanceAnalyzer/AppDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
Demo/Demo/AppDelegate.m → ...lyzer/CHPerformanceAnalyzer/AppDelegate.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
CHPerformanceAnalyzer/CHPerformanceAnalyzer/PerformanceAnalyzer1.0.1/CHGlobalDefines.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
71 changes: 71 additions & 0 deletions
71
CHPerformanceAnalyzer/CHPerformanceAnalyzer/PerformanceAnalyzer1.0.1/CHGlobalDefines.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
18 changes: 18 additions & 0 deletions
18
...r/CHPerformanceAnalyzer/PerformanceAnalyzer1.0.1/DataRepresentation/CHObserveredPrivate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
13 changes: 13 additions & 0 deletions
13
...r/CHPerformanceAnalyzer/PerformanceAnalyzer1.0.1/DataRepresentation/CHObserveredPrivate.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.