当前位置: 首页 > 编程日记 > 正文

Xcode中的NSLog详解

探究原因
基本上这种事情一定可以在Apple文档中找到,看NSLog的文档,第一句话就说:Logs an error message to the Apple System Log facility.,所以首先,NSLog就不是设计作为普通的debug log的,而是error log;其次,NSLog也并非是printf的简单封装,而是Apple System Log(后面简称ASL)的封装。
ASL
ASL是个啥?从官方手册上,或者从终端执行man 3 asl都可以看到说明:
These routines provide an interface to the Apple System Log facility. They are intended to be a replacement for the syslog(3) API, which will continue to be supported for backwards compatibility.
大概就是个系统级别的log工具吧,syslog的替代版,提供了一系列强大的log功能。不过一般我们接触不到,NSLog就对它提供了高层次的封装,如这篇文档所提到的:
You can use two interfaces in OS X to log messages: ASL and Syslog. You can also use a number of higher-level approaches such as NSLog. However, because most daemons are not linked against Foundation or the Application Kit, the low-level APIs are often more appropriate
一些底层相关的守护进程(deamons)不会link如Foundation等高层框架,所以asl用在这儿正合适;而对于应用层的用NSLog。
在CocoaLumberjack的文档中也说了NSLog效率低下的问题:
NSLog does 2 things:
- It writes log messages to the Apple System Logging (asl) facility. This allows log messages to show up in Console.app.
- It also checks to see if the application’s stderr stream is going to a terminal (such as when the application is being run via Xcode). If so it writes the log message to stderr (so that it shows up in the Xcode console).
To send a log message to the ASL facility, you basically open a client connection to the ASL daemon and send the message. BUT - each thread must use a separate client connection. So, to be thread safe, every time NSLog is called it opens a new asl client connection, sends the message, and then closes the connection.
意识大概是说,NSLog会向ASL写log,同时向Terminal写log,而且同时会出现在Console.app中(Mac自带软件,用NSLog打出的log在其中全部可见);不仅如此,每一次NSLog都会新建一个ASL client并向ASL守护进程发起连接,log之后再关闭连接。所以说,当这个过程出现N次时,消耗大量资源导致程序变慢也就不奇怪了。
时间和进程信息
主要原因已经找到,还有个值得注意的问题是NSLog每次会将当前的系统时间,进程和线程信息等作为前缀也打印出来,如:
2012-34-56 12:34:56.789 XXXXXXXX[36818:303] xxxxxx
当然这些也可能是作为ASL的参数创建的。

转载于:https://www.cnblogs.com/mumoozhu/p/4495260.html

相关文章:

java web程序示例_想要建立一些有趣的东西吗? 这是示例Web应用程序创意的列表。...

java web程序示例Interested in learning JavaScript? Get my ebook at jshandbook.com有兴趣学习JavaScript吗? 在jshandbook.com上获取我的电子书 If you’re reading this post, you are probably looking for an idea. You likely want to build a simple app …

python读取文件

请参考:http://www.cnblogs.com/sysuoyj/archive/2012/03/14/2395789.html转载于:https://www.cnblogs.com/yajing-zh/p/6807971.html

[Git/Github] ubuntu 14.0 下github 配置

转载自:http://www.faceye.net/search/77573.html 一:创建Repositories1:首先在github下创建一个帐号。这个不用多说,然后创建一个Repositories。2:然后在ubuntu下安装git相关的东东: 1sudo apt-get install git-core git-gui git…

php ile_get_contents无法请求https连接的解决方法

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文: 1.windows下的PHP,只需要到php.ini中把extensionphp_openssl.dll前面的;删掉,重启服务就可以了。

material-ui_满足Material-UI —您最喜欢的新用户界面库

material-uiby Code Realm通过Code Realm 满足Material-UI —您最喜欢的新用户界面库 (Meet Material-UI — your new favorite user interface library) Update (17/05/2018): Material-UI v1.0.0 is out! Check out this post by Olivier.更新 (17/05/2018):Mate…

day 2 基本类型和函数

列表,元组,字典的转换。list列表是一组可变的元素集合列表是[]括号组成的,[]括号包含所有元素,列表的创建可以传递字符串,也可以传递多个字符串来创建列表。如"asd", / "a","b" ...tupl…

手机号码输入历史记录匹配

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 效果图 html <view class"top_phone"><input placeholder"请输入手机号" typenumber bindinputtop_phone_input bindfocustop_phone_focus value{{ph…

Ubuntu安装Flash视频插件

http://www.linuxidc.com/Linux/2014-05/101095.htm转载于:https://www.cnblogs.com/acbingo/p/4501987.html

如何使用Web Audio API听到“ Yanny”和“ Laurel”的声音

by _haochuan通过_haochuan 如何使用Web Audio API听到“ Yanny”和“ Laurel”的声音 (How you can hear both “Yanny” and “Laurel” using the Web Audio API) Recently an audio clip asking listeners whether they hear the word “Yanny” or “Laurel” has been c…

SCARA——OpenGL入门学习一、二

参考博客&#xff1a;http://www.cppblog.com/doing5552/archive/2009/01/08/71532.html 简介 最近开始一个机械手臂的安装调试&#xff0c;平面关节型机器人又称SCARA(Selective Compliance Assembly Robot Arm)型机器人,是一种应用于装配作业的机器人手臂。然后找资料学习一下…

[.NET] 《Effective C#》快速笔记 - C# 中的动态编程

《Effective C#》快速笔记 - C# 中的动态编程 静态类型和动态类型各有所长&#xff0c;静态类型能够让编译器帮你找出更多的错误&#xff0c;因为编译器能够在编译时进行大部分的检查工作。C# 是一种静态类型的语言&#xff0c;不过它加入了动态类型的语言特性&#xff0c;可以…

阿里云https证书apache配置

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 一&#xff1a;下载证书&#xff1b; 二&#xff1a;安装证书 文件说明&#xff1a; 1. 证书文件1534884149377.pem&#xff0c;包含两段内容&#xff0c;请不要删除任何一段内容。…

vue css 应用变量_如何使用CSS Grid和CSS变量快速为应用创建原型

vue css 应用变量CSS Grid and CSS Variables are both huge wins for front-end developers. The former makes it dead simple to create website layouts, while the latter brings the power of variables to your stylesheets.CSS Grid和CSS变量对于前端开发人员都是巨大的…

linux--memcache的安装和使用(转)

memcache是高性能&#xff0c;分布式的内存对象缓存系统&#xff0c;用于在动态应用中减少数据库负载&#xff0c;提升访问速度。据说官方所说&#xff0c;其用户包括twitter、digg、flickr等&#xff0c;都是些互联网大腕呀。目前用memcache解决互联网上的大用户读取是非常流行…

EF 调试跟踪生成的SQL语句

IQueryable query from x in appEntitieswhere x.id 10select x;var sql ((System.Data.Objects.ObjectQuery)query).ToTraceString(); 或者 EF6 &#xff1a; var sql ((System.Data.Entity.Core.Objects.ObjectQuery)query).ToTraceString(); 转载于:https://www.cnblogs…

微信小程序图片自适应宽高比例显示解决方法

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 解决方案一&#xff1a;写固定宽度&#xff0c;然后使用 image 组件中 mode 属性的 widthFix &#xff1b; 先看效果图&#xff1a; 实现代码&#xff1a; <image classmy_img mo…

初创公司面试要问什么_聘请初创公司的产品设计师时要问的问题

初创公司面试要问什么by Bohdan Kit通过Bohdan Kit 聘请初创公司的产品设计师时要问的问题 (Questions to ask when hiring a product designer for a startup) 在人群中寻找隐藏宝石的方法指南 (A how-to guide on finding hidden gems in the crowd) Finding the right pers…

Select Top在不同数据库中的使用

1. oracle数据库 SELECT * FROM TABLE1 WHERE ROWNUM<N 2. Infomix数据库 SELECT FIRST N * FROM TABLE1 3. DB2数据库 SELECT * ROW_NUMBER() OVER(ORDER BY COL1 DESC) AS ROWNUM WHERE ROWNUM<N 或者 SELECT COLUMN FROM TABLE FETCH FIRST N ROWS ONLY 4. SQL Server…

bat+sqlcmd 批量执行脚本

Hello,此BAT脚本能够帮助开发者将某目录下全部SQL脚本按文件名称依次在指定数据库中批量执行。不用忍受powershell invoke-sqlcmd 的笨重。在指执行时多一种选择。 bat文件 echo off REM ******** ******** General Batch for Starting SQL ******** ******** REM %1 is the n…

突破微信小程序五层层级限制的解决方案

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 五层的限制只是针对 navigateTo&#xff0c;redirectTo 不受此限制。 navigateTo &#xff1a;保留当前页面&#xff0c;跳转到应用内的某个页面&#xff0c;使用wx.navigateBack可以…

react-dnd-dom_我如何使用react-dnd和react-flip-move构建React游戏

react-dnd-domby Nicholas Vincent-Hill尼古拉斯文森特希尔(Nicholas Vincent-Hill) 我如何使用react-dnd和react-flip-move构建React游戏 (How I built a React game with react-dnd and react-flip-move) This is a high level overview of my implementation of a puzzle/w…

web应用程序和web网站_Web应用程序和移动应用程序的基本启动清单

web应用程序和web网站by Ben Cheng通过本诚 Web应用程序和移动应用程序的基本启动清单 (The Essential Launch Checklist for Web Apps and Mobile Apps) This is a simple launch checklist for web and mobile apps that I’ve prepared for product and project managers t…

javascript禁止修改对象

禁止扩展 Object.preventExtensions(obj);var me {name: "xiaowtz" }; console.log(Object.isExtensible(me)); //true,对象默认都是可扩展的Object.preventExtensions(me); //禁止对象扩展后&#xff0c;不可以给对象添加新的属性console.log(Object.isExtensible(…

webpack入门之简单例子跑起来

webpack入门之简单例子跑起来 webpack介绍 Webpack是当下最热门的前端资源模块化管理和打包工具&#xff0c;它可以将很多松散的模块按照依赖和规则打包成符合生产环境部署的前端资源&#xff0c;还可以将按需加载的模块进行代码分割&#xff0c;等到实际需要的时候再异步加载。…

微信小程序 scroll-view 根据内容的高度自适应

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 1 <video autoplay src"{{videoPlayUrl}}" controls></video> <scroll-view scroll-y style"height: {{height?heightpx:auto}}"><view c…

org.hibernate.hibernate.connection.release_mode

org.hibernate.connection包的主要封装了通过JDBC来连接数据库的操作&#xff0c;用户可以以数据源的方式&#xff0c;或者通过特定数据库驱动的方式&#xff0c;甚至是自己定义连接类的方式来完成数据库的连接操作&#xff0c;包下面的代码文件并不多&#xff0c;只有5个&…

添加百度地图最简单的办法

http://map.baidu.com/?newmap1&ieutf-8&ss%26wd%3D%E4%B8%8A%E6%B5%B7%E9%9D%92%E6%B5%A6%E5%8C%BA%E5%BE%90%E9%BE%99%E8%B7%AF77%E5%8F%B7后面加上地址就好了 比方说&#xff1a;http://map.baidu.com/?newmap1&ieutf-8&ss%26wd%3D%E4%B8%8A%E6%B5%B7%E9%…

微信小程序的数字有部分会自动加粗的解决方法

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; bug图&#xff1a; 能看到&#xff0c;0和1是一个标签里面的&#xff0c;但是不统一显示 此时的代码&#xff1a; <view>2018-08-01</view> 修改后的代码&#xff1a;…

ux设计_从UX设计人员的角度来看Microsoft Build 2018

ux设计by Samuele Dassatti通过萨穆尔达萨蒂 从UX设计人员的角度来看Microsoft Build 2018 (Microsoft Build 2018 from the perspective of a UX designer) I recently attended Microsoft Build 2018 in Seattle, because one of my apps was nominated for Design Innovato…

DFS template and summary

最近一直在学习Deep Frist Search&#xff0c;也在leetcode上练习了不少题目。从最开始的懵懂&#xff0c;到现在遇到问题基本有了思路。依然清晰的记得今年2月份刚开始刷题的时做subsets的那个吃力劲&#xff0c;脑子就是转不过来到底该如何的递归&#xff0c;甚至试过使用deb…