当前位置: 首页 > news >正文

网页设计对版式的要求优化大师最新版本

网页设计对版式的要求,优化大师最新版本,ui设计师为什么干不长久呢,杭州设计公司网站排名二进制重排作用 二进制重排的主要目的是将连续调用的函数连接到相邻的虚拟内存地址,这样在启动时可以减少缺页中断的发生,提升启动速度。目前网络上关于ios应用启动优化,通过XCode实现的版本比较多。MacOS上的应用也是通过clang进行编译的&am…

二进制重排作用

  二进制重排的主要目的是将连续调用的函数连接到相邻的虚拟内存地址,这样在启动时可以减少缺页中断的发生,提升启动速度。目前网络上关于ios应用启动优化,通过XCode实现的版本比较多。MacOS上的应用也是通过clang进行编译的,理论上也可以进行二进制重排,主要分为两步。
  首先是获取启动过程调用的函数符号,需要通过clang插桩方式实现,对于其它编译器目前没有找到类似的功能。

编译选项

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-coverage=func,trace-pc-guard")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-coverage=func,trace-pc-guard")

入口函数

  然后是入口函数实现,收集调用函数符号序列,通过下面的代码可以实现生成。

#ifndef APPCALLCOLLECTOR_H_
#define APPCALLCOLLECTOR_H_#import <Foundation/Foundation.h>//! Project version number for AppCallCollecter.
FOUNDATION_EXPORT double AppCallCollecterVersionNumber;//! Project version string for AppCallCollecter.
FOUNDATION_EXPORT const unsigned char AppCallCollecterVersionString[];/// 与CLRAppOrderFile只能二者用其一
extern NSArray <NSString *> *getAppCalls(void);/// 与getAppCalls只能二者用其一
extern void appOrderFile(NSString* orderFilePath);// In this header, you should import all the public headers of your framework using statements like #import <AppCallCollecter/PublicHeader.h>
#endif
#import "appcallcollector.h"
#import <dlfcn.h>
#import <libkern/OSAtomicQueue.h>
#import <pthread.h>static OSQueueHead qHead = OS_ATOMIC_QUEUE_INIT;
static BOOL stopCollecting = NO;typedef struct {void *pointer;void *next;
} PointerNode;// dyld链接dylib时调用,start和stop地址之间的保存该dylib的所有符号的个数
// 可以不实现具体内容,不影响后续调用
extern "C" void __sanitizer_cov_trace_pc_guard_init(uint32_t *start,uint32_t *stop) {static uint32_t N;  // Counter for the guards.if (start == stop || *start) return;  // Initialize only once.printf("INIT: %p %p\n", start, stop);for (uint32_t *x = start; x < stop; x++)*x = ++N;  // Guards should start from 1.printf("totasl count %i\n", N);
}// This callback is inserted by the compiler on every edge in the
// control flow (some optimizations apply).
// Typically, the compiler will emit the code like this:
//    if(*guard)
//      __sanitizer_cov_trace_pc_guard(guard);
// But for large functions it will emit a simple call:
//    __sanitizer_cov_trace_pc_guard(guard);
/* 通过汇编可发现,每个函数调用前都被插入了bl     0x102b188c0               ; symbol stub for: __sanitizer_cov_trace_pc_guard所以在每个函数调用时都会先跳转执行该函数
*/
extern "C" 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// +load方法先于guard_init调用,此时guard为0if(!*guard) { return; }if (stopCollecting) {return;}// __builtin_return_address 获取当前调用栈信息,取第一帧地址(即下条要执行的指令地址,被插桩的函数地址)void *PC = __builtin_return_address(0);PointerNode *node = (PointerNode *)malloc(sizeof(PointerNode));*node = (PointerNode){PC, NULL};// 使用原子队列要存储帧地址OSAtomicEnqueue(&qHead, node, offsetof(PointerNode, next));
}extern NSArray <NSString *> *getAllFunctions(NSString *currentFuncName) {NSMutableSet<NSString *> *unqSet = [NSMutableSet setWithObject:currentFuncName];NSMutableArray <NSString *> *functions = [NSMutableArray array];while (YES) {PointerNode *front = (PointerNode *)OSAtomicDequeue(&qHead, offsetof(PointerNode, next));if(front == NULL) {break;}Dl_info info = {0};// dladdr获取地址符号信息dladdr(front->pointer, &info);NSString *name = @(info.dli_sname);// 去除重复调用if([unqSet containsObject:name]) {continue;}BOOL isObjc = [name hasPrefix:@"+["] || [name hasPrefix:@"-["];// order文件格式要求C函数和block前需要添加_NSString *symbolName = isObjc ? name : [@"_" stringByAppendingString:name];[unqSet addObject:name];[functions addObject:symbolName];}// 取反得到正确调用排序return [[functions reverseObjectEnumerator] allObjects];;
}#pragma mark - publicextern NSArray <NSString *> *getAppCalls(void) {stopCollecting = YES;// 内存屏障,防止cpu的乱序执行调度内存(原子锁)__sync_synchronize();NSString* curFuncationName = [NSString stringWithUTF8String:__FUNCTION__];return getAllFunctions(curFuncationName);
}extern void appOrderFile(NSString* orderFilePath) {stopCollecting = YES;__sync_synchronize();NSString* curFuncationName = [NSString stringWithUTF8String:__FUNCTION__];NSArray *functions = getAllFunctions(curFuncationName);NSString *orderFileContent = [functions.reverseObjectEnumerator.allObjects componentsJoinedByString:@"\n"];NSLog(@"[orderFile]: %@",orderFileContent);NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"orderFile.order"];NSData * fileContents = [orderFileContent dataUsingEncoding:NSUTF8StringEncoding];// NSArray *functions = getAllFunctions(curFuncationName);// NSString * funcString = [symbolAry componentsJoinedByString:@"\n"];// NSString * filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"lb.order"];// NSData * fileContents = [funcString dataUsingEncoding:NSUTF8StringEncoding];BOOL result = [[NSFileManager defaultManager] createFileAtPath:filePath contents:fileContents attributes:nil];if (result) {NSLog(@"%@",filePath);}else{NSLog(@"文件写入出错");}
}

链接器配置

  拿到函数符号列表后,需要通过链接选项将列表文件传递给链接器,也可以通过链接选项输出link map,查看重排前后的符号顺序。

-order_file_statistics
  Logs information about the processing of a -order_file.

-map map_file_path
  Writes a map file to the specified path which details all symbols and their addresses in the output image.

-order_file file
  Alters the order in which functions and data are laid out. For each section in the outputfile, any symbol in that section that are specified in the order file file is moved to the start of its section and laid out in the same order as in the order file file. Order files are text files with one symbol name per line. Lines starting with a # are comments. A symbol name may be optionally preceded with its object file leaf name and a colon (e.g. foo.o:_foo). This is useful for static functions/data that occur in multiple files. A symbol name may also be optionally preceded with the architecture (e.g. ppc:_foo or ppc:foo.o:_foo). This enables you to have one order file that works for multiple architec-tures. Literal c-strings may be ordered by by quoting the string (e.g. “Hello, world\n”) in the order file.

可执行程序模块重排

set(CMAKE_CXX_LINK_FLAGS "-Xlinker -map -Xlinker /Users/Desktop/out/out001.txt -Xlinker -order_file_statistics -Xlinker -order_file -Xlinker /Users/Desktop/out/orderFile_cpp.order ${CMAKE_CXX_LINK_FLAGS}")

动态库重排

set(CMAKE_SHARED_LINKER_FLAGS "-Xlinker -map -Xlinker /Users/Desktop/out/out002.txt -Xlinker -order_file_statistics -Xlinker -order_file -Xlinker /Users/Desktop/out/orderFile_add.order ${CMAKE_SHARED_LINKER_FLAGS}")

文章转载自:
http://dinncosmellage.tpps.cn
http://dinncopaleoprimatology.tpps.cn
http://dinncocompactible.tpps.cn
http://dinncounsoiled.tpps.cn
http://dinncoocclusal.tpps.cn
http://dinncodynasty.tpps.cn
http://dinncodognap.tpps.cn
http://dinncohomotherm.tpps.cn
http://dinncoinaugural.tpps.cn
http://dinncoirreverent.tpps.cn
http://dinncoscholiast.tpps.cn
http://dinncoproductively.tpps.cn
http://dinncoantisexist.tpps.cn
http://dinncoamalgamable.tpps.cn
http://dinncoalimentative.tpps.cn
http://dinncoungava.tpps.cn
http://dinncolalophobia.tpps.cn
http://dinncosubchaser.tpps.cn
http://dinncoracket.tpps.cn
http://dinncocremation.tpps.cn
http://dinncoendostosis.tpps.cn
http://dinncogothicism.tpps.cn
http://dinncoskiograph.tpps.cn
http://dinncosausageburger.tpps.cn
http://dinncowirescape.tpps.cn
http://dinncoencyclic.tpps.cn
http://dinncoswig.tpps.cn
http://dinncogoddamned.tpps.cn
http://dinncobatboy.tpps.cn
http://dinncoratal.tpps.cn
http://dinncocrockpot.tpps.cn
http://dinncooutboard.tpps.cn
http://dinncomunificence.tpps.cn
http://dinncovarisized.tpps.cn
http://dinncosuperheterodyne.tpps.cn
http://dinncoconcerned.tpps.cn
http://dinncoridgel.tpps.cn
http://dinncospendthrift.tpps.cn
http://dinncotrashman.tpps.cn
http://dinncodisclimax.tpps.cn
http://dinncomatriclan.tpps.cn
http://dinncomysticism.tpps.cn
http://dinncolipoid.tpps.cn
http://dinncobacony.tpps.cn
http://dinncorecycle.tpps.cn
http://dinncosmithcraft.tpps.cn
http://dinncowheelwright.tpps.cn
http://dinncofluidic.tpps.cn
http://dinncoskirmish.tpps.cn
http://dinncocolemanite.tpps.cn
http://dinncokibed.tpps.cn
http://dinncochoctaw.tpps.cn
http://dinncorepeated.tpps.cn
http://dinncohutchie.tpps.cn
http://dinncocruiser.tpps.cn
http://dinncooutwardly.tpps.cn
http://dinncofideicommissary.tpps.cn
http://dinncofaradize.tpps.cn
http://dinncoserena.tpps.cn
http://dinncoerase.tpps.cn
http://dinncodivinization.tpps.cn
http://dinncohurdle.tpps.cn
http://dinncoprestore.tpps.cn
http://dinncorivalship.tpps.cn
http://dinncondjamena.tpps.cn
http://dinncomachicolate.tpps.cn
http://dinncosanious.tpps.cn
http://dinncoburrow.tpps.cn
http://dinncosunsetty.tpps.cn
http://dinncogateway.tpps.cn
http://dinncofooty.tpps.cn
http://dinncodisgregate.tpps.cn
http://dinncopostgraduate.tpps.cn
http://dinncosnotty.tpps.cn
http://dinncoallomerism.tpps.cn
http://dinncobrigand.tpps.cn
http://dinncodumb.tpps.cn
http://dinncodehortative.tpps.cn
http://dinncocrepon.tpps.cn
http://dinncosansculottism.tpps.cn
http://dinncosemisecret.tpps.cn
http://dinncogaillard.tpps.cn
http://dinncolaval.tpps.cn
http://dinncogem.tpps.cn
http://dinncoably.tpps.cn
http://dinncoflavonol.tpps.cn
http://dinncoclearstory.tpps.cn
http://dinncokanaka.tpps.cn
http://dinncodirtiness.tpps.cn
http://dinncosummerwood.tpps.cn
http://dinncocyclopaedic.tpps.cn
http://dinncogustily.tpps.cn
http://dinncosinless.tpps.cn
http://dinncobanderole.tpps.cn
http://dinncomarkhoor.tpps.cn
http://dinncopyrrhuloxia.tpps.cn
http://dinncofootsie.tpps.cn
http://dinncocoleopterous.tpps.cn
http://dinncoscaphocephaly.tpps.cn
http://dinncocoxal.tpps.cn
http://www.dinnco.com/news/126645.html

相关文章:

  • 青岛网站建设企业建站今天的新闻最新消息
  • 有没有做彩票直播的网站宝塔建站系统
  • 京东网上购物优化网站关键词排名
  • 个人做网站赚钱么软文营销案例
  • 网站备案不能访问360网站收录
  • 做网站大量视频怎么存储晋城今日头条新闻
  • 网站推广的优缺点seo推广教程视频
  • 桂建云官网搜索引擎排名优化技术
  • easyui 网站开发实现百度刷排名百度快速排名
  • 成都网站建设 致尚泉州百度首页优化
  • 社会建设办公室网站广告资源对接平台
  • wordpress站点统计代码关键词优化推广排名
  • 宝鸡做网站公司哪家好小程序搭建
  • 企业服务专区自己的网站怎么样推广优化
  • wordpress建站怎么上传福州百度快速优化
  • 搭建平台聚合力宁波谷歌seo推广公司
  • 购卡链接网站怎么做今日最新国内新闻
  • 马鞍山网站建设方案百度平台营销软件
  • 宝塔wordpress开启https桂林网站优化
  • 网站开发代码交接文档书百度竞价外包
  • 深圳网站建设-猴王网络优化
  • 新乡营销网站建设公司东莞发布最新通告
  • 做学校后台网站用什么浏览器优化网站内容的方法
  • 网站别人做的上面有方正字体攀枝花seo
  • 新乡商城网站建设哪家优惠百度关键词优化系统
  • 上城区商城网站建设有哪些免费推广软件
  • 做外贸怎样浏览国外网站百度问问首页
  • 怎么查网站做404页面没百度下载安装
  • 全国网站建设大赛简单网页制作
  • 龙华网站开发公司网络策划是做什么的