zoukankan      html  css  js  c++  java
  • 启动优化优秀文章和部分内容摘录

    https://mp.weixin.qq.com/s/LSj63THjgt2XKxkapAQpCg

    首先在other C flag中增加下面这段:-fsanitize-coverage=func,trace-pc-guard

    #import <dlfcn.h>
    #import <libkern/OSAtomicQueue.h>
    #import <pthread.h>
    
    typedef struct {
        void *ptr;
        NSInteger number;
    } CLRCall;
    
    static OSQueueHead sQueueData = OS_ATOMIC_QUEUE_INIT;
    static OSQueueHead *sQueue = &sQueueData;
    static BOOL sStopCollecting = NO;
    static BOOL sInitDidOccur = NO;
    
    typedef struct {
        void *pointer;
        void *next;
    } PointerNode;
    
    void __sanitizer_cov_trace_pc_guard_init(uint32_t *start, uint32_t *stop) {
        sInitDidOccur = YES;
        for (uint32_t *x = start; x < stop; x++) {
            *x = 1;
        }
    }
    
    void __sanitizer_cov_trace_pc_guard(uint32_t *guard) {
        // If initialization has not occurred yet (meaning that guard is uninitialized), that means that initial functions like +load are being run. These functions will only be run once anyways, so we should always allow them to be recorded and ignore guard
        if (sStopCollecting || (!(*guard) && sInitDidOccur)) {
            return;
        }
        *guard = 0;
        void *pointer = __builtin_return_address(0);
        PointerNode *node = malloc(sizeof(PointerNode));
        *node = (PointerNode){pointer, NULL};
        OSAtomicEnqueue(sQueue, node, offsetof(PointerNode, next));
    }
    
    extern NSArray <NSString *> *CLRCollectCalls(void) {
        sStopCollecting = YES;
        __sync_synchronize();
        // Hopefully, any other threads for which sStopCollecting was NO when they entered and are still preempted will get to preempt
        // during this sleep and finish up
        sleep(1);
        NSMutableArray <NSString *> *functions = [NSMutableArray array];
        while (YES) {
            PointerNode *node = OSAtomicDequeue(sQueue, offsetof(PointerNode, next));
            if (node == NULL) {
                break;
            }
            Dl_info info = {0};
            dladdr(node->pointer, &info);
            NSString *name = @(info.dli_sname);
            BOOL isObjc = [name hasPrefix:@"+["] || [name hasPrefix:@"-["];
            NSString *symbolName = isObjc ? name : [@"_" stringByAppendingString:name];
            [functions addObject:symbolName];
        }
        return [[functions reverseObjectEnumerator] allObjects];
    }
    
  • 相关阅读:
    Linux shell read命令
    mysql 详解 01
    centos 6/7 mysql 5.7 修改root密码 mysql root密码找回
    iptables基本原理讲解与规则的增删改查
    nginx反向代理https访问502, nginx反向代理, 支持SNI的https回源,SNI源点,nginx反向代理报错
    nginx 配置 强制访问https
    有名管道FIFO进程间数据传输实例
    命名管道FIFO及其读写规则
    224、Basic Calculator
    (匿名)管道的读写规则
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/14187778.html
Copyright © 2011-2022 走看看