perf tools: Include errno.h where needed
[linux-2.6-block.git] / tools / perf / util / util.h
CommitLineData
07800601
IM
1#ifndef GIT_COMPAT_UTIL_H
2#define GIT_COMPAT_UTIL_H
3
07800601 4#define _ALL_SOURCE 1
07800601 5#define _BSD_SOURCE 1
512fe365
CP
6/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
7#define _DEFAULT_SOURCE 1
e206d556 8#define HAS_BOOL
07800601
IM
9
10#include <unistd.h>
11#include <stdio.h>
12#include <sys/stat.h>
f6bdafef 13#include <sys/statfs.h>
07800601 14#include <fcntl.h>
e206d556 15#include <stdbool.h>
07800601
IM
16#include <stddef.h>
17#include <stdlib.h>
18#include <stdarg.h>
19#include <string.h>
1fe143c5 20#include <term.h>
07800601
IM
21#include <limits.h>
22#include <sys/param.h>
23#include <sys/types.h>
24#include <dirent.h>
25#include <sys/time.h>
26#include <time.h>
27#include <signal.h>
28#include <fnmatch.h>
29#include <assert.h>
30#include <regex.h>
31#include <utime.h>
07800601 32#include <sys/wait.h>
a8fa4960 33#include <poll.h>
07800601
IM
34#include <sys/socket.h>
35#include <sys/ioctl.h>
972f393b 36#include <linux/kernel.h>
d944c4ee 37#include <linux/types.h>
46e3e055 38#include <sys/ttydefaults.h>
4605eab3 39#include <api/fs/tracing_path.h>
756bbc84 40#include <termios.h>
1dbfa938 41#include <linux/bitops.h>
9398c484 42#include <termios.h>
e1ce726e 43#include "strlist.h"
1fe2c106 44
45de34bb 45extern char buildid_dir[];
2890284b 46
07800601
IM
47#ifdef __GNUC__
48#define NORETURN __attribute__((__noreturn__))
49#else
50#define NORETURN
51#ifndef __attribute__
52#define __attribute__(x)
53#endif
54#endif
55
fc67297b
NK
56#define PERF_GTK_DSO "libperf-gtk.so"
57
07800601 58/* General helper functions */
3938bad4
ACM
59void usage(const char *err) NORETURN;
60void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
61int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
62void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
07800601 63
3938bad4 64void set_warning_routine(void (*routine)(const char *err, va_list params));
07800601 65
3938bad4
ACM
66int prefixcmp(const char *str, const char *prefix);
67void set_buildid_dir(const char *dir);
07800601 68
07800601
IM
69#ifdef __GLIBC_PREREQ
70#if __GLIBC_PREREQ(2, 1)
71#define HAVE_STRCHRNUL
72#endif
73#endif
74
75#ifndef HAVE_STRCHRNUL
76#define strchrnul gitstrchrnul
77static inline char *gitstrchrnul(const char *s, int c)
78{
79 while (*s && *s != c)
80 s++;
81 return (char *)s;
82}
83#endif
84
36479484
ACM
85static inline void *zalloc(size_t size)
86{
87 return calloc(1, size);
88}
89
04662523
ACM
90#define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
91
4cf40131 92int mkdir_p(char *path, mode_t mode);
9a9c733d 93int rm_rf(const char *path);
e1ce726e
MH
94struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
95bool lsdir_no_dot_filter(const char *name, struct dirent *d);
4cf40131 96int copyfile(const char *from, const char *to);
9a17d726 97int copyfile_mode(const char *from, const char *to, mode_t mode);
9c9f5a2f 98int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
4cf40131 99
c82ee828 100unsigned long convert_unit(unsigned long value, char *unit);
727ebd54 101ssize_t readn(int fd, void *buf, size_t n);
bc3a502b 102ssize_t writen(int fd, void *buf, size_t n);
e206d556 103
1aed2671
JR
104struct perf_event_attr;
105
106void event_attr_init(struct perf_event_attr *attr);
107
61e04b33 108size_t hex_width(u64 v);
b2aff5f6 109int hex2u64(const char *ptr, u64 *val);
61e04b33 110
dc4552bf 111void dump_stack(void);
07c1a0da 112void sighandler_dump_stack(int sig);
dc4552bf 113
0c1fe6b2 114extern unsigned int page_size;
2b1b7100 115extern int cacheline_size;
a29d5c9b
ACM
116extern int sysctl_perf_event_max_stack;
117extern int sysctl_perf_event_max_contexts_per_stack;
0c1fe6b2 118
27050f53
JO
119struct parse_tag {
120 char tag;
121 int mult;
122};
123
124unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
f048d548 125
972f393b
ACM
126static inline int path__join(char *bf, size_t size,
127 const char *path1, const char *path2)
128{
129 return scnprintf(bf, size, "%s%s%s", path1, path1[0] ? "/" : "", path2);
130}
131
132static inline int path__join3(char *bf, size_t size,
133 const char *path1, const char *path2,
134 const char *path3)
135{
136 return scnprintf(bf, size, "%s%s%s%s%s",
137 path1, path1[0] ? "/" : "",
138 path2, path2[0] ? "/" : "", path3);
139}
140
1a47245d 141int perf_event_paranoid(void);
e1a2b174 142
71db07b1
AH
143void mem_bswap_64(void *src, int byte_size);
144void mem_bswap_32(void *src, int byte_size);
145
e1a2b174 146const char *get_filename_for_perf_kvm(void);
63914aca 147bool find_process(const char *name);
e92ce12e
NK
148
149#ifdef HAVE_ZLIB_SUPPORT
150int gzip_decompress_to_file(const char *input, int output_fd);
151#endif
152
80a32e5b
JO
153#ifdef HAVE_LZMA_SUPPORT
154int lzma_decompress_to_file(const char *input, int output_fd);
155#endif
156
076a30c4
KL
157int get_stack_size(const char *str, unsigned long *_size);
158
07bc5c69
WN
159int fetch_kernel_version(unsigned int *puint,
160 char *str, size_t str_sz);
d3e0ce39
WN
161#define KVER_VERSION(x) (((x) >> 16) & 0xff)
162#define KVER_PATCHLEVEL(x) (((x) >> 8) & 0xff)
163#define KVER_SUBLEVEL(x) ((x) & 0xff)
164#define KVER_FMT "%d.%d.%d"
165#define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
07bc5c69 166
14cbfbeb 167const char *perf_tip(const char *dirpath);
40356721 168bool is_regular_file(const char *file);
37b20151 169int fetch_current_timestamp(char *buf, size_t sz);
14cbfbeb 170
120010cb
ACM
171#ifndef HAVE_SCHED_GETCPU_SUPPORT
172int sched_getcpu(void);
c7007e98
ACM
173#endif
174
99620a5d
NK
175int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
176
9808143b 177int unit_number__scnprintf(char *buf, size_t size, u64 n);
a64489c5 178
1355915a 179#endif /* GIT_COMPAT_UTIL_H */