Linux Perf
util.c File Reference
#include "../perf.h"
#include "util.h"
#include "debug.h"
#include <api/fs/fs.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <dirent.h>
#include <fcntl.h>
#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <linux/kernel.h>
#include <linux/log2.h>
#include <linux/time64.h>
#include <unistd.h>
#include "strlist.h"
Include dependency graph for util.c:

Go to the source code of this file.

Functions

void perf_set_singlethreaded (void)
 
void perf_set_multithreaded (void)
 
static void cache_line_size (int *cacheline_sizep)
 
int cacheline_size (void)
 
int sysctl__max_stack (void)
 
void event_attr_init (struct perf_event_attr *attr)
 
int mkdir_p (char *path, mode_t mode)
 
int rm_rf (const char *path)
 
bool lsdir_no_dot_filter (const char *name __maybe_unused, struct dirent *d)
 
struct strlistlsdir (const char *name, bool(*filter)(const char *, struct dirent *))
 
static int slow_copyfile (const char *from, const char *to, struct nsinfo *nsi)
 
static int copyfile_offset (int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size)
 
static int copyfile_mode_ns (const char *from, const char *to, mode_t mode, struct nsinfo *nsi)
 
int copyfile_ns (const char *from, const char *to, struct nsinfo *nsi)
 
int copyfile_mode (const char *from, const char *to, mode_t mode)
 
int copyfile (const char *from, const char *to)
 
static ssize_t ion (bool is_read, int fd, void *buf, size_t n)
 
ssize_t readn (int fd, void *buf, size_t n)
 
ssize_t writen (int fd, const void *buf, size_t n)
 
size_t hex_width (u64 v)
 
int hex2u64 (const char *ptr, u64 *long_val)
 
int perf_event_paranoid (void)
 
static int fetch_ubuntu_kernel_version (unsigned int *puint)
 
int fetch_kernel_version (unsigned int *puint, char *str, size_t str_size)
 
const char * perf_tip (const char *dirpath)
 

Variables

bool perf_singlethreaded = true
 
unsigned int page_size
 
int sysctl_perf_event_max_stack = PERF_MAX_STACK_DEPTH
 
int sysctl_perf_event_max_contexts_per_stack = PERF_MAX_CONTEXTS_PER_STACK
 
bool test_attr__enabled
 
bool perf_host = true
 
bool perf_guest = false
 

Function Documentation

◆ cache_line_size()

static void cache_line_size ( int *  cacheline_sizep)
static

Definition at line 45 of file util.c.

◆ cacheline_size()

int cacheline_size ( void  )

Definition at line 52 of file util.c.

Here is the call graph for this function:

◆ copyfile()

int copyfile ( const char *  from,
const char *  to 
)

Definition at line 320 of file util.c.

Here is the call graph for this function:

◆ copyfile_mode()

int copyfile_mode ( const char *  from,
const char *  to,
mode_t  mode 
)

Definition at line 315 of file util.c.

Here is the call graph for this function:

◆ copyfile_mode_ns()

static int copyfile_mode_ns ( const char *  from,
const char *  to,
mode_t  mode,
struct nsinfo nsi 
)
static

Definition at line 252 of file util.c.

Here is the call graph for this function:

◆ copyfile_ns()

int copyfile_ns ( const char *  from,
const char *  to,
struct nsinfo nsi 
)

Definition at line 310 of file util.c.

Here is the call graph for this function:

◆ copyfile_offset()

static int copyfile_offset ( int  ifd,
loff_t  off_in,
int  ofd,
loff_t  off_out,
u64  size 
)
static

Definition at line 224 of file util.c.

◆ event_attr_init()

void event_attr_init ( struct perf_event_attr *  attr)

Definition at line 83 of file util.c.

◆ fetch_kernel_version()

int fetch_kernel_version ( unsigned int *  puint,
char *  str,
size_t  str_size 
)

Definition at line 447 of file util.c.

Here is the call graph for this function:

◆ fetch_ubuntu_kernel_version()

static int fetch_ubuntu_kernel_version ( unsigned int *  puint)
static

Definition at line 398 of file util.c.

Here is the call graph for this function:

◆ hex2u64()

int hex2u64 ( const char *  ptr,
u64 *  long_val 
)

Definition at line 379 of file util.c.

◆ hex_width()

size_t hex_width ( u64  v)

Definition at line 365 of file util.c.

◆ ion()

static ssize_t ion ( bool  is_read,
int  fd,
void *  buf,
size_t  n 
)
static

Definition at line 325 of file util.c.

◆ lsdir()

struct strlist* lsdir ( const char *  name,
bool(*)(const char *, struct dirent *)  filter 
)

Definition at line 166 of file util.c.

Here is the call graph for this function:

◆ lsdir_no_dot_filter()

bool lsdir_no_dot_filter ( const char *name  __maybe_unused,
struct dirent *  d 
)

Definition at line 160 of file util.c.

◆ mkdir_p()

int mkdir_p ( char *  path,
mode_t  mode 
)

Definition at line 93 of file util.c.

◆ perf_event_paranoid()

int perf_event_paranoid ( void  )

Definition at line 388 of file util.c.

◆ perf_set_multithreaded()

void perf_set_multithreaded ( void  )

Definition at line 35 of file util.c.

◆ perf_set_singlethreaded()

void perf_set_singlethreaded ( void  )

Definition at line 30 of file util.c.

◆ perf_tip()

const char* perf_tip ( const char *  dirpath)

Definition at line 482 of file util.c.

Here is the call graph for this function:

◆ readn()

ssize_t readn ( int  fd,
void *  buf,
size_t  n 
)

Definition at line 351 of file util.c.

Here is the call graph for this function:

◆ rm_rf()

int rm_rf ( const char *  path)

Definition at line 119 of file util.c.

Here is the call graph for this function:

◆ slow_copyfile()

static int slow_copyfile ( const char *  from,
const char *  to,
struct nsinfo nsi 
)
static

Definition at line 193 of file util.c.

Here is the call graph for this function:

◆ sysctl__max_stack()

int sysctl__max_stack ( void  )

Definition at line 65 of file util.c.

◆ writen()

ssize_t writen ( int  fd,
const void *  buf,
size_t  n 
)

Definition at line 359 of file util.c.

Here is the call graph for this function:

Variable Documentation

◆ page_size

unsigned int page_size

Definition at line 40 of file util.c.

◆ perf_guest

bool perf_guest = false

Definition at line 81 of file util.c.

◆ perf_host

bool perf_host = true

Definition at line 80 of file util.c.

◆ perf_singlethreaded

bool perf_singlethreaded = true

Definition at line 28 of file util.c.

◆ sysctl_perf_event_max_contexts_per_stack

int sysctl_perf_event_max_contexts_per_stack = PERF_MAX_CONTEXTS_PER_STACK

Definition at line 63 of file util.c.

◆ sysctl_perf_event_max_stack

int sysctl_perf_event_max_stack = PERF_MAX_STACK_DEPTH

Definition at line 62 of file util.c.

◆ test_attr__enabled

bool test_attr__enabled

Definition at line 78 of file util.c.