]> git.karo-electronics.de Git - karo-tx-linux.git/blob - tools/perf/util/util.h
622c2d251ad363bc243efdcb881fc4c9a3a4e875
[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
9 #include <fcntl.h>
10 #include <stdbool.h>
11 #include <stddef.h>
12 #include <stdlib.h>
13 #include <stdarg.h>
14 #include <linux/types.h>
15
16 #ifdef __GNUC__
17 #define NORETURN __attribute__((__noreturn__))
18 #else
19 #define NORETURN
20 #ifndef __attribute__
21 #define __attribute__(x)
22 #endif
23 #endif
24
25 #define PERF_GTK_DSO  "libperf-gtk.so"
26
27 /* General helper functions */
28 void usage(const char *err) NORETURN;
29 void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
30 int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
31 void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
32
33 void set_warning_routine(void (*routine)(const char *err, va_list params));
34
35 int prefixcmp(const char *str, const char *prefix);
36
37 static inline void *zalloc(size_t size)
38 {
39         return calloc(1, size);
40 }
41
42 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
43
44 struct dirent;
45 struct strlist;
46
47 int mkdir_p(char *path, mode_t mode);
48 int rm_rf(const char *path);
49 struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
50 bool lsdir_no_dot_filter(const char *name, struct dirent *d);
51 int copyfile(const char *from, const char *to);
52 int copyfile_mode(const char *from, const char *to, mode_t mode);
53 int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
54
55 ssize_t readn(int fd, void *buf, size_t n);
56 ssize_t writen(int fd, void *buf, size_t n);
57
58 size_t hex_width(u64 v);
59 int hex2u64(const char *ptr, u64 *val);
60
61 extern unsigned int page_size;
62 extern int cacheline_size;
63
64 struct parse_tag {
65         char tag;
66         int mult;
67 };
68
69 unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
70
71 bool find_process(const char *name);
72
73 int fetch_kernel_version(unsigned int *puint,
74                          char *str, size_t str_sz);
75 #define KVER_VERSION(x)         (((x) >> 16) & 0xff)
76 #define KVER_PATCHLEVEL(x)      (((x) >> 8) & 0xff)
77 #define KVER_SUBLEVEL(x)        ((x) & 0xff)
78 #define KVER_FMT        "%d.%d.%d"
79 #define KVER_PARAM(x)   KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
80
81 const char *perf_tip(const char *dirpath);
82
83 #ifndef HAVE_SCHED_GETCPU_SUPPORT
84 int sched_getcpu(void);
85 #endif
86
87 #endif /* GIT_COMPAT_UTIL_H */