#include "op_hw_config.h"
#include "opd_proc.h"
#include "opd_image.h"
#include "opd_mapping.h"
#include "opd_sample_files.h"
#include "opd_kernel.h"
#include "opd_24_stats.h"
#include "opd_printf.h"
#include "oprofiled.h"
#include "op_interface.h"
#include "op_libiberty.h"
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
Defines | |
#define | OPD_MAX_PROC_HASH 1024 |
Typedefs | |
typedef void(* | opd_proc_cb )(struct opd_proc *) |
Functions | |
void | opd_init_procs (void) |
int | opd_get_nr_procs (void) |
static uint | proc_hash (pid_t tid) |
struct opd_proc * | opd_new_proc (pid_t tid, pid_t tgid) |
struct opd_proc * | opd_get_proc (pid_t tid, pid_t tgid) |
static void | verb_show_sample (unsigned long offset, struct opd_map *map) |
void | opd_put_image_sample (struct opd_image *image, unsigned long offset, u32 counter) |
static int | opd_lookup_maps (struct opd_proc *proc, struct op_sample const *sample) |
void | opd_put_sample (struct op_sample const *sample) |
void | opd_handle_fork (struct op_note const *note) |
void | opd_handle_exec (pid_t tid, pid_t tgid) |
void | opd_handle_exit (struct op_note const *note) |
static void | opd_for_each_proc (opd_proc_cb proc_cb) |
static void | opd_delete_proc (struct opd_proc *proc) |
void | opd_proc_cleanup (void) |
static void | opd_age_proc (struct opd_proc *proc) |
void | opd_age_procs (void) |
static void | opd_remove_kernel_mapping (struct opd_proc *proc) |
void | opd_clear_kernel_mapping (void) |
Variables | |
int | cpu_number |
static struct list_head | opd_procs [OPD_MAX_PROC_HASH] |
static int | nr_procs |
Management of processes
Definition in file opd_proc.c.
#define OPD_MAX_PROC_HASH 1024 |
Definition at line 31 of file opd_proc.c.
Referenced by opd_for_each_proc(), opd_init_procs(), and proc_hash().
typedef void(* opd_proc_cb)(struct opd_proc *) |
Definition at line 333 of file opd_proc.c.
static void opd_age_proc | ( | struct opd_proc * | proc | ) | [static] |
opd_age_proc - age a struct opd_proc
proc | proc to age |
age dead proc in such way if a proc doesn't receive any samples between two age_proc the opd_proc struct is deleted
Definition at line 388 of file opd_proc.c.
References opd_proc::accessed, opd_proc::dead, and opd_delete_proc().
Referenced by opd_age_procs().
void opd_age_procs | ( | void | ) |
opd_age_procs - age all dead process preparing them for a deletion
Definition at line 400 of file opd_proc.c.
References opd_age_proc(), and opd_for_each_proc().
Referenced by opd_alarm().
void opd_clear_kernel_mapping | ( | void | ) |
opd_clear_kernel_mapping - remove all kernel mapping for all opd_proc
invalidate (by removing them) all kernel mapping. This function do nothing when separate_kernel == 0 because we don't add mapping for kernel sample in proc struct. As side effect decrease reference count of associated with these mapping which eventually close this image
Definition at line 429 of file opd_proc.c.
References opd_for_each_proc(), and opd_remove_kernel_mapping().
Referenced by opd_clear_module_info().
static void opd_delete_proc | ( | struct opd_proc * | proc | ) | [static] |
opd_delete_proc - delete a process
proc | process to delete |
Remove the process proc from the process list and free the associated structures.
Definition at line 364 of file opd_proc.c.
References list_del(), opd_proc::name, opd_proc::next, nr_procs, and opd_kill_maps().
Referenced by opd_age_proc(), and opd_proc_cleanup().
static void opd_for_each_proc | ( | opd_proc_cb | proc_cb | ) | [static] |
proc_cb | callback to apply onto each existing proc struct |
the callback receive a struct opd_proc * (not a const struct) and is allowed to freeze the proc struct itself.
Definition at line 341 of file opd_proc.c.
References list_entry, list_for_each_safe, opd_proc::next, OPD_MAX_PROC_HASH, and opd_procs.
Referenced by opd_age_procs(), opd_clear_kernel_mapping(), and opd_proc_cleanup().
int opd_get_nr_procs | ( | void | ) |
opd_get_nr_procs - return number of processes tracked
Definition at line 50 of file opd_proc.c.
References nr_procs.
Referenced by opd_print_24_stats().
struct opd_proc* opd_get_proc | ( | pid_t | tid, | |
pid_t | tgid | |||
) | [read] |
opd_get_proc - get process from process list
tid | tid for this process | |
tgid | tgid for this process |
A process with pid tid is searched on the process list, maintaining LRU order. If it is not found, NULL is returned, otherwise the process structure is returned.
Definition at line 85 of file opd_proc.c.
References list_add(), list_del(), list_entry, list_for_each_safe, opd_proc::next, list_head::next, opd_24_stats, OPD_PROC_QUEUE_ACCESS, OPD_PROC_QUEUE_DEPTH, opd_procs, proc_hash(), opd_proc::tgid, and opd_proc::tid.
Referenced by opd_get_ascii_procs(), opd_handle_exec(), opd_handle_exit(), opd_handle_fork(), opd_handle_mapping(), and opd_put_sample().
void opd_handle_exec | ( | pid_t | tid, | |
pid_t | tgid | |||
) |
opd_handle_exec - deal with notification of execve()
tid | tid for this process | |
tgid | tgid for this process |
Drop all mapping information for the process.
Definition at line 286 of file opd_proc.c.
References opd_proc::name, opd_get_proc(), opd_kill_maps(), opd_new_proc(), verbprintf, and vmisc.
Referenced by opd_do_notes().
void opd_handle_exit | ( | struct op_note const * | note | ) |
opd_handle_exit - deal with exit notification
note | note to handle |
Deal with an exit() notification by setting the flag "dead" on a process. These will be later cleaned up by the SIGALRM handler.
sample->pid contains the process id of the exited process.
Definition at line 317 of file opd_proc.c.
References opd_proc::accessed, opd_proc::dead, opd_get_proc(), op_note::pid, op_note::tgid, verbprintf, and vmisc.
Referenced by opd_do_notes().
void opd_handle_fork | ( | struct op_note const * | note | ) |
opd_handle_fork - deal with fork notification
note | note to handle |
Deal with a fork() notification by creating a new process structure, and copying mapping information from the old process.
sample->pid contains the process id of the old process. sample->eip contains the process id of the new process.
Definition at line 238 of file opd_proc.c.
References op_note::addr, opd_map::end, opd_map::image, opd_image::kernel, op_note::len, list_entry, list_for_each, opd_proc::maps, opd_proc::name, opd_image::name, opd_map::next, opd_map::offset, opd_add_mapping(), opd_get_image(), opd_get_proc(), opd_new_proc(), op_note::pid, separate_thread, opd_map::start, op_note::tgid, verbprintf, and vmisc.
Referenced by opd_do_notes().
void opd_init_procs | ( | void | ) |
initialize opd_proc container
Definition at line 42 of file opd_proc.c.
References list_init(), OPD_MAX_PROC_HASH, and opd_procs.
Referenced by opd_24_init().
opd_lookup_maps - lookup a proc mappings for a sample
proc | proc to lookup | |
sample | sample to lookup |
iterate through the proc maps searching the mapping which owns sample if sucessful sample count will be updated and we return non-zero
Definition at line 164 of file opd_proc.c.
References opd_proc::accessed, op_sample::counter, op_sample::eip, opd_map::image, list_entry, list_for_each, opd_proc::maps, opd_map::next, opd_map::offset, opd_24_stats, opd_is_in_map(), OPD_MAP_ARRAY_ACCESS, OPD_MAP_ARRAY_DEPTH, opd_map_offset(), OPD_PROCESS, opd_put_image_sample(), and verb_show_sample().
Referenced by opd_put_sample().
struct opd_proc* opd_new_proc | ( | pid_t | tid, | |
pid_t | tgid | |||
) | [read] |
opd_new_proc - create a new process structure
tid | tid for this process | |
tgid | tgid for this process |
Allocate and initialise a process structure and insert it into the procs hash table.
Definition at line 68 of file opd_proc.c.
References opd_proc::accessed, opd_proc::dead, list_add(), list_init(), opd_proc::maps, opd_proc::name, opd_proc::next, nr_procs, opd_procs, proc_hash(), opd_proc::tgid, and opd_proc::tid.
Referenced by opd_get_ascii_procs(), opd_handle_exec(), opd_handle_fork(), and opd_handle_mapping().
void opd_proc_cleanup | ( | void | ) |
freeze all resource used by opd_procs managment
Definition at line 375 of file opd_proc.c.
References opd_delete_proc(), and opd_for_each_proc().
Referenced by opd_24_exit().
opd_put_image_sample - write sample to file
image | image for sample | |
offset | (file) offset to write to | |
counter | counter number |
Add to the count stored at position offset in the image file. Overflow pins the count at the maximum value.
Definition at line 122 of file opd_proc.c.
References cpu_number, opd_image::ignored, odb_open_count(), odb_update_node(), OP_MAX_COUNTERS, opd_24_sfile_lru(), opd_24_stats, OPD_LOST_SAMPLEFILE, opd_open_24_sample_file(), opd_24_sfile::sample_file, and opd_image::sfiles.
Referenced by opd_handle_kernel_sample(), opd_handle_module_sample(), and opd_lookup_maps().
void opd_put_sample | ( | struct op_sample const * | sample | ) |
opd_put_sample - process a sample
sample | sample to process |
Write out the sample to the appropriate sample file. This routine handles kernel and module samples as well as ordinary ones.
Definition at line 190 of file opd_proc.c.
References op_sample::counter, op_sample::eip, no_vmlinux, opd_24_stats, opd_add_kernel_map(), opd_eip_is_kernel(), opd_get_proc(), opd_handle_kernel_sample(), opd_lookup_maps(), OPD_LOST_MAP_PROCESS, OPD_LOST_PROCESS, OPD_SAMPLES, op_sample::pid, separate_kernel, op_sample::tgid, verbprintf, vmisc, and vsamples.
Referenced by opd_do_samples(), and opd_process_samples().
static void opd_remove_kernel_mapping | ( | struct opd_proc * | proc | ) | [static] |
opd_remove_kernel_mapping - remove all kernel mapping for an opd_proc
proc | proc where mappings must be updated. |
invalidate (by removing them) all kernel mapping. This function do nothing when separate_kernel == 0 because we don't add mapping for kernel sample in proc struct.
Definition at line 414 of file opd_proc.c.
References opd_map::image, list_del(), list_entry, list_for_each_safe, opd_proc::maps, opd_map::next, opd_map::offset, opd_delete_image(), opd_eip_is_kernel(), and opd_map::start.
Referenced by opd_clear_kernel_mapping().
static uint proc_hash | ( | pid_t | tid | ) | [inline, static] |
proc_hash - hash pid value
tid | pid value to hash |
Definition at line 61 of file opd_proc.c.
References OPD_MAX_PROC_HASH.
Referenced by opd_get_proc(), and opd_new_proc().
static void verb_show_sample | ( | unsigned long | offset, | |
struct opd_map * | map | |||
) | [inline, static] |
verb_show_sample - print the sample out to the log
offset | the offset value | |
map | map to print |
Definition at line 113 of file opd_proc.c.
References opd_map::end, opd_map::image, opd_image::name, opd_map::offset, opd_map::start, verbprintf, and vsamples.
Referenced by opd_lookup_maps().
int cpu_number |
Definition at line 41 of file init.c.
Referenced by opd_do_samples(), and opd_put_image_sample().
int nr_procs [static] |
Definition at line 39 of file opd_proc.c.
Referenced by opd_delete_proc(), opd_get_nr_procs(), and opd_new_proc().
Definition at line 36 of file opd_proc.c.
Referenced by opd_for_each_proc(), opd_get_proc(), opd_init_procs(), and opd_new_proc().