HPCToolkit
linux_perf.c File Reference
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#include <sys/syscall.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <linux/perf_event.h>
#include <linux/version.h>
#include <monitor.h>
#include "sample-sources/simple_oo.h"
#include "sample-sources/sample_source_obj.h"
#include "sample-sources/common.h"
#include "sample-sources/ss-errno.h"
#include <hpcrun/cct_insert_backtrace.h>
#include <hpcrun/files.h>
#include <hpcrun/hpcrun_stats.h>
#include <hpcrun/loadmap.h>
#include <hpcrun/messages/messages.h>
#include <hpcrun/metrics.h>
#include <hpcrun/safe-sampling.h>
#include <hpcrun/sample_event.h>
#include <hpcrun/sample_sources_registered.h>
#include <hpcrun/sample-sources/blame-shift/blame-shift.h>
#include <hpcrun/utilities/tokenize.h>
#include <hpcrun/utilities/arch/context-pc.h>
#include <evlist.h>
#include <limits.h>
#include <lib/prof-lean/hpcrun-metric.h>
#include <lib/support-lean/OSUtil.h>
#include <include/linux_info.h>
#include "perfmon-util.h"
#include "perf-util.h"
#include "perf_mmap.h"
#include "perf_skid.h"
#include "perf_event_open.h"
#include "event_custom.h"
#include "sample-sources/display.h"
#include "kernel_blocking.h"
#include "sample-sources/datacentric/datacentric.h"
#include "sample-sources/datacentric/memaddress.h"
#include "lib/support-lean/compress.h"
#include "sample-sources/ss_obj.h"

Go to the source code of this file.

Macros

#define LINUX_PERF_DEBUG   0
 
#define DEFAULT_THRESHOLD   HPCRUN_DEFAULT_SAMPLE_RATE
 
#define sigev_notify_thread_id   _sigev_un._tid
 
#define PERF_SIGNAL   (SIGRTMIN+4)
 
#define PERF_EVENT_AVAILABLE_UNKNOWN   0
 
#define PERF_EVENT_AVAILABLE_NO   1
 
#define PERF_EVENT_AVAILABLE_YES   2
 
#define PERF_MULTIPLEX_RANGE   1.2
 
#define FILE_BUFFER_SIZE   (1024*1024)
 
#define DEFAULT_COMPRESSION   5
 
#define PERIOD_THRESHOLD   1
 
#define PERIOD_FREQUENCY   2
 
#define PERIOD_DEFAULT   0
 
#define PERF_FD_FINALIZED   (-2)
 
#define ss_name   linux_perf
 
#define ss_cls   SS_HARDWARE
 
#define ss_sort_order   60
 

Functions

static void perf_thread_fini (int nevents, event_thread_t *event_thread)
 
static int perf_event_handler (int sig, siginfo_t *siginfo, void *context)
 
static int perf_was_finalized (int nevents, event_thread_t *event_thread)
 
static void perf_start_all (int nevents, event_thread_t *event_thread)
 
static void perf_stop_all (int nevents, event_thread_t *event_thread)
 
static int perf_get_pmu_support (const char *name, struct perf_event_attr *event_attr)
 
static int copy_kallsyms ()
 
static void perf_init ()
 
static bool perf_thread_init (event_info_t *event, event_thread_t *et)
 
static int get_fd_index (int nevents, int fd, event_thread_t *event_thread)
 
static double record_sample (event_thread_t *current, perf_mmap_data_t *mmap_data, void *context, int metric, int freq, sample_val_t *sv)
 
static size_t exist_precise_ip_modifier (const char *original_event)
 
static void METHOD_FN (init)
 
static void METHOD_FN (thread_init)
 
static void METHOD_FN (thread_init_action)
 
static void METHOD_FN (start)
 
static void METHOD_FN (thread_fini_action)
 
static void METHOD_FN (stop)
 
static void METHOD_FN (shutdown)
 
static bool METHOD_FN (supports_event, const char *ev_str)
 
static void METHOD_FN (process_event_list, int lush_metrics)
 
static void METHOD_FN (gen_event_set, int lush_metrics)
 
static void METHOD_FN (display_events)
 
long read_fd (int fd)
 

Variables

static const struct timespec nowait = {0, 0}
 
__thread bool hpcrun_thread_suppress_sample
 

Macro Definition Documentation

◆ DEFAULT_COMPRESSION

#define DEFAULT_COMPRESSION   5

Definition at line 166 of file linux_perf.c.

◆ DEFAULT_THRESHOLD

#define DEFAULT_THRESHOLD   HPCRUN_DEFAULT_SAMPLE_RATE

Definition at line 145 of file linux_perf.c.

◆ FILE_BUFFER_SIZE

#define FILE_BUFFER_SIZE   (1024*1024)

Definition at line 164 of file linux_perf.c.

◆ LINUX_PERF_DEBUG

#define LINUX_PERF_DEBUG   0

Definition at line 135 of file linux_perf.c.

◆ PERF_EVENT_AVAILABLE_NO

#define PERF_EVENT_AVAILABLE_NO   1

Definition at line 159 of file linux_perf.c.

◆ PERF_EVENT_AVAILABLE_UNKNOWN

#define PERF_EVENT_AVAILABLE_UNKNOWN   0

Definition at line 158 of file linux_perf.c.

◆ PERF_EVENT_AVAILABLE_YES

#define PERF_EVENT_AVAILABLE_YES   2

Definition at line 160 of file linux_perf.c.

◆ PERF_FD_FINALIZED

#define PERF_FD_FINALIZED   (-2)

Definition at line 172 of file linux_perf.c.

◆ PERF_MULTIPLEX_RANGE

#define PERF_MULTIPLEX_RANGE   1.2

Definition at line 162 of file linux_perf.c.

◆ PERF_SIGNAL

#define PERF_SIGNAL   (SIGRTMIN+4)

Definition at line 156 of file linux_perf.c.

◆ PERIOD_DEFAULT

#define PERIOD_DEFAULT   0

Definition at line 170 of file linux_perf.c.

◆ PERIOD_FREQUENCY

#define PERIOD_FREQUENCY   2

Definition at line 169 of file linux_perf.c.

◆ PERIOD_THRESHOLD

#define PERIOD_THRESHOLD   1

Definition at line 168 of file linux_perf.c.

◆ sigev_notify_thread_id

#define sigev_notify_thread_id   _sigev_un._tid

Definition at line 148 of file linux_perf.c.

◆ ss_cls

#define ss_cls   SS_HARDWARE

Definition at line 1005 of file linux_perf.c.

◆ ss_name

#define ss_name   linux_perf

Definition at line 1004 of file linux_perf.c.

◆ ss_sort_order

#define ss_sort_order   60

Definition at line 1006 of file linux_perf.c.

Function Documentation

◆ copy_kallsyms()

static int copy_kallsyms ( )
static

Definition at line 287 of file linux_perf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exist_precise_ip_modifier()

static size_t exist_precise_ip_modifier ( const char *  original_event)
static

return the position of precise_ip modifier if exist if not exist, returns 0

Definition at line 587 of file linux_perf.c.

Here is the caller graph for this function:

◆ get_fd_index()

static int get_fd_index ( int  nevents,
int  fd,
event_thread_t event_thread 
)
static

Definition at line 483 of file linux_perf.c.

Here is the caller graph for this function:

◆ METHOD_FN() [1/11]

static void METHOD_FN ( init  )
static

Definition at line 612 of file linux_perf.c.

Here is the call graph for this function:

◆ METHOD_FN() [2/11]

static void METHOD_FN ( thread_init  )
static

Definition at line 639 of file linux_perf.c.

◆ METHOD_FN() [3/11]

static void METHOD_FN ( thread_init_action  )
static

Definition at line 651 of file linux_perf.c.

◆ METHOD_FN() [4/11]

static void METHOD_FN ( start  )
static

Definition at line 663 of file linux_perf.c.

Here is the call graph for this function:

◆ METHOD_FN() [5/11]

static void METHOD_FN ( thread_fini_action  )
static

Definition at line 695 of file linux_perf.c.

Here is the call graph for this function:

◆ METHOD_FN() [6/11]

static void METHOD_FN ( stop  )
static

Definition at line 716 of file linux_perf.c.

Here is the call graph for this function:

◆ METHOD_FN() [7/11]

static void METHOD_FN ( shutdown  )
static

Definition at line 748 of file linux_perf.c.

Here is the call graph for this function:

◆ METHOD_FN() [8/11]

static bool METHOD_FN ( supports_event  ,
const char *  ev_str 
)
static

Definition at line 770 of file linux_perf.c.

Here is the call graph for this function:

◆ METHOD_FN() [9/11]

static void METHOD_FN ( process_event_list  ,
int  lush_metrics 
)
static

Definition at line 809 of file linux_perf.c.

Here is the call graph for this function:

◆ METHOD_FN() [10/11]

static void METHOD_FN ( gen_event_set  ,
int  lush_metrics 
)
static

Definition at line 920 of file linux_perf.c.

Here is the call graph for this function:

◆ METHOD_FN() [11/11]

static void METHOD_FN ( display_events  )
static

Definition at line 968 of file linux_perf.c.

Here is the call graph for this function:

◆ perf_event_handler()

static int perf_event_handler ( int  sig,
siginfo_t *  siginfo,
void *  context 
)
static

Definition at line 1015 of file linux_perf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ perf_get_pmu_support()

static int perf_get_pmu_support ( const char *  name,
struct perf_event_attr *  event_attr 
)
static

Definition at line 274 of file linux_perf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ perf_init()

static void perf_init ( )
static

Definition at line 338 of file linux_perf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ perf_start_all()

static void perf_start_all ( int  nevents,
event_thread_t event_thread 
)
static

Definition at line 236 of file linux_perf.c.

Here is the caller graph for this function:

◆ perf_stop_all()

static void perf_stop_all ( int  nevents,
event_thread_t event_thread 
)
static

Definition at line 257 of file linux_perf.c.

Here is the caller graph for this function:

◆ perf_thread_fini()

static void perf_thread_fini ( int  nevents,
event_thread_t event_thread 
)
static

Definition at line 443 of file linux_perf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ perf_thread_init()

static bool perf_thread_init ( event_info_t event,
event_thread_t et 
)
static

Definition at line 377 of file linux_perf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ perf_was_finalized()

static int perf_was_finalized ( int  nevents,
event_thread_t event_thread 
)
static

Definition at line 223 of file linux_perf.c.

Here is the caller graph for this function:

◆ read_fd()

long read_fd ( int  fd)

Definition at line 985 of file linux_perf.c.

Here is the call graph for this function:

◆ record_sample()

static double record_sample ( event_thread_t current,
perf_mmap_data_t mmap_data,
void *  context,
int  metric,
int  freq,
sample_val_t sv 
)
static

Definition at line 500 of file linux_perf.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ hpcrun_thread_suppress_sample

__thread bool hpcrun_thread_suppress_sample

Definition at line 193 of file main.c.

◆ nowait

const struct timespec nowait = {0, 0}
static

Definition at line 196 of file linux_perf.c.