11 * XXX We need to find a better place for these things...
13 bool perf_host = true;
14 bool perf_guest = false;
16 void event_attr_init(struct perf_event_attr *attr)
19 attr->exclude_host = 1;
21 attr->exclude_guest = 1;
22 /* to capture ABI version */
23 attr->size = sizeof(*attr);
26 int mkdir_p(char *path, mode_t mode)
35 if (stat(path, &st) == 0)
40 while ((d = strchr(d, '/'))) {
42 err = stat(path, &st) && mkdir(path, mode);
49 return (stat(path, &st) && mkdir(path, mode)) ? -1 : 0;
52 static int slow_copyfile(const char *from, const char *to)
57 FILE *from_fp = fopen(from, "r"), *to_fp;
62 to_fp = fopen(to, "w");
66 while (getline(&line, &n, from_fp) > 0)
67 if (fputs(line, to_fp) == EOF)
79 int copyfile(const char *from, const char *to)
89 if (st.st_size == 0) /* /proc? do it slowly... */
90 return slow_copyfile(from, to);
92 fromfd = open(from, O_RDONLY);
96 tofd = creat(to, 0755);
100 addr = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fromfd, 0);
101 if (addr == MAP_FAILED)
104 if (write(tofd, addr, st.st_size) == st.st_size)
107 munmap(addr, st.st_size);
118 unsigned long convert_unit(unsigned long value, char *unit)
140 int readn(int fd, void *buf, size_t n)
142 void *buf_start = buf;
145 int ret = read(fd, buf, n);
154 return buf - buf_start;
157 size_t hex_width(u64 v)
167 /* Obtain a backtrace and print it to stdout. */
169 void dump_stack(void)
172 size_t size = backtrace(array, ARRAY_SIZE(array));
173 char **strings = backtrace_symbols(array, size);
176 printf("Obtained %zd stack frames.\n", size);
178 for (i = 0; i < size; i++)
179 printf("%s\n", strings[i]);
184 void dump_stack(void) {}