blob: 4b9aab7f04056ef6d599ba9e2eb8d7d3333d579b [file] [log] [blame]
John Kacur8b40f522009-09-24 18:02:18 +02001#ifndef __PERF_CACHE_H
2#define __PERF_CACHE_H
Ingo Molnar07800602009-04-20 15:00:56 +02003
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -03004#include <stdbool.h>
Ingo Molnar07800602009-04-20 15:00:56 +02005#include "util.h"
6#include "strbuf.h"
Ingo Molnarf37a2912009-07-01 12:37:06 +02007#include "../perf.h"
Ingo Molnar07800602009-04-20 15:00:56 +02008
Vincent Legollcfed95a2009-10-13 10:18:16 +02009#define CMD_EXEC_PATH "--exec-path"
10#define CMD_PERF_DIR "--perf-dir="
11#define CMD_WORK_TREE "--work-tree="
12#define CMD_DEBUGFS_DIR "--debugfs-dir="
13
Ingo Molnar07800602009-04-20 15:00:56 +020014#define PERF_DIR_ENVIRONMENT "PERF_DIR"
15#define PERF_WORK_TREE_ENVIRONMENT "PERF_WORK_TREE"
16#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
17#define DB_ENVIRONMENT "PERF_OBJECT_DIRECTORY"
18#define INDEX_ENVIRONMENT "PERF_INDEX_FILE"
19#define GRAFT_ENVIRONMENT "PERF_GRAFT_FILE"
20#define TEMPLATE_DIR_ENVIRONMENT "PERF_TEMPLATE_DIR"
21#define CONFIG_ENVIRONMENT "PERF_CONFIG"
22#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
23#define CEILING_DIRECTORIES_ENVIRONMENT "PERF_CEILING_DIRECTORIES"
24#define PERFATTRIBUTES_FILE ".perfattributes"
25#define INFOATTRIBUTES_FILE "info/attributes"
26#define ATTRIBUTE_MACRO_PREFIX "[attr]"
Jason Baron5beeded2009-07-21 14:16:29 -040027#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
Ingo Molnar07800602009-04-20 15:00:56 +020028
29typedef int (*config_fn_t)(const char *, const char *, void *);
30extern int perf_default_config(const char *, const char *, void *);
31extern int perf_config_from_file(config_fn_t fn, const char *, void *);
32extern int perf_config(config_fn_t fn, void *);
33extern int perf_parse_ulong(const char *, unsigned long *);
34extern int perf_config_int(const char *, const char *);
35extern unsigned long perf_config_ulong(const char *, const char *);
36extern int perf_config_bool_or_int(const char *, const char *, int *);
37extern int perf_config_bool(const char *, const char *);
38extern int perf_config_string(const char **, const char *, const char *);
39extern int perf_config_set(const char *, const char *);
40extern int perf_config_set_multivar(const char *, const char *, const char *, int);
41extern int perf_config_rename_section(const char *, const char *);
42extern const char *perf_etc_perfconfig(void);
43extern int check_repository_format_version(const char *var, const char *value, void *cb);
44extern int perf_config_system(void);
45extern int perf_config_global(void);
46extern int config_error_nonbool(const char *);
47extern const char *config_exclusive_filename;
48
49#define MAX_PERFNAME (1000)
50extern char perf_default_email[MAX_PERFNAME];
51extern char perf_default_name[MAX_PERFNAME];
52extern int user_ident_explicitly_given;
53
54extern const char *perf_log_output_encoding;
55extern const char *perf_mailmap_file;
56
57/* IO helper functions */
58extern void maybe_flush_or_die(FILE *, const char *);
59extern int copy_fd(int ifd, int ofd);
60extern int copy_file(const char *dst, const char *src, int mode);
Ingo Molnar07800602009-04-20 15:00:56 +020061extern ssize_t write_in_full(int fd, const void *buf, size_t count);
62extern void write_or_die(int fd, const void *buf, size_t count);
63extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
64extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg);
65extern void fsync_or_die(int fd, const char *);
66
67/* pager.c */
68extern void setup_pager(void);
69extern const char *pager_program;
70extern int pager_in_use(void);
71extern int pager_use_color;
72
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -030073extern bool use_browser;
74
75#ifdef NO_NEWT_SUPPORT
76static inline void setup_browser(void)
77{
78 setup_pager();
79}
Arnaldo Carvalho de Melof3a1f0e2010-03-22 13:10:25 -030080static inline void exit_browser(bool wait_for_ok __used) {}
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -030081#else
82void setup_browser(void);
Arnaldo Carvalho de Melof3a1f0e2010-03-22 13:10:25 -030083void exit_browser(bool wait_for_ok);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -030084#endif
85
Ingo Molnar07800602009-04-20 15:00:56 +020086extern const char *editor_program;
87extern const char *excludes_file;
88
89char *alias_lookup(const char *alias);
90int split_cmdline(char *cmdline, const char ***argv);
91
92#define alloc_nr(x) (((x)+16)*3/2)
93
94/*
95 * Realloc the buffer pointed at by variable 'x' so that it can hold
96 * at least 'nr' entries; the number of entries currently allocated
97 * is 'alloc', using the standard growing factor alloc_nr() macro.
98 *
99 * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
100 */
101#define ALLOC_GROW(x, nr, alloc) \
102 do { \
103 if ((nr) > alloc) { \
104 if (alloc_nr(alloc) < (nr)) \
105 alloc = (nr); \
106 else \
107 alloc = alloc_nr(alloc); \
108 x = xrealloc((x), alloc * sizeof(*(x))); \
109 } \
110 } while(0)
111
112
113static inline int is_absolute_path(const char *path)
114{
115 return path[0] == '/';
116}
Ingo Molnar6f06ccb2009-04-20 15:22:22 +0200117
118const char *make_absolute_path(const char *path);
119const char *make_nonrelative_path(const char *path);
120const char *make_relative_path(const char *abs, const char *base);
121int normalize_path_copy(char *dst, const char *src);
122int longest_ancestor_length(const char *path, const char *prefix_list);
123char *strip_path_suffix(const char *path, const char *suffix);
124
125extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
126extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
Ingo Molnar16f762a2009-05-27 09:10:38 +0200127/* perf_mkstemp() - create tmp file honoring TMPDIR variable */
128extern int perf_mkstemp(char *path, size_t len, const char *template);
Ingo Molnar6f06ccb2009-04-20 15:22:22 +0200129
130extern char *mksnpath(char *buf, size_t n, const char *fmt, ...)
131 __attribute__((format (printf, 3, 4)));
132extern char *perf_snpath(char *buf, size_t n, const char *fmt, ...)
133 __attribute__((format (printf, 3, 4)));
134extern char *perf_pathdup(const char *fmt, ...)
135 __attribute__((format (printf, 1, 2)));
136
137extern size_t strlcpy(char *dest, const char *src, size_t size);
138
John Kacur8b40f522009-09-24 18:02:18 +0200139#endif /* __PERF_CACHE_H */