Giter VIP home page Giter VIP logo

ios-monitor-platform's Issues

获取 App 内存不准

- (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 图形化

您好,请问是否有 API 图形化的计划?

只有 API 的话,个人觉得还是有一定使用门槛的。如果能够像 logo.gif 所展示的那样把数据实时的展示出来,我觉得使用起来会更方便,工具的受众也会扩大不少。

希望能考虑一下。

使用NSProxy的时候遇到问题了

我在使用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];
    }

@EnD

@interface NSURLDelegateProxy()
@Property(nonatomic, weak) id proxyTarget;

@EnD

@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

ReadMe中的获取应用占用内存方法错误

 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了

Xcode13 thread_info failed

想问下获取CPU时, Xcode13调试,通过thread_info获取线程信息失败,有对应的解决办法么?目前看 kr != KERN_SUCCESS的判断去掉就ok了,kr的值在枚举中没有对应的。

使用CFReadStreamCreateForHTTPRequest 截取网络请求,无果!

@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

我想用NSProxy实现webview的代理方法监听处理, 但delegate是weak的类型会提前释放,该怎么正确使用这个方案

发现获取cpu频率的函数iOS上并不能正常工作

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能够返回

关于冷热启动的概念描述不对

苹果在 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.

Readme里关于`vm_statistics_data_t`的描述

感谢分享,收获很大。

文章里有一段

读者可能会看到有些代码会使用 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会停留在一个最大值(这个最大值会比resident_size_max小一点),然后不在增加.所以这个resident_size并不能真的代表app使用的内存.

用resident_size 去获取app的使用内存是不准确的.

网络监控里面为什么不直接hook socket

Network监控里面用到的NSURLConnection,NSURLSession,CFNetwork,最底层还是使用的socket,我们要同时监控NSURLConnection,NSURLSession,CFNetwork。那为什么不直接监控iOS里面的socket呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.