获取 OS X 中的 CPU 时间

发布于 2024-08-04 15:39:25 字数 385 浏览 2 评论 0原文

我有一个适用于 OS X 的 Objective-C 应用程序,它比较两个 sqlite DB 并生成 json 格式的差异。数据库非常大(10,000 个项目,有很多字段)。有时,此应用程序运行时间约为 55 秒(使用 95% 的 CPU)。有时需要大约 8 分钟(使用 12% 的 CPU)。这是使用相同的数据库。当它只使用一小部分 CPU 时,其余部分可用。似乎没有什么比这个过程优先的事情。在命令中添加“nice -20”似乎可以确保我获得 cpu 使用情况。我的问题是

  1. 如果没有其他东西在使用CPU,为什么 我的应用程序没有利用 是吗?

  2. 有什么我可以做的吗 以编程方式改变这个?

  3. 我可以对 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你げ笑在眉眼 2024-08-11 15:39:25

问题 1:

我假设您必须从磁盘读取数据库,因此您没有充分利用 CPU,因为您的代码阻塞了磁盘读取。在 Mac OS X 上,有很多东西在后台运行,它们不会占用大量 CPU 时间,但会发出大量磁盘读取操作,例如 Spotlight。

问题 2:

可能不会,除非能够最有效地利用磁盘访问。

问题 3:

关闭正在访问磁盘的所有其他进程。这包括许多你确实不应该关闭的系统进程,所以我认为除了尝试在没有 Mac OS X 的所有功能的 Darwin 上运行它之外,你在这里没有什么可以做的。

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.

稀香 2024-08-11 15:39:25

当你的程序使用很少的CPU时,可能是因为它正在等待磁盘,特别是当其他进程同时访问磁盘时。另一种可能性是您的程序使用了太多内存,并且操作系统开始使用交换空间。

When your program uses little CPU, probably because it is waiting for disk, especially when other processes are accessing to the disk at the same time. Another possibility is your program uses too much memory and the OS begins to use swap space.

凶凌 2024-08-11 15:39:25

听起来你在长的情况下受 IO 限制。您还在机器上做其他事情吗? CPU 并没有自我限制——它肯定在等待某些东西。

您可以使用一些开发人员工具在应用程序运行时查看应用程序 - 也许最有用的是“Instruments”,它是 dtrace 之上的 GUI。如果您运行的是最新的 Xcode,则应该安装它。您还可以使用 Shark,乍一看它更容易使用,但从长远来看,它提供的信息较少。

It sounds like you're IO bound in the long cases. Are you doing anything else on the machine? The CPU isn't throttling itself - it's definitely waiting for something.

You can use some of the developer tools to look at your app while it's running - perhaps most useful would be "Instruments", which is a GUI on top of dtrace. You should have this installed if you're running the most recent Xcode. You can also use Shark, which is somewhat easier to use at first glance, but less informative in the long run.

烟若柳尘 2024-08-11 15:39:25

通常您可以获得所有可用的性能。如果 CPU 未达到 100%,则有东西阻碍了它。对于数据库来说,它通常是锁定的。使用 Shark 来了解您的应用程序中发生了什么。

Usually you get all the performance that's available. If the CPU is not at 100% there's something blocking it. In case of databases it's often locking. Use Shark to find out what's going on in your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文