summaryrefslogtreecommitdiffstats
path: root/runtime/libprofile/GCDAProfiling.c
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/libprofile/GCDAProfiling.c')
-rw-r--r--runtime/libprofile/GCDAProfiling.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/runtime/libprofile/GCDAProfiling.c b/runtime/libprofile/GCDAProfiling.c
index 2dcf22d..09a1aec 100644
--- a/runtime/libprofile/GCDAProfiling.c
+++ b/runtime/libprofile/GCDAProfiling.c
@@ -24,6 +24,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#ifdef _MSC_VER
+#include <direct.h>
+#endif
/* #define DEBUG_GCDAPROFILING */
@@ -46,6 +51,17 @@ static void write_int64(uint64_t i) {
write_int32(hi);
}
+static uint32_t length_of_string(const char *s) {
+ return (strlen(s) / 4) + 1;
+}
+
+static void write_string(const char *s) {
+ uint32_t len = length_of_string(s);
+ write_int32(len);
+ fwrite(s, strlen(s), 1, output_file);
+ fwrite("\0\0\0\0", 4 - (strlen(s) % 4), 1, output_file);
+}
+
static char *mangle_filename(const char *orig_filename) {
/* TODO: handle GCOV_PREFIX_STRIP */
const char *prefix;
@@ -54,7 +70,7 @@ static char *mangle_filename(const char *orig_filename) {
prefix = getenv("GCOV_PREFIX");
if (!prefix)
- return strdup(filename);
+ return strdup(orig_filename);
filename = malloc(strlen(prefix) + 1 + strlen(orig_filename) + 1);
strcpy(filename, prefix);
@@ -64,6 +80,25 @@ static char *mangle_filename(const char *orig_filename) {
return filename;
}
+static void recursive_mkdir(const char *filename) {
+ char *pathname;
+ int i, e;
+
+ for (i = 1, e = strlen(filename); i != e; ++i) {
+ if (filename[i] == '/') {
+ pathname = malloc(i + 1);
+ strncpy(pathname, filename, i);
+ pathname[i] = '\0';
+#ifdef _MSC_VER
+ _mkdir(pathname);
+#else
+ mkdir(pathname, 0750); /* some of these will fail, ignore it. */
+#endif
+ free(pathname);
+ }
+ }
+}
+
/*
* --- LLVM line counter API ---
*/
@@ -75,6 +110,7 @@ static char *mangle_filename(const char *orig_filename) {
void llvm_gcda_start_file(const char *orig_filename) {
char *filename;
filename = mangle_filename(orig_filename);
+ recursive_mkdir(filename);
output_file = fopen(filename, "wb");
/* gcda file, version 404*, stamp LLVM. */
@@ -111,16 +147,18 @@ void llvm_gcda_increment_indirect_counter(uint32_t *predecessor,
#endif
}
-void llvm_gcda_emit_function(uint32_t ident) {
+void llvm_gcda_emit_function(uint32_t ident, const char *function_name) {
#ifdef DEBUG_GCDAPROFILING
printf("llvmgcda: function id=%x\n", ident);
#endif
/* function tag */
fwrite("\0\0\0\1", 4, 1, output_file);
- write_int32(2);
+ write_int32(3 + 1 + length_of_string(function_name));
write_int32(ident);
write_int32(0);
+ write_int32(0);
+ write_string(function_name);
}
void llvm_gcda_emit_arcs(uint32_t num_counters, uint64_t *counters) {
OpenPOWER on IntegriCloud