6 * XXX We need to find a better place for these things...
9 bool perf_guest = false;
11 void event_attr_init(struct perf_event_attr *attr)
14 attr->exclude_host = 1;
16 attr->exclude_guest = 1;
17 /* to capture ABI version */
18 attr->size = sizeof(*attr);
21 int mkdir_p(char *path, mode_t mode)
30 if (stat(path, &st) == 0)
35 while ((d = strchr(d, '/'))) {
37 err = stat(path, &st) && mkdir(path, mode);
44 return (stat(path, &st) && mkdir(path, mode)) ? -1 : 0;
47 static int slow_copyfile(const char *from, const char *to)
52 FILE *from_fp = fopen(from, "r"), *to_fp;
57 to_fp = fopen(to, "w");
61 while (getline(&line, &n, from_fp) > 0)
62 if (fputs(line, to_fp) == EOF)
74 int copyfile(const char *from, const char *to)
84 if (st.st_size == 0) /* /proc? do it slowly... */
85 return slow_copyfile(from, to);
87 fromfd = open(from, O_RDONLY);
91 tofd = creat(to, 0755);
95 addr = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fromfd, 0);
96 if (addr == MAP_FAILED)
99 if (write(tofd, addr, st.st_size) == st.st_size)
102 munmap(addr, st.st_size);
113 unsigned long convert_unit(unsigned long value, char *unit)
135 int readn(int fd, void *buf, size_t n)
137 void *buf_start = buf;
140 int ret = read(fd, buf, n);
149 return buf - buf_start;
152 size_t hex_width(u64 v)