#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <dirent.h>
#include <exception>
#include <pwd.h>
#include <errno.h>
#include <sys/time.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <ftw.h>
#include <iostream>
#include "operf_utils.h"
#include "op_libiberty.h"
#include "string_manip.h"
#include "cverb.h"
#include "operf_counter.h"
#include "op_cpu_type.h"
#include "op_cpufreq.h"
#include "op_events.h"
#include "op_string.h"
#include "operf_kernel.h"
#include "child_reader.h"
#include "op_get_time.h"
Go to the source code of this file.
Namespaces | |
namespace | operf_options |
Defines | |
#define | DEFAULT_OPERF_OUTFILE "operf.data" |
#define | CALLGRAPH_MIN_COUNT_SCALE 15 |
#define | NUM_VERBOSE_OPTIONS (sizeof(valid_verbose_vals)/sizeof(char *)) |
#define | _OP_UM 1 |
#define | _OP_KERNEL 2 |
#define | _OP_USER 3 |
Typedefs | |
typedef enum END_CODE | end_code_t |
Enumerations | |
enum | END_CODE { ALL_OK = 0, APP_ABNORMAL_END = 1, PERF_RECORD_ERROR = 2, PERF_READ_ERROR = 4, PERF_BOTH_ERROR = 8 } |
Functions | |
static void | convert_sample_data (void) |
static void | __print_usage_and_exit (const char *extra_msg) |
static void | op_sig_stop (int val __attribute__((unused))) |
static void | _handle_sigint (int val __attribute__((unused))) |
void | _set_signals_for_record (void) |
void | set_signals (void) |
void | run_app (void) |
int | start_profiling (void) |
static end_code_t | _kill_operf_read_pid (end_code_t rc) |
static end_code_t | _kill_operf_record_pid (void) |
static end_code_t | _run (void) |
static void | cleanup (void) |
static void | _jitconv_complete (int val __attribute__((unused))) |
static void | _set_signals_for_convert (void) |
static void | _do_jitdump_convert () |
static int | __delete_old_previous_sample_data (const char *fpath, const struct stat *sb __attribute__((unused)), int tflag __attribute__((unused)), struct FTW *ftwbuf __attribute__((unused))) |
static int | find_app_file_in_dir (const struct dirent *d) |
static int | get_PATH_based_pathname (char *path_holder, size_t n) |
int | validate_app_name (void) |
static void | _get_event_code (operf_event_t *event) |
static void | _process_events_list (void) |
static void | get_default_event (void) |
static void | _process_session_dir (void) |
bool | _get_vmlinux_address_info (vector< string > args, string cmp_val, string &str) |
string | _process_vmlinux (string vmlinux_file) |
static void | _print_valid_verbose_options (void) |
static bool | _validate_verbose_args (char *verbosity) |
static int | _process_operf_and_app_args (int argc, char *const argv[]) |
static void | process_args (int argc, char *const argv[]) |
static int | _check_perf_events_cap (void) |
static void | _precheck_permissions_to_samplesdir (string sampledir, bool for_current) |
static int | _get_sys_value (const char *filename) |
int | main (int argc, char *const argv[]) |
Variables | |
char * | app_name = NULL |
pid_t | app_PID = -1 |
uint64_t | kernel_start |
uint64_t | kernel_end |
operf_read | operfRead |
op_cpu | cpu_type |
double | cpu_speed |
char | op_samples_current_dir [PATH_MAX] |
uint | op_nr_counters |
verbose | vmisc ("misc") |
all others not fitting in above category, not voluminous. | |
uid_t | my_uid |
bool | no_vmlinux |
int | kptr_restrict |
char * | start_time_human_readable |
static char | full_pathname [PATH_MAX] |
static char * | app_name_SAVE = NULL |
static char * | app_args = NULL |
static pid_t | jitconv_pid = -1 |
static bool | app_started |
static pid_t | operf_record_pid |
static pid_t | operf_read_pid |
static string | samples_dir |
static bool | startApp |
static string | outputfile |
static char | start_time_str [32] |
static vector< operf_event_t > | events |
static bool | jit_conversion_running |
static int | sample_data_pipe [2] |
static bool | ctl_c = false |
bool | operf_options::append |
bool | operf_options::callgraph |
string | operf_options::vmlinux |
bool | operf_options::post_conversion |
vector< string > | operf_options::evts |
static const char * | valid_verbose_vals [] = { "debug", "record", "convert", "misc", "sfile", "arcs", "all"} |
struct option | long_options [] |
const char * | short_options = "V:d:k:gsap:e:ctlhuv" |
vector< string > | verbose_string |
static int | app_ready_pipe [2] |
static int | start_app_pipe [2] |
static int | operf_record_ready_pipe [2] |
Front-end (containing main) for handling a user request to run a profile using the new Linux Performance Events Subsystem.
Created on: Dec 7, 2011
Modified by Maynard Johnson <maynardj@us.ibm.com> (C) Copyright IBM Corporation 2012
Definition in file operf.cpp.
#define _OP_KERNEL 2 |
Referenced by _process_events_list().
#define _OP_UM 1 |
Referenced by _process_events_list().
#define _OP_USER 3 |
Referenced by _process_events_list().
#define CALLGRAPH_MIN_COUNT_SCALE 15 |
Definition at line 76 of file operf.cpp.
Referenced by get_default_event().
#define DEFAULT_OPERF_OUTFILE "operf.data" |
Definition at line 75 of file operf.cpp.
Referenced by process_args().
#define NUM_VERBOSE_OPTIONS (sizeof(valid_verbose_vals)/sizeof(char *)) |
Definition at line 111 of file operf.cpp.
Referenced by _print_valid_verbose_options(), and _validate_verbose_args().
typedef enum END_CODE end_code_t |
enum END_CODE |
static int __delete_old_previous_sample_data | ( | const char * | fpath, | |
const struct stat *sb | __attribute__(unused), | |||
int tflag | __attribute__(unused), | |||
struct FTW *ftwbuf | __attribute__(unused) | |||
) | [static] |
Definition at line 840 of file operf.cpp.
Referenced by convert_sample_data().
static void __print_usage_and_exit | ( | const char * | extra_msg | ) | [static] |
Definition at line 136 of file operf.cpp.
Referenced by _process_operf_and_app_args(), process_args(), and run_app().
static int _check_perf_events_cap | ( | void | ) | [static] |
static void _do_jitdump_convert | ( | ) | [static] |
Definition at line 792 of file operf.cpp.
References cverb, delete_jitdumps, jit_conversion_running, jitconv_pid, my_uid, OP_BINDIR, operf_options::session_dir, start_time_str, and vdebug.
Referenced by convert_sample_data().
static void _get_event_code | ( | operf_event_t * | event | ) | [static] |
Definition at line 1045 of file operf.cpp.
References buf, operf_event::count, OP_BINDIR, and operf_event::um_name.
Referenced by _process_events_list(), and get_default_event().
static int _get_sys_value | ( | const char * | filename | ) | [static] |
bool _get_vmlinux_address_info | ( | vector< string > | args, | |
string | cmp_val, | |||
string & | str | |||
) |
Definition at line 1310 of file operf.cpp.
References child_reader::error(), child_reader::error_str(), child_reader::get_data(), child_reader::getline(), and child_reader::terminate_process().
Referenced by _process_vmlinux().
static void _handle_sigint | ( | int val | __attribute__(unused) | ) | [static] |
Definition at line 158 of file operf.cpp.
References ctl_c, cverb, and vdebug.
Referenced by _set_signals_for_convert(), and _set_signals_for_record().
static void _jitconv_complete | ( | int val | __attribute__(unused) | ) | [static] |
Definition at line 747 of file operf.cpp.
References cverb, jit_conversion_running, jitconv_pid, and vdebug.
Referenced by _set_signals_for_convert().
static end_code_t _kill_operf_read_pid | ( | end_code_t | rc | ) | [static] |
Definition at line 443 of file operf.cpp.
References ctl_c, cverb, operf_read_pid, PERF_BOTH_ERROR, PERF_READ_ERROR, PERF_RECORD_ERROR, and vdebug.
Referenced by _run().
static end_code_t _kill_operf_record_pid | ( | void | ) | [static] |
Definition at line 523 of file operf.cpp.
References ALL_OK, ctl_c, cverb, operf_record_pid, PERF_RECORD_ERROR, and vdebug.
Referenced by _run().
static void _precheck_permissions_to_samplesdir | ( | string | sampledir, | |
bool | for_current | |||
) | [static] |
Definition at line 1621 of file operf.cpp.
References operf_options::append, and cleanup().
Referenced by main().
static void _print_valid_verbose_options | ( | void | ) | [static] |
Definition at line 1416 of file operf.cpp.
References NUM_VERBOSE_OPTIONS, and valid_verbose_vals.
Referenced by _validate_verbose_args().
static void _process_events_list | ( | void | ) | [static] |
Definition at line 1127 of file operf.cpp.
References _get_event_code(), _OP_KERNEL, _OP_UM, _OP_USER, operf_options::callgraph, events, operf_options::evts, OP_BINDIR, OP_perf_utils::op_convert_event_vals(), OP_MAX_EVT_NAME_LEN, OP_MAX_UM_NAME_LEN, and op_xstrndup().
Referenced by process_args().
static int _process_operf_and_app_args | ( | int | argc, | |
char *const | argv[] | |||
) | [static] |
Definition at line 1446 of file operf.cpp.
References __print_usage_and_exit(), _validate_verbose_args(), operf_options::append, operf_options::callgraph, operf_options::evts, long_options, PACKAGE, operf_options::pid, operf_options::post_conversion, operf_options::separate_cpu, operf_options::separate_thread, operf_options::session_dir, short_options, operf_options::system_wide, VERSION, and operf_options::vmlinux.
Referenced by process_args().
static void _process_session_dir | ( | void | ) | [static] |
Definition at line 1263 of file operf.cpp.
References cverb, samples_dir, operf_options::session_dir, and vdebug.
Referenced by process_args().
string _process_vmlinux | ( | string | vmlinux_file | ) |
Definition at line 1355 of file operf.cpp.
References _get_vmlinux_address_info(), cverb, kernel_end, kernel_start, no_vmlinux, and vmisc.
Referenced by process_args().
static end_code_t _run | ( | void | ) | [static] |
Definition at line 561 of file operf.cpp.
References _kill_operf_read_pid(), _kill_operf_record_pid(), ALL_OK, APP_ABNORMAL_END, app_PID, app_started, convert_sample_data(), cverb, operf_read_pid, operf_record_pid, PERF_RECORD_ERROR, operf_options::post_conversion, sample_data_pipe, set_signals(), start_profiling(), startApp, operf_options::system_wide, and vdebug.
Referenced by main().
static void _set_signals_for_convert | ( | void | ) | [static] |
Definition at line 766 of file operf.cpp.
References _handle_sigint(), and _jitconv_complete().
Referenced by convert_sample_data().
void _set_signals_for_record | ( | void | ) |
Definition at line 168 of file operf.cpp.
References _handle_sigint().
Referenced by start_profiling().
static bool _validate_verbose_args | ( | char * | verbosity | ) | [static] |
Definition at line 1424 of file operf.cpp.
References _print_valid_verbose_options(), NUM_VERBOSE_OPTIONS, valid_verbose_vals, and verbose_string.
Referenced by _process_operf_and_app_args().
static void cleanup | ( | void | ) | [static] |
Definition at line 734 of file operf.cpp.
References app_args, app_name_SAVE, events, outputfile, operf_options::post_conversion, and verbose_string.
Referenced by _precheck_permissions_to_samplesdir(), cb_compiled_method_load(), and main().
static void convert_sample_data | ( | void | ) | [static] |
Definition at line 857 of file operf.cpp.
References __delete_old_previous_sample_data(), _do_jitdump_convert(), _set_signals_for_convert(), app_started, operf_options::append, operf_read::convertPerfData(), cverb, events, operf_read::init(), operf_read::is_valid(), jit_conversion_running, jitconv_pid, OP_PERF_HANDLED_ERROR, op_samples_current_dir, outputfile, operf_options::post_conversion, operf_read::readPerfHeader(), sample_data_pipe, samples_dir, operf_options::system_wide, and vdebug.
Referenced by _run(), and main().
static int find_app_file_in_dir | ( | const struct dirent * | d | ) | [static] |
Definition at line 940 of file operf.cpp.
References app_name.
Referenced by get_PATH_based_pathname().
static void get_default_event | ( | void | ) | [static] |
Definition at line 1216 of file operf.cpp.
References _get_event_code(), operf_options::callgraph, CALLGRAPH_MIN_COUNT_SCALE, op_default_event_descr::count, operf_event::count, events, operf_event::evt_um, find_event_by_name(), op_event::min_count, operf_event::name, op_default_event_descr::name, OP_perf_utils::op_convert_event_vals(), op_default_event(), op_events(), OP_MAX_EVT_NAME_LEN, and op_default_event_descr::um.
Referenced by process_args().
static int get_PATH_based_pathname | ( | char * | path_holder, | |
size_t | n | |||
) | [static] |
Definition at line 948 of file operf.cpp.
References app_name, and find_app_file_in_dir().
Referenced by validate_app_name().
int main | ( | int | argc, | |
char *const | argv[] | |||
) |
Definition at line 1665 of file operf.cpp.
References _check_perf_events_cap(), _get_sys_value(), _precheck_permissions_to_samplesdir(), _run(), APP_ABNORMAL_END, app_PID, app_started, operf_options::append, cleanup(), convert_sample_data(), CPU_NO_GOOD, cpu_speed, cverb, kptr_restrict, my_uid, op_cpu_frequency(), op_get_cpu_type(), PERF_BOTH_ERROR, PERF_READ_ERROR, PERF_RECORD_ERROR, operf_options::post_conversion, process_args(), samples_dir, startApp, operf_options::system_wide, throttled, and vdebug.
static void op_sig_stop | ( | int val | __attribute__(unused) | ) | [static] |
static void process_args | ( | int | argc, | |
char *const | argv[] | |||
) | [static] |
Definition at line 1526 of file operf.cpp.
References __print_usage_and_exit(), _process_events_list(), _process_operf_and_app_args(), _process_session_dir(), _process_vmlinux(), app_args, app_name, app_PID, DEFAULT_OPERF_OUTFILE, events, operf_options::evts, get_default_event(), no_vmlinux, op_nr_counters, operf_create_vmlinux(), outputfile, operf_options::pid, operf_options::post_conversion, samples_dir, verbose::setup(), operf_options::system_wide, validate_app_name(), verbose_string, and operf_options::vmlinux.
Referenced by main().
void run_app | ( | void | ) |
Definition at line 207 of file operf.cpp.
References __print_usage_and_exit(), app_args, app_name, app_started, cverb, and vdebug.
Referenced by start_profiling().
void set_signals | ( | void | ) |
Definition at line 186 of file operf.cpp.
References op_sig_stop().
Referenced by _run().
int start_profiling | ( | void | ) |
Definition at line 273 of file operf.cpp.
References _set_signals_for_record(), app_PID, app_started, operf_options::callgraph, ctl_c, cverb, OP_perf_utils::vmlinux_info::end, events, operf_record::get_total_bytes_recorded(), operf_record::get_valid(), OP_perf_utils::vmlinux_info::image_name, kernel_end, kernel_start, op_get_time(), operf_record_pid, outputfile, operf_options::pid, operf_options::post_conversion, operf_record::recordPerfData(), run_app(), sample_data_pipe, operf_options::separate_cpu, OP_perf_utils::vmlinux_info::start, start_time_human_readable, start_time_str, startApp, operf_options::system_wide, vdebug, vmisc, and operf_options::vmlinux.
Referenced by _run().
int validate_app_name | ( | void | ) |
Definition at line 985 of file operf.cpp.
References app_name, app_name_SAVE, full_pathname, get_PATH_based_pathname(), and OP_APPNAME_LEN.
Referenced by process_args().
char* app_args = NULL [static] |
Definition at line 80 of file operf.cpp.
Referenced by cleanup(), process_args(), and run_app().
char* app_name = NULL |
Definition at line 61 of file operf.cpp.
Referenced by __handle_comm_event(), __handle_fork_event(), __handle_mmap_event(), __map_hypervisor_sample(), find_app_file_in_dir(), get_PATH_based_pathname(), opd_add_kernel_map(), process_args(), run_app(), and validate_app_name().
char* app_name_SAVE = NULL [static] |
Definition at line 79 of file operf.cpp.
Referenced by cleanup(), and validate_app_name().
pid_t app_PID = -1 |
Definition at line 62 of file operf.cpp.
Referenced by __handle_comm_event(), __handle_mmap_event(), __map_hypervisor_sample(), _run(), main(), op_sig_stop(), process_args(), and start_profiling().
int app_ready_pipe[2] [static] |
bool app_started [static] |
Definition at line 82 of file operf.cpp.
Referenced by _run(), convert_sample_data(), main(), run_app(), and start_profiling().
bool ctl_c = false [static] |
Definition at line 93 of file operf.cpp.
Referenced by _handle_sigint(), _kill_operf_read_pid(), _kill_operf_record_pid(), op_sig_stop(), and start_profiling().
vector<operf_event_t> events [static] |
Definition at line 89 of file operf.cpp.
Referenced by _process_events_list(), cleanup(), convert_sample_data(), get_default_event(), process_args(), and start_profiling().
char full_pathname[PATH_MAX] [static] |
Definition at line 78 of file operf.cpp.
Referenced by validate_app_name().
bool jit_conversion_running [static] |
Definition at line 90 of file operf.cpp.
Referenced by _do_jitdump_convert(), _jitconv_complete(), and convert_sample_data().
pid_t jitconv_pid = -1 [static] |
Definition at line 81 of file operf.cpp.
Referenced by _do_jitdump_convert(), _jitconv_complete(), and convert_sample_data().
uint64_t kernel_end |
Definition at line 63 of file operf.cpp.
Referenced by _process_vmlinux(), and start_profiling().
uint64_t kernel_start |
Definition at line 63 of file operf.cpp.
Referenced by _process_vmlinux(), and start_profiling().
int kptr_restrict |
Definition at line 72 of file operf.cpp.
Referenced by __handle_mmap_event(), and main().
struct option long_options[] |
{ {"verbose", required_argument, NULL, 'V'}, {"session-dir", required_argument, NULL, 'd'}, {"vmlinux", required_argument, NULL, 'k'}, {"callgraph", no_argument, NULL, 'g'}, {"system-wide", no_argument, NULL, 's'}, {"append", no_argument, NULL, 'a'}, {"pid", required_argument, NULL, 'p'}, {"events", required_argument, NULL, 'e'}, {"separate-cpu", no_argument, NULL, 'c'}, {"separate-thread", no_argument, NULL, 't'}, {"lazy-conversion", no_argument, NULL, 'l'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {"usage", no_argument, NULL, 'u'}, {NULL, 9, NULL, 0} }
Definition at line 113 of file operf.cpp.
Referenced by _process_operf_and_app_args().
uid_t my_uid |
Definition at line 70 of file operf.cpp.
Referenced by __handle_mmap_event(), _do_jitdump_convert(), and main().
bool no_vmlinux |
uint op_nr_counters |
char op_samples_current_dir[PATH_MAX] |
pid_t operf_read_pid [static] |
Definition at line 84 of file operf.cpp.
Referenced by _kill_operf_read_pid(), and _run().
pid_t operf_record_pid [static] |
Definition at line 83 of file operf.cpp.
Referenced by _kill_operf_record_pid(), _run(), and start_profiling().
int operf_record_ready_pipe[2] [static] |
string outputfile [static] |
Definition at line 87 of file operf.cpp.
Referenced by cleanup(), convert_sample_data(), process_args(), and start_profiling().
int sample_data_pipe[2] [static] |
Definition at line 92 of file operf.cpp.
Referenced by _run(), convert_sample_data(), and start_profiling().
string samples_dir [static] |
Definition at line 85 of file operf.cpp.
Referenced by _process_session_dir(), convert_sample_data(), main(), op_process_jit_dumpfiles(), and process_args().
const char* short_options = "V:d:k:gsap:e:ctlhuv" |
Definition at line 132 of file operf.cpp.
Referenced by _process_operf_and_app_args().
int start_app_pipe[2] [static] |
Definition at line 73 of file operf.cpp.
Referenced by operf_read::convertPerfData(), and start_profiling().
char start_time_str[32] [static] |
Definition at line 88 of file operf.cpp.
Referenced by _do_jitdump_convert(), and start_profiling().
bool startApp [static] |
Definition at line 86 of file operf.cpp.
Referenced by _run(), main(), op_sig_stop(), and start_profiling().
const char* valid_verbose_vals[] = { "debug", "record", "convert", "misc", "sfile", "arcs", "all"} [static] |
Definition at line 110 of file operf.cpp.
Referenced by _print_valid_verbose_options(), and _validate_verbose_args().
vector<string> verbose_string |
Definition at line 134 of file operf.cpp.
Referenced by _validate_verbose_args(), cleanup(), and process_args().
all others not fitting in above category, not voluminous.
Definition at line 61 of file oprofiled.c.
Referenced by _process_vmlinux(), add_anon_mapping(), add_image_filter(), clear_anon_maps(), code_cookie_switch(), code_cpu_switch(), code_ctx_switch(), code_kernel_enter(), code_spu_ctx_switch(), code_user_enter(), code_xen_enter(), enough_remaining(), find_anon_mapping(), opd_add_kernel_map(), opd_add_mapping(), opd_create_vmlinux(), opd_create_xen(), opd_delete_image(), opd_do_jitdumps(), opd_do_read(), opd_do_samples(), opd_get_ascii_maps(), opd_get_ascii_procs(), opd_handle_exec(), opd_handle_exit(), opd_handle_fork(), opd_handle_mapping(), opd_handle_verbose_option(), opd_new_image(), opd_parse_events(), opd_parse_kernel_range(), opd_process_samples(), opd_put_sample(), opd_shutdown(), opd_sigchild(), operf_process_info::process_deferred_forked_processes(), operf_process_info::process_hypervisor_mapping(), operf_process_info::process_new_mapping(), process_spu_samples(), and start_profiling().