aozhimin / ios-monitor-platform Goto Github PK
View Code? Open in Web Editor NEW:books: iOS 性能监控 SDK —— Wedjat(华狄特)开发过程的调研和整理
Home Page: https://aozhimin.github.io/iOS-Monitor-Platform/
License: MIT License
:books: iOS 性能监控 SDK —— Wedjat(华狄特)开发过程的调研和整理
Home Page: https://aozhimin.github.io/iOS-Monitor-Platform/
License: MIT License
- (NSUInteger)getResidentMemory
{
struct mach_task_basic_info info;
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
int r = task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)& info, & count);
if (r == KERN_SUCCESS)
{
return info.resident_size;
}
else
{
return -1;
}
}
这个拿到的值和 Xcode 上的不一致啊,多了30-40MB 左右
启动时间这个由于 Load 顺序不确定,而且 dyld 在 load class 之后还有 initializers 之前也要 load dylib 所以这个冷启动的时间应该是不准确的 ...
我在网上也没找到其他的api可以获取cpu的占用率,个人水平有限,所以还请作者帮忙看下是什么原因.
Anybody succeed for connect() and send() methods?
您好,请问是否有 API 图形化的计划?
只有 API 的话,个人觉得还是有一定使用门槛的。如果能够像 logo.gif 所展示的那样把数据实时的展示出来,我觉得使用起来会更方便,工具的受众也会扩大不少。
希望能考虑一下。
[email protected] 好人一生平安,谢谢
https://aozhimin.github.io/iOS-Monitor-Platform/
这个文章 页面、文字用的主题和配色方案,向楼主请教
我在使用NSProxy替换NSURLSession原来的的delegate的时候,再使用AFNetwork的AFHTTPSessionManager的GET方法的时候崩溃了,不知道是什么原因,具体代码如下:
static void swizzleClassMethod(Class theClass, SEL originalSelector, SEL swizzledSelector)
{
Method origMethod = class_getClassMethod(theClass, originalSelector);
Method newMethod = class_getClassMethod(theClass, swizzledSelector);
theClass = object_getClass((id)theClass);
if(class_addMethod(theClass, originalSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(theClass, swizzledSelector, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
else
method_exchangeImplementations(origMethod, newMethod);
}
@interface NSURLSession()
@Property(nonatomic, strong) NSURLDelegateProxy *delegateProxy;
@EnD;
@implementation NSURLSession (DelegateMonitor)
(void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
swizzleClassMethod([self class],
@selector(sessionWithConfiguration:delegate:delegateQueue:),
@selector(hcz_sessionWithConfiguration:delegate:delegateQueue:));
});
}
(NSURLSession *)hcz_sessionWithConfiguration:(NSURLSessionConfiguration *)configuration delegate:(nullable id )delegate delegateQueue:(nullable NSOperationQueue *)queue
{
if (delegate) {
NSURLDelegateProxy *proxy = [[NSURLDelegateProxy alloc] initWithTarget:delegate];
NSURLSession *session = [NSURLSession hcz_sessionWithConfiguration:configuration delegate:proxy delegateQueue:queue];
session.delegateProxy = proxy;
return session;
}
return [self hcz_sessionWithConfiguration:configuration delegate:delegate delegateQueue:queue];
}
@interface NSURLDelegateProxy()
@Property(nonatomic, weak) id proxyTarget;
@implementation NSURLDelegateProxy
(instancetype)initWithTarget:(id)target
{
self.proxyTarget = target;
return self;
}
(void)forwardInvocation:(NSInvocation *)invocation
{
SEL sel = [invocation selector];
if ( [self.proxyTarget respondsToSelector:sel]) {
[invocation invokeWithTarget:self.proxyTarget];
}
}
(nullable NSMethodSignature *)methodSignatureForSelector:(SEL)sel
{
NSMethodSignature *methodSignature = nil;
if ( [self.proxyTarget respondsToSelector:sel]) {
methodSignature = [self.proxyTarget methodSignatureForSelector:sel];
}
return methodSignature;
}
都是很简单的调用,AFHTTPSessionManager的调用方法如下:
AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
NSURLSessionDataTask *task = [session GET:@"https://hcz-static.pingan.com.cn/fuelCard/fuelCard.zip" parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
错误提示:
2017-12-08 18:08:44.923871+0800 AFNetworkingDemo[82876:14788953] *** NSForwarding: warning: object 0x608000036560 of class '__NSMessageBuilder' does not implement doesNotRecognizeSelector: -- abort
struct mach_task_basic_info info;
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
int r = task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)& info, & count);
if (r == KERN_SUCCESS)
{
return info.phys_footprint;
}
else
{
return -1;
}
中的info为mach_task_basic_info,这个结构体中并没有phys_footprint变量。
int64_t usage = 0;
task_vm_info_data_t vmInfo;
mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
kern_return_t kr = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);
if(kr != KERN_SUCCESS) {
return -1;
}
usage = (int64_t) vmInfo.phys_footprint;
return usage;
换成这个就OK了
想问下获取CPU时, Xcode13调试,通过thread_info获取线程信息失败,有对应的解决办法么?目前看 kr != KERN_SUCCESS的判断去掉就ok了,kr的值在枚举中没有对应的。
@implementation UIViewController (Hook1)
+ (void)load {
struct rebinding _request_binding = { "CFReadStreamCreateForHTTPRequest", wt_CFReadStreamCreateForHTTPRequest, (void *)&original_CFReadStreamCreateForHTTPRequest};
struct rebinding rebs[]={_request_binding};
rebind_symbols(rebs, 1);
}
static CFReadStreamRef
wt_CFReadStreamCreateForHTTPRequest(CFAllocatorRef __nullable alloc, CFHTTPMessageRef request);
CFReadStreamRef wt_CFReadStreamCreateForHTTPRequest(CFAllocatorRef __nullable alloc, CFHTTPMessageRef request) {
NSURL *url = (__bridge NSURL *)CFHTTPMessageCopyRequestURL(request);
NSString *method = (__bridge NSString *)CFHTTPMessageCopyRequestMethod(request);
CFReadStreamRef readStream = original_CFReadStreamCreateForHTTPRequest(alloc, request);
return readStream;
}
static CFReadStreamRef (*original_CFReadStreamCreateForHTTPRequest)(CFAllocatorRef, CFHTTPMessageRef);
@end
我想监控 CFNetwork 返回的结果,但是我不能收到返回结果,我使用的是 AFNetworking 做网络请求,但是我没能得到结果,请帮我指点一下,到底是哪里不对,难道一定要使用自己封装的 CFNetwork 请求网络才可以拿到交换的信息吗,我感觉只要底层是使用的 cfnetwork 作为请求底层应该就可以拿到信息,请帮忙看看是不是我哪里使用的不当导致的,谢谢。
我想用NSProxy实现webview的代理方法监听处理, 但delegate是weak的类型会提前释放,该怎么正确使用这个方案
size_t size = sizeof(int);
int results = 0;
int mib[2] = {CTL_HW, HW_CPU_FREQ};
int status = sysctl(mib, 2, &results, &size, NULL, 0);
NSString *cpuFrequency = [NSString stringWithFormat:@"%d", results];
return cpuFrequency;
这段代码
但是macos能够返回
oc和swift的方法还是有些不相同 谢谢
苹果在 WWDC 的 Optimizing App Startup Time 给出了定义
So when you launch an app, we talk about warm and cold launches.And a warm launch is an app where the application is already in memory, either because it's been launched and quit previously, and it's still sitting in the discache in the kernel, or because you just copied it over.
A cold launch is a launch where it's not in the discache. And a cold launch is generally the more important to measure.The reason a cold launch is more important to measure is that's when your user is launching an app after rebooting the phone, or for the first time in a long time, that's when you really want it to be instant.
感谢分享,收获很大。
文章里有一段
读者可能会看到有些代码会使用 vm_statistics_data_t 结构体,但是这个结构体是32位机器的,随着 Apple 逐渐放弃对32位应用的支持,所以建议读者还是使用 vm_statistics64_data_t 64位的结构体。
但我看到14.5的头文件定义里
/* Used by all architectures */
typedef struct vm_statistics *vm_statistics_t;
typedef struct vm_statistics vm_statistics_data_t;
是不是实际上用vm_statistics_data_t
更好一些?
文章很多内容和头条乐少的文章很相似,逻辑顺序也基本一致。
移动端监控体系之技术原理剖析
如果有参考的话,给个链接。或者是我想多了,你们异曲同工?
能发一份网络监控的源码吗, 大神
当内存一直增加,resident_size会停留在一个最大值(这个最大值会比resident_size_max小一点),然后不在增加.所以这个resident_size并不能真的代表app使用的内存.
用resident_size 去获取app的使用内存是不准确的.
Network监控里面用到的NSURLConnection,NSURLSession,CFNetwork,最底层还是使用的socket,我们要同时监控NSURLConnection,NSURLSession,CFNetwork。那为什么不直接监控iOS里面的socket呢?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.