【问题标题】:How to compile driver to be profiled with Gprof如何编译要使用 Gprof 分析的驱动程序
【发布时间】:2010-09-10 13:16:50
【问题描述】:

简单的问题..如何编译驱动程序以使用 Gprof 进行分析?

我当前的 Makefile:

obj-m += hello-2.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

工作正常(我可以加载驱动程序等),但如果我尝试将 -pg 选项添加到文件中,则会出现错误。

生成文件:

obj-m += hello-2.o

EXTRA_CFLAGS += -pg
LDFLAGS += -pg

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

我得到错误:

make -C /lib/modules/2.6.31/build M=/home/I/drivertest modules
make[1]: Entering directory `/home/I/linux-2.6.31'
  CC [M]  /home/I/drivertest/hello-2.o
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "mcount" [/home/I/drivertest/hello-2.ko] undefined!
  CC      /home/I/drivertest/hello-2.mod.o
  LD [M]  /home/I/drivertest/hello-2.ko
ld: unrecognized option '-pg'
ld: use the --help option for usage information
make[2]: *** [/home/I/drivertest/hello-2.ko] Error 1
make[1]: *** [modules] Error 2
make[1]: Leaving directory `/home/I/linux-2.6.31'
make: *** [all] Error 2

【问题讨论】:

    标签: linux linux-device-driver gprof


    【解决方案1】:

    您不能使用 gprof 分析内核模块。您需要编译启用了分析支持的内核并使用readprofile 工具。有关详细信息,请参阅the Linux kernel documentation

    【讨论】:

      【解决方案2】:

      即使您可以在内核模块上使用 gprof,它也从未被宣传为能够帮助您定位瓶颈。 More on that.

      【讨论】:

        【解决方案3】:

        -pg 是编译标志,而不是链接标志。从LDFLAGS 中删除它(显然将其留在EXTRA_CFLAGS 中)。

        【讨论】:

        猜你喜欢
        • 2014-01-23
        • 2013-10-17
        • 1970-01-01
        • 2019-07-12
        • 1970-01-01
        • 1970-01-01
        • 2016-02-23
        • 2022-10-06
        • 1970-01-01
        相关资源
        最近更新 更多