operf.cpp File Reference

#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"
Include dependency graph for operf.cpp:

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_tevents
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]

Detailed Description

Front-end (containing main) for handling a user request to run a profile using the new Linux Performance Events Subsystem.

Remarks:
Copyright 2011 OProfile authors
Read the file COPYING

Created on: Dec 7, 2011

Author:
Maynard Johnson (C) Copyright IBM Corp. 2011

Modified by Maynard Johnson <maynardj@us.ibm.com> (C) Copyright IBM Corporation 2012

Definition in file operf.cpp.


Define Documentation

#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 Documentation

typedef enum END_CODE end_code_t

Enumeration Type Documentation

enum END_CODE
Enumerator:
ALL_OK 
APP_ABNORMAL_END 
PERF_RECORD_ERROR 
PERF_READ_ERROR 
PERF_BOTH_ERROR 

Definition at line 52 of file operf.cpp.


Function Documentation

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().

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

static int _check_perf_events_cap ( void   )  [static]

Definition at line 1602 of file operf.cpp.

References pid.

Referenced by main().

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

static int _get_sys_value ( const char *  filename  )  [static]

Definition at line 1651 of file operf.cpp.

Referenced by main().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

static int _process_operf_and_app_args ( int  argc,
char *const   argv[] 
) [static]
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().

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

static end_code_t _run ( void   )  [static]
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().

Here is the call graph for this function:

Here is the caller graph for this function:

void _set_signals_for_record ( void   ) 

Definition at line 168 of file operf.cpp.

References _handle_sigint().

Referenced by start_profiling().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the caller graph for this function:

static void convert_sample_data ( void   )  [static]
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().

Here is the caller graph for this function:

static void get_default_event ( void   )  [static]
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().

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *const   argv[] 
)
static void op_sig_stop ( int val   __attribute__(unused)  )  [static]

Definition at line 146 of file operf.cpp.

References app_PID, ctl_c, cverb, startApp, and vdebug.

Referenced by set_signals().

Here is the caller graph for this function:

static void process_args ( int  argc,
char *const   argv[] 
) [static]
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().

Here is the call graph for this function:

Here is the caller graph for this function:

void set_signals ( void   ) 

Definition at line 186 of file operf.cpp.

References op_sig_stop().

Referenced by _run().

Here is the call graph for this function:

Here is the caller graph for this function:

int start_profiling ( void   ) 
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().

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

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
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
int app_ready_pipe[2] [static]

Definition at line 205 of file operf.cpp.

bool app_started [static]

Definition at line 82 of file operf.cpp.

Referenced by _run(), convert_sample_data(), main(), run_app(), and start_profiling().

double cpu_speed

Definition at line 66 of file operf.cpp.

Definition at line 65 of file operf.cpp.

bool ctl_c = false [static]
vector<operf_event_t> events [static]
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().

Definition at line 72 of file operf.cpp.

Referenced by __handle_mmap_event(), and main().

struct option long_options[]
Initial value:
{
 {"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

Definition at line 71 of file operf.cpp.

Definition at line 68 of file operf.cpp.

char op_samples_current_dir[PATH_MAX]

Definition at line 67 of file operf.cpp.

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]

Definition at line 205 of file operf.cpp.

Definition at line 64 of file operf.cpp.

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]
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 205 of file operf.cpp.

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().

verbose vmisc("misc")

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1