]> git.karo-electronics.de Git - karo-tx-linux.git/blob - tools/perf/util/util.h
perf tools: Move units conversion/formatting routines to separate object
[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 <sys/statfs.h>
14 #include <fcntl.h>
15 #include <stdbool.h>
16 #include <stddef.h>
17 #include <stdlib.h>
18 #include <stdarg.h>
19 #include <string.h>
20 #include <limits.h>
21 #include <sys/param.h>
22 #include <sys/types.h>
23 #include <sys/time.h>
24 #include <time.h>
25 #include <assert.h>
26 #include <utime.h>
27 #include <sys/wait.h>
28 #include <poll.h>
29 #include <sys/socket.h>
30 #include <sys/ioctl.h>
31 #include <linux/kernel.h>
32 #include <linux/types.h>
33
34 extern char buildid_dir[];
35
36 #ifdef __GNUC__
37 #define NORETURN __attribute__((__noreturn__))
38 #else
39 #define NORETURN
40 #ifndef __attribute__
41 #define __attribute__(x)
42 #endif
43 #endif
44
45 #define PERF_GTK_DSO  "libperf-gtk.so"
46
47 /* General helper functions */
48 void usage(const char *err) NORETURN;
49 void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));
50 int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
51 void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
52
53 void set_warning_routine(void (*routine)(const char *err, va_list params));
54
55 int prefixcmp(const char *str, const char *prefix);
56 void set_buildid_dir(const char *dir);
57
58 static inline void *zalloc(size_t size)
59 {
60         return calloc(1, size);
61 }
62
63 #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
64
65 struct dirent;
66 struct strlist;
67
68 int mkdir_p(char *path, mode_t mode);
69 int rm_rf(const char *path);
70 struct strlist *lsdir(const char *name, bool (*filter)(const char *, struct dirent *));
71 bool lsdir_no_dot_filter(const char *name, struct dirent *d);
72 int copyfile(const char *from, const char *to);
73 int copyfile_mode(const char *from, const char *to, mode_t mode);
74 int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
75
76 ssize_t readn(int fd, void *buf, size_t n);
77 ssize_t writen(int fd, void *buf, size_t n);
78
79 struct perf_event_attr;
80
81 void event_attr_init(struct perf_event_attr *attr);
82
83 size_t hex_width(u64 v);
84 int hex2u64(const char *ptr, u64 *val);
85
86 void dump_stack(void);
87 void sighandler_dump_stack(int sig);
88
89 extern unsigned int page_size;
90 extern int cacheline_size;
91 extern int sysctl_perf_event_max_stack;
92 extern int sysctl_perf_event_max_contexts_per_stack;
93
94 struct parse_tag {
95         char tag;
96         int mult;
97 };
98
99 unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
100
101 int perf_event_paranoid(void);
102
103 void mem_bswap_64(void *src, int byte_size);
104 void mem_bswap_32(void *src, int byte_size);
105
106 const char *get_filename_for_perf_kvm(void);
107 bool find_process(const char *name);
108
109 #ifdef HAVE_ZLIB_SUPPORT
110 int gzip_decompress_to_file(const char *input, int output_fd);
111 #endif
112
113 #ifdef HAVE_LZMA_SUPPORT
114 int lzma_decompress_to_file(const char *input, int output_fd);
115 #endif
116
117 int get_stack_size(const char *str, unsigned long *_size);
118
119 int fetch_kernel_version(unsigned int *puint,
120                          char *str, size_t str_sz);
121 #define KVER_VERSION(x)         (((x) >> 16) & 0xff)
122 #define KVER_PATCHLEVEL(x)      (((x) >> 8) & 0xff)
123 #define KVER_SUBLEVEL(x)        ((x) & 0xff)
124 #define KVER_FMT        "%d.%d.%d"
125 #define KVER_PARAM(x)   KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x)
126
127 const char *perf_tip(const char *dirpath);
128 int fetch_current_timestamp(char *buf, size_t sz);
129
130 #ifndef HAVE_SCHED_GETCPU_SUPPORT
131 int sched_getcpu(void);
132 #endif
133
134 int timestamp__scnprintf_usec(u64 timestamp, char *buf, size_t sz);
135
136 #endif /* GIT_COMPAT_UTIL_H */