diff options
| -rw-r--r-- | tools/perf/jvmti/jvmti_agent.c | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c index ac1bcdc17dae..f7eb63cbbc65 100644 --- a/tools/perf/jvmti/jvmti_agent.c +++ b/tools/perf/jvmti/jvmti_agent.c | |||
| @@ -125,7 +125,7 @@ perf_get_timestamp(void) | |||
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | static int | 127 | static int |
| 128 | debug_cache_init(void) | 128 | create_jit_cache_dir(void) |
| 129 | { | 129 | { |
| 130 | char str[32]; | 130 | char str[32]; |
| 131 | char *base, *p; | 131 | char *base, *p; |
| @@ -144,8 +144,13 @@ debug_cache_init(void) | |||
| 144 | 144 | ||
| 145 | strftime(str, sizeof(str), JIT_LANG"-jit-%Y%m%d", &tm); | 145 | strftime(str, sizeof(str), JIT_LANG"-jit-%Y%m%d", &tm); |
| 146 | 146 | ||
| 147 | snprintf(jit_path, PATH_MAX - 1, "%s/.debug/", base); | 147 | ret = snprintf(jit_path, PATH_MAX, "%s/.debug/", base); |
| 148 | 148 | if (ret >= PATH_MAX) { | |
| 149 | warnx("jvmti: cannot generate jit cache dir because %s/.debug/" | ||
| 150 | " is too long, please check the cwd, JITDUMPDIR, and" | ||
| 151 | " HOME variables", base); | ||
| 152 | return -1; | ||
| 153 | } | ||
| 149 | ret = mkdir(jit_path, 0755); | 154 | ret = mkdir(jit_path, 0755); |
| 150 | if (ret == -1) { | 155 | if (ret == -1) { |
| 151 | if (errno != EEXIST) { | 156 | if (errno != EEXIST) { |
| @@ -154,20 +159,32 @@ debug_cache_init(void) | |||
| 154 | } | 159 | } |
| 155 | } | 160 | } |
| 156 | 161 | ||
| 157 | snprintf(jit_path, PATH_MAX - 1, "%s/.debug/jit", base); | 162 | ret = snprintf(jit_path, PATH_MAX, "%s/.debug/jit", base); |
| 163 | if (ret >= PATH_MAX) { | ||
| 164 | warnx("jvmti: cannot generate jit cache dir because" | ||
| 165 | " %s/.debug/jit is too long, please check the cwd," | ||
| 166 | " JITDUMPDIR, and HOME variables", base); | ||
| 167 | return -1; | ||
| 168 | } | ||
| 158 | ret = mkdir(jit_path, 0755); | 169 | ret = mkdir(jit_path, 0755); |
| 159 | if (ret == -1) { | 170 | if (ret == -1) { |
| 160 | if (errno != EEXIST) { | 171 | if (errno != EEXIST) { |
| 161 | warn("cannot create jit cache dir %s", jit_path); | 172 | warn("jvmti: cannot create jit cache dir %s", jit_path); |
| 162 | return -1; | 173 | return -1; |
| 163 | } | 174 | } |
| 164 | } | 175 | } |
| 165 | 176 | ||
| 166 | snprintf(jit_path, PATH_MAX - 1, "%s/.debug/jit/%s.XXXXXXXX", base, str); | 177 | ret = snprintf(jit_path, PATH_MAX, "%s/.debug/jit/%s.XXXXXXXX", base, str); |
| 167 | 178 | if (ret >= PATH_MAX) { | |
| 179 | warnx("jvmti: cannot generate jit cache dir because" | ||
| 180 | " %s/.debug/jit/%s.XXXXXXXX is too long, please check" | ||
| 181 | " the cwd, JITDUMPDIR, and HOME variables", | ||
| 182 | base, str); | ||
| 183 | return -1; | ||
| 184 | } | ||
| 168 | p = mkdtemp(jit_path); | 185 | p = mkdtemp(jit_path); |
| 169 | if (p != jit_path) { | 186 | if (p != jit_path) { |
| 170 | warn("cannot create jit cache dir %s", jit_path); | 187 | warn("jvmti: cannot create jit cache dir %s", jit_path); |
| 171 | return -1; | 188 | return -1; |
| 172 | } | 189 | } |
| 173 | 190 | ||
| @@ -228,7 +245,7 @@ void *jvmti_open(void) | |||
| 228 | { | 245 | { |
| 229 | char dump_path[PATH_MAX]; | 246 | char dump_path[PATH_MAX]; |
| 230 | struct jitheader header; | 247 | struct jitheader header; |
| 231 | int fd; | 248 | int fd, ret; |
| 232 | FILE *fp; | 249 | FILE *fp; |
| 233 | 250 | ||
| 234 | init_arch_timestamp(); | 251 | init_arch_timestamp(); |
| @@ -245,12 +262,22 @@ void *jvmti_open(void) | |||
| 245 | 262 | ||
| 246 | memset(&header, 0, sizeof(header)); | 263 | memset(&header, 0, sizeof(header)); |
| 247 | 264 | ||
| 248 | debug_cache_init(); | 265 | /* |
| 266 | * jitdump file dir | ||
| 267 | */ | ||
| 268 | if (create_jit_cache_dir() < 0) | ||
| 269 | return NULL; | ||
| 249 | 270 | ||
| 250 | /* | 271 | /* |
| 251 | * jitdump file name | 272 | * jitdump file name |
| 252 | */ | 273 | */ |
| 253 | scnprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid()); | 274 | ret = snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid()); |
| 275 | if (ret >= PATH_MAX) { | ||
| 276 | warnx("jvmti: cannot generate jitdump file full path because" | ||
| 277 | " %s/jit-%i.dump is too long, please check the cwd," | ||
| 278 | " JITDUMPDIR, and HOME variables", jit_path, getpid()); | ||
| 279 | return NULL; | ||
| 280 | } | ||
| 254 | 281 | ||
| 255 | fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666); | 282 | fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666); |
| 256 | if (fd == -1) | 283 | if (fd == -1) |
