简体   繁体   English

估算C库的内存占用量和CPU使用率

[英]Estimating memory footprint and CPU usage for a C library

I have a static library written in C, with no dynamic memory allocation. 我有一个用C编写的静态库,没有动态内存分配。

Until now, the library has only been used in an application for regular i386 Linux, where CPU and memory was plentiful. 到目前为止,该库仅用于常规i386 Linux的应用程序中,在该应用程序中CPU和内存充足。

I now need to try building a version of the library for an embedded, real-time ARM9 system (provided by a 3rd party). 我现在需要尝试为嵌入式实时ARM9系统(由第3方提供)构建该库的版本。 Before that I have to give some rough estimates of memory footprint and CPU usage. 在此之前,我必须对内存占用量和CPU使用率进行一些粗略的估算。

For memory footprint, I build a tiny application on my i386 machine, statically linking with my library, that exercises all the functions of my library. 为了节省内存,我在i386机器上构建了一个微型应用程序,它与我的库静态链接,并行使我的库的所有功能。 Is it roughly correct that checking the resident memory of this application will give me a ballpark estimate of my library's memory footprint? 检查此应用程序的常驻内存是否能大致估算出我的图书馆的内存占用量,是否大致正确? Is there a better way to measure it? 有更好的测量方法吗?

For estimating CPU usage, I'm at a loss. 为了估算CPU使用率,我很茫然。 I can of course run the test application mentioned above, on my i386 system, but I don't know what metrics that'll give me (if any) that can translate into something relateable to the ARM system. 我当然可以在i386系统上运行上面提到的测试应用程序,但是我不知道有什么度量标准(如果有的话)可以转化为与ARM系统相关的东西。 Is there a way to do it? 有办法吗?

Your memory estimate sounds pretty good to me, as long as you compiled it for ARM9 . 只要您为ARM9编译了内存,对我来说听起来就不错。 Actually, if you cross-compile the library without debug info, and you expect all the functions of the library to be used in the final application, then the file-size of the library is a pretty good ball-park estimate. 实际上,如果您在没有调试信息的情况下交叉编译该库,并且希望该库的所有功能都可以在最终应用程序中使用,则该库的文件大小是一个不错的估算。 The only way that wouldn't work is if you had a lot of zero-initialized global (or static) variables. 唯一不起作用的方法是,如果您有很多零初始化的全局(或静态)变量。 Run-time memory allocation is a different matter, of course, but you've accounted for that already. 当然,运行时内存分配是另一回事,但是您已经考虑了这一点。

Size estimates based on x86 code may be within the same ball-park, but really shouldn't be trusted. 基于x86代码的大小估计可能在同一范围内,但实际上不应该被信任。 Sizes do vary from compiler to compiler also, so try to match it if you can, but any recent ARM compiler is OK for a rough estimate. 大小确实会因编译器的不同而有所不同,因此,如果可以,请尝试将其匹配,但是任何最新的ARM编译器都可以进行粗略估算。

As for CPU estimates, that's impossible to put a figure on without measuring it. 至于CPU估计,如果不进行测量就不可能得出一个数字。 It's a function of the architectural efficiency of the CPU, effectiveness of compiler optimizations, clock rate, memory speed, bus speed, cache size, cache pressure caused by other running tasks, etc., etc., etc. There's just too many variables. 它是CPU的体系结构效率,编译器优化的有效性,时钟速率,内存速度,总线速度,缓存大小,由其他正在运行的任务等引起的缓存压力等的函数。变量太多了。

One thing you might be able to do is use big-O notation to say something about the performance of the algorithms on different input. 您可能能够做的一件事就是使用big-O表示法来说明算法在不同输入上的性能。

I'd probably just say "light", or "heavy". 我可能只会说“轻”或“沉重”。 You probably have an idea which of those fits. 您可能有一个合适的主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM