获得CPU时间在OS X [英] Getting CPU time in OS X

查看:154
本文介绍了获得CPU时间在OS X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对OS X的一个Objective-C的应用程序,比较两个sqlite的DB的,并产生一个JSON格式的差异。该数据库是相当大(10,000项与许多领域)。有时这个应用中约为55秒运行(使用CPU的95%)。有时需要约8分钟(使用CPU的12%)。这是使用相同的DB的。当它仅使用CPU的一小部分,其余是可用的。似乎没有被任何服用优先的处理。加入好看-20的命令,似乎保证我得到的CPU使用率。我的问题是


  1. 如果没有其他正在使用的CPU为什么
    我的应用程序没有利用
    呢?


  2. 有什么我可以做
    编程改变这种?


  3. 有什么我可以做的OS X操作系统
    改变呢?



解决方案

问1:

一直以来,我认为,你从磁盘数据库读取,你是不是因为你的code被阻塞在磁盘读取,充分利用CPU的。在Mac OS X上有很多东西在后台运行,不使用大量的CPU时间,但并散发出大量的磁盘的读操作,就像聚光灯下。

问题2:

或许不会,除了最有效地利用磁盘访问成为可能。

问题3:

关闭正在访问磁盘的任何其他进程。这包括许多系统进程,你真的不应该关机,所以我不认为有什么可以做,在这里除了尝试运行它达尔文没有所有的Mac OS X的空想。

I have an objective-c application for OS X that compares two sqlite DB's and produces a diff in json format. The db are quite large (10,000 items with many fields). Sometimes this applications runs in about 55 sec(using 95% of the cpu). Sometimes it takes around 8 min (using 12% of the cpu). This is with the same DB's. When it is only using a small portion of the cpu the rest is available. There does not appear to be anything taking priority over the process. Adding "nice -20" on the command seems to assure I get the cpu usage. My questions are

  1. If nothing else is using the cpu why does my app not take advantage of it?

  2. Is there something I can do programatically to change this?

  3. Is there something I can do to OS X to change this?

解决方案

Question 1:

Since, I assume, you have to read in the databases from disk, you aren't making full use of the CPU because your code is blocking on disk reads. On Mac OS X there is a lot of stuff running in the background that doesn't use a lot of CPU time but does send out a lot of disk reads, like Spotlight.

Question 2:

Probably not, other than make the most efficient use of disk access possible.

Question 3:

Shut down any other processes that are accessing the disk. This includes many system processes that you really shouldn't shut down, so I don't think there's much you can do here other than try running it on Darwin without all the Mac OS X fanciness.

这篇关于获得CPU时间在OS X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆