kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: Bharath Vedartham <linux.bhar@gmail.com>
To: Pedro Terra Delboni <terra0009@gmail.com>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: how to collect information regarding function calls in run time?
Date: Thu, 4 Apr 2019 01:45:06 +0530	[thread overview]
Message-ID: <20190403201506.GA4664@bharath12345-Inspiron-5559> (raw)
In-Reply-To: <CAHKDPP9rTJC3oaMOUkEEfa=-=OETMxfR1VpUHyUGh13zzH_3PQ@mail.gmail.com>

On Wed, Apr 03, 2019 at 04:25:02PM -0300, Pedro Terra Delboni wrote:
> Hello!
> 
> I have a question about profiling, please, let me know if this is not
> the right mailing list to post these kind of questions.
>
> Is there a way for me to record how many times each specific direct
> call to a function happened?
> I've seen ways of profiling the kernel that calculate how much time
> the system spent in each function, but having a bit more information
> related to calls would be really good.
> 
> I would like to know, for every function call that happens in run
> time, who called it (it's for a project in my University).
> 
> I've also seen (I may be mistaken here) that by compiling the kernel
> with perf, each function will start with a stub call which can be used
> for profiling purposes.
> I was thinking in using this stub to plug a function to dump
> (somewhere) the return address before it's own (so I can collect the
> info about where the call came from).
> I wonder if changing every stub calls in all functions to dump its
> return address wouldn't create too much of a latency impact to the
> point of skewing the control flow of the execution,
> or even making it nonviable.
> 
> Thanks in advance, any help would be great!
> If this is not the right place to post this question, I would
> appreciate if anyone could point me to the right place.
> 
> Thanks
> Pedro
>
I am assuming your talking about profiling functions in the linux kernel.
You can the kernel tracing infrastructure called kprobes to record how
many times a function is called by a particular process or for a time
interval. Kprobes will dynamically put a 'tracepoint'(if you use
debuggers it is similar to 'breakpoints') at the function call. 
You can then trace that particular function to see how many times its called and stuff like that. 
Luckily perf comes with kprobes! yay!
eg:
	perf probe --add <function_name> 
This will add a probe to the function. You can then trace it by:
	perf record -e <function_name> <options>

The perf.data file will give you all the info you need. 
Also for better output from perf, enable CONFIG_FRAME_POINTER in your
kernel build(assuming it is a custom build).
Check this out for more info:
     http://www.brendangregg.com/perf.html
There is similar functionality in user space. It is called uprobes(user
probes) similar to kprobes(kernel probes).

Now before you click on the above link, use kprobes only for functions
which do not have a static tracepoint. Certain interesting functions like system
calls, scheduler specific functions, mm functions like kmalloc etc. You
can find the static tracepoints in /sys/kernel/debug/tracing/events. You
do not need kprobes. For example if your tracing the write system call,
you can just do:
	perf record -e syscalls:sys_enter_write -ag 1 (For system wide
	tracing.)

Again check out the above link for more info!

Hope I was helpful!


> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kerne
lnewbies.org/mailman/listinfo/kernelnewbies

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  reply	other threads:[~2019-04-03 20:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-03 19:25 how to collect information regarding function calls in run time? Pedro Terra Delboni
2019-04-03 20:15 ` Bharath Vedartham [this message]
     [not found] ` <CADFy_4FJODA9gT7Enb+eLt-bdJBkkgTmqhhb3AhJhjibgbzD2A@mail.gmail.com>
2019-05-14 13:55   ` Pedro Terra Delboni
2019-05-14 14:05     ` Greg KH
2019-05-14 14:14       ` Pedro Terra Delboni
2019-05-14 17:45     ` Valdis Klētnieks
2019-05-14 19:11       ` Pedro Terra Delboni
2019-05-17 14:09         ` Valdis Klētnieks
2019-05-17 16:19           ` Pedro Terra Delboni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190403201506.GA4664@bharath12345-Inspiron-5559 \
    --to=linux.bhar@gmail.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=terra0009@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).