12

I am interested in profiling a module for the Linux Kernel. I tried it this way:

  1. Built the kernel with CONFIG_PROFILING=y
  2. Booted the kernel with profile=2
  3. Reset the profiler by echo 123 > /proc/profile
  4. The module was successfully loaded by a dedicated daemon
  5. Run a user-space app that is using the module through specific ioctl calls. The test app worked as expected so the module was working OK.
  6. Read the profiling info using readprofile -p /proc/profile -m System.map where System.app was generated along with the kernel.

So far, so good. Almost everything worked as expected. What did not work however, is that I didn't get any info about my module, i.e. there was no mention of any function from the module.

However, on second thoughts, I remebered that I forgot to recompile the module using the CONFIG_PROFILING=y.

So, my question is: Did the module not show up in the profiling log because it had not been compiled with the CONFIG_PROFILING=y or is there some other more obvious reason that I don't know of?

If one wonders, why I am asking rather than trying it straight away, that is because, I can't do it at home and I'd rather like to hear what the knowledgable would say before I get access to the code again.

Albus Dumbledore
  • 12,368
  • 23
  • 64
  • 105
  • 1
    I don't know. I would think your guess about the problem is correct since the common way to have profiling information is for the compiler to instrument the code. But, I'm wondering, does oprofile not work for your purposes? - http://oprofile.sourceforge.net/about/ – Omnifarious Apr 23 '11 at 09:08
  • Thanks! Oprofile seems to have a rather tedious installation and I'm not sure it supports ARM CPUs. – Albus Dumbledore Apr 23 '11 at 09:12
  • 1
    It's been a long time since I did anything in a *n*x kernel, but it has to be possible to run your module under a debugger like GDB. Then you can use [this basic technique](http://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux/378024#378024). – Mike Dunlavey Apr 23 '11 at 20:14
  • can you put here the source code? please – 0x90 Oct 24 '12 at 12:34

2 Answers2

6

It doesn't seem possible for modules to be profiled in this way as they are loaded dynamically, which means that they are missing from the System.map file.

A solution would be to build the driver into the kernel. Unfortunately, this does not always work as the system may be designed to run only with the driver built into a module.

Albus Dumbledore
  • 12,368
  • 23
  • 64
  • 105
0

I suggest that using oprofile should work.

sehe
  • 374,641
  • 47
  • 450
  • 633