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