什么呢编译器的-p和-g标志 [英] what does the -p and -g flag in compiler

查看:126
本文介绍了什么呢编译器的-p和-g标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在分析一个C code和这样做,我使用-p和-g标志进行编译。所以我徘徊做这些标志实际上做什么开销?他们添加到二进制?
谢谢

I have been profiling a C code and to do so I compiled with -p and -g flags. So I was wandering what do these flags actually do and what overhead do they add to the binary? Thanks

推荐答案

-p 教授信息,和 -pg 为提供信息 gprof的

-p provides information for prof, and -pg provides information for gprof.

让我们来看看后者。
下面是如何 gprof的作品
但让我在这里凝结了。

Let's look at the latter. Here's an explanation of how gprof works, but let me condense it here.

在例行B与 -pg 编译一些code插在例行的入口点查找该程序被调用它,说A.
然后,计数器加一说,一个称为B

When a routine B is compiled with -pg, some code is inserted at the routine's entry point that looks up which routine is calling it, say A. Then it increments a counter saying that A called B.

然后执行code时,两件事情正在发生。
第一是那些计数器被递增。
第二个是定时器中断正在发生,而且是每一个常规的计数器,说有多少中断发生时,PC是常规。

Then when the code is executed, two things are happening. The first is that those counters are being incremented. The second is that timer interrupts are occurring, and there is a counter for each routine, saying how many of those interrupts happened when the PC was in the routine.

定时器中断发生在一定的速度,例如每秒100次。
那么,如果,例如,676中断发生在程序中,你可以告诉它的自我时间约为6.76秒,S $ P $垫在所有调用它。

The timer interrupts happen at a certain rate, like 100 times per second. Then if, for example, 676 interrupts occurred in a routine, you can tell that its "self time" was about 6.76 seconds, spread over all the calls to it.

什么是调用计数允许你要做的就是把它们加起来告诉例程调用多少次,所以你可以除以到其自身的总时间估计每个呼叫多少自我的时间。
然后,你就可以开始评估累计时间。
这是在例行花费的时间,加上时间,它调用子程序度过的,等下到调用树的底部。

What the call counts allow you to do is add them up to tell how many times a routine was called, so you can divide that into its total self time to estimate how much self time per call. Then from that you can start to estimate "cumulative time". That's the time spent in a routine, plus time spent in the routines that it calls, and so on down to the bottom of the call tree.

这是所有有趣的技术,1982年,但如果你的目标是要找到办法,加快程序,的它有很多问题的。

This is all interesting technology, from 1982, but if your goal is to find ways to speed up your program, it has a lot of issues.

这篇关于什么呢编译器的-p和-g标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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