2009-04-20 20:00:56 +07:00
|
|
|
#ifndef GIT_COMPAT_UTIL_H
|
|
|
|
#define GIT_COMPAT_UTIL_H
|
|
|
|
|
|
|
|
#ifndef FLEX_ARRAY
|
|
|
|
/*
|
|
|
|
* See if our compiler is known to support flexible array members.
|
|
|
|
*/
|
|
|
|
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
|
|
|
# define FLEX_ARRAY /* empty */
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
# if (__GNUC__ >= 3)
|
|
|
|
# define FLEX_ARRAY /* empty */
|
|
|
|
# else
|
|
|
|
# define FLEX_ARRAY 0 /* older GNU extension */
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Otherwise, default to safer but a bit wasteful traditional style
|
|
|
|
*/
|
|
|
|
#ifndef FLEX_ARRAY
|
|
|
|
# define FLEX_ARRAY 1
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define TYPEOF(x) (__typeof__(x))
|
|
|
|
#else
|
|
|
|
#define TYPEOF(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (sizeof(x) * 8 - (bits))))
|
|
|
|
#define HAS_MULTI_BITS(i) ((i) & ((i) - 1)) /* checks if an integer has more than 1 bit set */
|
|
|
|
|
|
|
|
/* Approximation of the length of the decimal representation of this type. */
|
|
|
|
#define decimal_length(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1)
|
|
|
|
|
|
|
|
#define _ALL_SOURCE 1
|
|
|
|
#define _BSD_SOURCE 1
|
2010-04-03 20:19:26 +07:00
|
|
|
#define HAS_BOOL
|
2009-04-20 20:00:56 +07:00
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.h>
|
2009-07-21 23:20:22 +07:00
|
|
|
#include <sys/statfs.h>
|
2009-04-20 20:00:56 +07:00
|
|
|
#include <fcntl.h>
|
2010-04-03 20:19:26 +07:00
|
|
|
#include <stdbool.h>
|
2009-04-20 20:00:56 +07:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <fnmatch.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <utime.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <inttypes.h>
|
2012-09-11 05:14:58 +07:00
|
|
|
#include <linux/magic.h>
|
2010-04-03 20:19:26 +07:00
|
|
|
#include "types.h"
|
2010-05-22 21:25:40 +07:00
|
|
|
#include <sys/ttydefaults.h>
|
2013-02-20 22:32:31 +07:00
|
|
|
#include <lk/debugfs.h>
|
2009-08-12 15:19:53 +07:00
|
|
|
|
2009-11-24 02:51:08 +07:00
|
|
|
extern const char *graph_line;
|
|
|
|
extern const char *graph_dotted_line;
|
perf buildid: add perfconfig option to specify buildid cache dir
This patch adds the ability to specify an alternate directory to store the
buildid cache (buildids, copy of binaries). By default, it is hardcoded to
$HOME/.debug. This directory contains immutable data. The layout of the
directory is such that no conflicts in filenames are possible. A modification
in a file, yields a different buildid and thus a different location in the
subdir hierarchy.
You may want to put the buildid cache elsewhere because of disk space
limitation or simply to share the cache between users. It is also useful for
remote collect vs. local analysis of profiles.
This patch adds a new config option to the perfconfig file. Under the tag
'buildid', there is a dir option. For instance, if you have:
$ cat /etc/perfconfig
[buildid]
dir = /var/cache/perf-buildid
All buildids and binaries are be saved in the directory specified. The perf
record, buildid-list, buildid-cache, report, annotate, and archive commands
will it to pull information out.
The option can be set in the system-wide perfconfig file or in the
$HOME/.perfconfig file.
Cc: David S. Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <4c055fb7.df0ce30a.5f0d.ffffae52@mx.google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-06-02 02:25:01 +07:00
|
|
|
extern char buildid_dir[];
|
2013-02-20 22:32:31 +07:00
|
|
|
extern char tracing_events_path[];
|
|
|
|
extern void perf_debugfs_set_path(const char *mountpoint);
|
|
|
|
const char *perf_debugfs_mount(const char *mountpoint);
|
2009-11-24 02:51:08 +07:00
|
|
|
|
2009-04-20 20:00:56 +07:00
|
|
|
/* On most systems <limits.h> would have given us this, but
|
|
|
|
* not on some systems (e.g. GNU/Hurd).
|
|
|
|
*/
|
|
|
|
#ifndef PATH_MAX
|
|
|
|
#define PATH_MAX 4096
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PRIuMAX
|
|
|
|
#define PRIuMAX "llu"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PRIu32
|
|
|
|
#define PRIu32 "u"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PRIx32
|
|
|
|
#define PRIx32 "x"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PATH_SEP
|
|
|
|
#define PATH_SEP ':'
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef STRIP_EXTENSION
|
|
|
|
#define STRIP_EXTENSION ""
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef has_dos_drive_prefix
|
|
|
|
#define has_dos_drive_prefix(path) 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef is_dir_sep
|
|
|
|
#define is_dir_sep(c) ((c) == '/')
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define NORETURN __attribute__((__noreturn__))
|
|
|
|
#else
|
|
|
|
#define NORETURN
|
|
|
|
#ifndef __attribute__
|
|
|
|
#define __attribute__(x)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* General helper functions */
|
|
|
|
extern void usage(const char *err) NORETURN;
|
|
|
|
extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
|
|
|
|
extern int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
|
|
|
extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
|
|
|
|
2009-10-17 07:08:18 +07:00
|
|
|
#include "../../../include/linux/stringify.h"
|
|
|
|
|
|
|
|
#define DIE_IF(cnd) \
|
|
|
|
do { if (cnd) \
|
|
|
|
die(" at (" __FILE__ ":" __stringify(__LINE__) "): " \
|
|
|
|
__stringify(cnd) "\n"); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
2009-04-20 20:00:56 +07:00
|
|
|
extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
|
|
|
|
|
|
|
|
extern int prefixcmp(const char *str, const char *prefix);
|
perf buildid: add perfconfig option to specify buildid cache dir
This patch adds the ability to specify an alternate directory to store the
buildid cache (buildids, copy of binaries). By default, it is hardcoded to
$HOME/.debug. This directory contains immutable data. The layout of the
directory is such that no conflicts in filenames are possible. A modification
in a file, yields a different buildid and thus a different location in the
subdir hierarchy.
You may want to put the buildid cache elsewhere because of disk space
limitation or simply to share the cache between users. It is also useful for
remote collect vs. local analysis of profiles.
This patch adds a new config option to the perfconfig file. Under the tag
'buildid', there is a dir option. For instance, if you have:
$ cat /etc/perfconfig
[buildid]
dir = /var/cache/perf-buildid
All buildids and binaries are be saved in the directory specified. The perf
record, buildid-list, buildid-cache, report, annotate, and archive commands
will it to pull information out.
The option can be set in the system-wide perfconfig file or in the
$HOME/.perfconfig file.
Cc: David S. Miller <davem@davemloft.net>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <4c055fb7.df0ce30a.5f0d.ffffae52@mx.google.com>
Signed-off-by: Stephane Eranian <eranian@google.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2010-06-02 02:25:01 +07:00
|
|
|
extern void set_buildid_dir(void);
|
2010-06-17 16:39:01 +07:00
|
|
|
extern void disable_buildid_cache(void);
|
2009-04-20 20:00:56 +07:00
|
|
|
|
|
|
|
static inline const char *skip_prefix(const char *str, const char *prefix)
|
|
|
|
{
|
|
|
|
size_t len = strlen(prefix);
|
|
|
|
return strncmp(str, prefix, len) ? NULL : str + len;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __GLIBC_PREREQ
|
|
|
|
#if __GLIBC_PREREQ(2, 1)
|
|
|
|
#define HAVE_STRCHRNUL
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STRCHRNUL
|
|
|
|
#define strchrnul gitstrchrnul
|
|
|
|
static inline char *gitstrchrnul(const char *s, int c)
|
|
|
|
{
|
|
|
|
while (*s && *s != c)
|
|
|
|
s++;
|
|
|
|
return (char *)s;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-04-20 20:22:22 +07:00
|
|
|
/*
|
|
|
|
* Wrappers:
|
|
|
|
*/
|
|
|
|
extern char *xstrdup(const char *str);
|
2009-11-24 21:05:17 +07:00
|
|
|
extern void *xrealloc(void *ptr, size_t size) __attribute__((weak));
|
2009-05-27 14:10:38 +07:00
|
|
|
|
2010-03-17 05:05:21 +07:00
|
|
|
|
2009-11-24 21:05:16 +07:00
|
|
|
static inline void *zalloc(size_t size)
|
|
|
|
{
|
|
|
|
return calloc(1, size);
|
|
|
|
}
|
|
|
|
|
2009-04-20 20:00:56 +07:00
|
|
|
static inline int has_extension(const char *filename, const char *ext)
|
|
|
|
{
|
|
|
|
size_t len = strlen(filename);
|
|
|
|
size_t extlen = strlen(ext);
|
2010-03-17 05:05:21 +07:00
|
|
|
|
2009-04-20 20:00:56 +07:00
|
|
|
return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sane ctype - no locale, and works with signed chars */
|
|
|
|
#undef isascii
|
|
|
|
#undef isspace
|
|
|
|
#undef isdigit
|
2009-11-11 10:51:07 +07:00
|
|
|
#undef isxdigit
|
2009-04-20 20:00:56 +07:00
|
|
|
#undef isalpha
|
2009-08-17 21:18:08 +07:00
|
|
|
#undef isprint
|
2009-04-20 20:00:56 +07:00
|
|
|
#undef isalnum
|
2012-02-10 08:10:15 +07:00
|
|
|
#undef islower
|
|
|
|
#undef isupper
|
2009-04-20 20:00:56 +07:00
|
|
|
#undef tolower
|
|
|
|
#undef toupper
|
2010-03-17 05:05:21 +07:00
|
|
|
|
perf trace: Support interrupted syscalls
Using the same strategies as in the tmp.perf/trace2, i.e. the 'trace'
tool implemented by tglx, just updated to the current codebase.
Example:
[root@sandy linux]# perf trace usleep 1 | tail
2.003: mmap(addr: 0, len: 4096, prot: 3, flags: 34, fd: 4294967295, off: 0 ) = -2128396288
2.017: mmap(addr: 0, len: 4096, prot: 3, flags: 34, fd: 4294967295, off: 0 ) = -2128400384
2.029: arch_prctl(option: 4098, arg2: 140146949441280, arg3: 140146949435392, arg4: 34, arg5: 4294967295) = 0
2.084: mprotect(start: 208741634048, len: 16384, prot: 1 ) = 0
2.098: mprotect(start: 208735956992, len: 4096, prot: 1 ) = 0
2.122: munmap(addr: 140146949447680, len: 91882 ) = 0
2.359: brk(brk: 0 ) = 28987392
2.371: brk(brk: 29122560 ) = 29122560
2.490: nanosleep(rqtp: 140735694241504, rmtp: 0 ) = 0
2.507: exit_group(error_code: 0
[root@sandy linux]#
For now the timestamp and duration are always on, will be selectable.
Also if multiple threads are being monitored, its tid will appear.
The ret output continues to be interpreted a la strace.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-ly9ulroru4my5isn0xe9gr0m@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-10-07 04:43:19 +07:00
|
|
|
#ifndef NSEC_PER_MSEC
|
|
|
|
#define NSEC_PER_MSEC 1000000L
|
|
|
|
#endif
|
|
|
|
|
2009-04-20 20:00:56 +07:00
|
|
|
extern unsigned char sane_ctype[256];
|
2009-06-18 14:44:20 +07:00
|
|
|
#define GIT_SPACE 0x01
|
|
|
|
#define GIT_DIGIT 0x02
|
|
|
|
#define GIT_ALPHA 0x04
|
|
|
|
#define GIT_GLOB_SPECIAL 0x08
|
|
|
|
#define GIT_REGEX_SPECIAL 0x10
|
|
|
|
#define GIT_PRINT_EXTRA 0x20
|
|
|
|
#define GIT_PRINT 0x3E
|
2009-04-20 20:00:56 +07:00
|
|
|
#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
|
|
|
|
#define isascii(x) (((x) & ~0x7f) == 0)
|
|
|
|
#define isspace(x) sane_istest(x,GIT_SPACE)
|
|
|
|
#define isdigit(x) sane_istest(x,GIT_DIGIT)
|
2009-11-11 10:51:07 +07:00
|
|
|
#define isxdigit(x) \
|
|
|
|
(sane_istest(toupper(x), GIT_ALPHA | GIT_DIGIT) && toupper(x) < 'G')
|
2009-04-20 20:00:56 +07:00
|
|
|
#define isalpha(x) sane_istest(x,GIT_ALPHA)
|
|
|
|
#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
|
2009-06-18 14:44:20 +07:00
|
|
|
#define isprint(x) sane_istest(x,GIT_PRINT)
|
2012-02-10 08:10:15 +07:00
|
|
|
#define islower(x) (sane_istest(x,GIT_ALPHA) && sane_istest(x,0x20))
|
|
|
|
#define isupper(x) (sane_istest(x,GIT_ALPHA) && !sane_istest(x,0x20))
|
2009-04-20 20:00:56 +07:00
|
|
|
#define tolower(x) sane_case((unsigned char)(x), 0x20)
|
|
|
|
#define toupper(x) sane_case((unsigned char)(x), 0)
|
|
|
|
|
|
|
|
static inline int sane_case(int x, int high)
|
|
|
|
{
|
|
|
|
if (sane_istest(x, GIT_ALPHA))
|
|
|
|
x = (x & ~0x20) | high;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
perf record: Introduce a symtab cache
Now a cache will be created in a ~/.debug debuginfo like
hierarchy, so that at the end of a 'perf record' session all the
binaries (with build-ids) involved get collected and indexed by
their build-ids, so that perf report can find them.
This is interesting when developing software where you want to
do a 'perf diff' with the previous build and opens avenues for
lots more interesting tools, like a 'perf diff --graph' that
takes more than two binaries into account.
Tunables for collecting just the symtabs can be added if one
doesn't want to have the full binary, but having the full binary
allows things like 'perf rerecord' or other tools that can
re-run the tests by having access to the exact binary in some
perf.data file, so it may well be interesting to keep the full
binary there.
Space consumption is minimised by trying to use hard links, a
'perf cache' tool to manage the space used, a la ccache is
required to purge older entries.
With this in place it will be possible also to introduce new
commands, 'perf archive' and 'perf restore' (or some more
suitable and future proof names) to create a cpio/tar file with
the perf data and the files in the cache that _had_ perf hits of
interest.
There are more aspects to polish, like finding the right vmlinux
file to cache, etc, but this is enough for a first step.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1261957026-15580-10-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-12-28 06:37:06 +07:00
|
|
|
int mkdir_p(char *path, mode_t mode);
|
|
|
|
int copyfile(const char *from, const char *to);
|
|
|
|
|
2010-04-03 20:19:26 +07:00
|
|
|
s64 perf_atoll(const char *str);
|
|
|
|
char **argv_split(const char *str, int *argcp);
|
|
|
|
void argv_free(char **argv);
|
|
|
|
bool strglobmatch(const char *str, const char *pat);
|
|
|
|
bool strlazymatch(const char *str, const char *pat);
|
2011-06-27 14:27:15 +07:00
|
|
|
int strtailcmp(const char *s1, const char *s2);
|
2012-10-28 04:18:31 +07:00
|
|
|
char *strxfrchar(char *s, char from, char to);
|
2010-05-15 00:19:35 +07:00
|
|
|
unsigned long convert_unit(unsigned long value, char *unit);
|
2011-01-04 01:50:55 +07:00
|
|
|
int readn(int fd, void *buf, size_t size);
|
2010-04-03 20:19:26 +07:00
|
|
|
|
2012-01-04 23:54:20 +07:00
|
|
|
struct perf_event_attr;
|
|
|
|
|
|
|
|
void event_attr_init(struct perf_event_attr *attr);
|
|
|
|
|
2010-04-03 20:19:26 +07:00
|
|
|
#define _STR(x) #x
|
|
|
|
#define STR(x) _STR(x)
|
|
|
|
|
2011-12-19 20:39:32 +07:00
|
|
|
/*
|
|
|
|
* Determine whether some value is a power of two, where zero is
|
|
|
|
* *not* considered a power of two.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline __attribute__((const))
|
|
|
|
bool is_power_of_2(unsigned long n)
|
|
|
|
{
|
|
|
|
return (n != 0 && ((n & (n - 1)) == 0));
|
|
|
|
}
|
|
|
|
|
2012-04-19 23:15:24 +07:00
|
|
|
size_t hex_width(u64 v);
|
2012-10-28 04:18:30 +07:00
|
|
|
int hex2u64(const char *ptr, u64 *val);
|
2012-04-19 23:15:24 +07:00
|
|
|
|
2013-01-22 16:09:41 +07:00
|
|
|
char *ltrim(char *s);
|
2012-06-08 04:23:31 +07:00
|
|
|
char *rtrim(char *s);
|
|
|
|
|
2012-08-08 09:32:05 +07:00
|
|
|
void dump_stack(void);
|
|
|
|
|
2012-10-07 00:57:10 +07:00
|
|
|
extern unsigned int page_size;
|
|
|
|
|
2013-01-15 00:48:01 +07:00
|
|
|
struct winsize;
|
|
|
|
void get_term_dimensions(struct winsize *ws);
|
2013-02-20 22:32:31 +07:00
|
|
|
#endif /* GIT_COMPAT_UTIL_H */
|