]> git.karo-electronics.de Git - karo-tx-linux.git/blob - tools/perf/util/util.h
perf tools: Remove a few more needless includes from util.h
[karo-tx-linux.git] / tools / perf / util / util.h
1 #ifndef GIT_COMPAT_UTIL_H
2 #define GIT_COMPAT_UTIL_H
3
4 #define _ALL_SOURCE 1
5 #define _BSD_SOURCE 1
6 /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
7 #define _DEFAULT_SOURCE 1
8 #define HAS_BOOL
9
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14 #include <stdbool.h>
15 #include <stddef.h>
16 #include <stdlib.h>
17 #include <stdarg.h>
18 #include <string.h>
19 #include <sys/wait.h>
20 #include <poll.h>
21 #include <sys/ioctl.h>
22 #include <linux/types.h>
23
24 extern char buildid_dir[];
25
26 #ifdef __GNUC__
27 #define NORETURN __attribute__((__noreturn__))
28 #else
29 #define NORETURN
30 #ifndef __attribute__
31 #define __attribute__(x)
32 #endif
33 #endif
34
35 #define PERF_GTK_DSO  "libperf-gtk.so"
36
37 /* General helper functions */
38 void usage(const char *err) NORETURN;
39 void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
40 int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
41 void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
42
43 void set_warning_routine(void (*routine)(const char *err, va_list params));
44
45 int prefixcmp(const char *str, const char *prefix);
46 void set_buildid_dir(const char *dir);
47
48 static inline void *zalloc(size_t size)
49 {
50         return calloc(1, size);
51 }
52
53 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
54
55 struct dirent;
56 struct strlist;
57
58 int mkdir_p(char *path, mode_t mode);
59 int rm_rf(const char *path);
60 struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
61 bool lsdir_no_dot_filter(const char *name, struct dirent *d);
62 int copyfile(const char *from, const char *to);
63 int copyfile_mode(const char *from, const char *to, mode_t mode);
64 int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
65
66 ssize_t readn(int fd, void *buf, size_t n);
67 ssize_t writen(int fd, void *buf, size_t n);
68
69 struct perf_event_attr;
70
71 void event_attr_init(struct perf_event_attr *attr);
72
73 size_t hex_width(u64 v);
74 int hex2u64(const char *ptr, u64 *val);
75
76 extern unsigned int page_size;
77 extern int cacheline_size;
78 extern int sysctl_perf_event_max_stack;
79 extern int sysctl_perf_event_max_contexts_per_stack;
80
81 struct parse_tag {
82         char tag;
83         int mult;
84 };
85
86 unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
87
88 int perf_event_paranoid(void);
89
90 void mem_bswap_64(void *src, int byte_size);
91 void mem_bswap_32(void *src, int byte_size);
92
93 bool find_process(const char *name);
94
95 int fetch_kernel_version(unsigned int *puint,
96                          char *str, size_t str_sz);
97 #define KVER_VERSION(x)         (((x) >> 16) & 0xff)
98 #define KVER_PATCHLEVEL(x)      (((x) >> 8) & 0xff)
99 #define KVER_SUBLEVEL(x)        ((x) & 0xff)
100 #define KVER_FMT        "%d.%d.%d"
101 #define KVER_PARAM(x)   KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
102
103 const char *perf_tip(const char *dirpath);
104
105 #ifndef HAVE_SCHED_GETCPU_SUPPORT
106 int sched_getcpu(void);
107 #endif
108
109 #endif /* GIT_COMPAT_UTIL_H */