diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2011-04-16 01:20:23 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2011-04-16 01:20:23 +0000 |
commit | b1928704201034c785a26296a49f69355eb56a05 (patch) | |
tree | 6cb5f9d9c717c85a5e9ccb6ada1a9c2a103e192c /runtime | |
parent | e9db5e29e3af91eec572bfeb8dcec908213298b0 (diff) | |
download | external_llvm-b1928704201034c785a26296a49f69355eb56a05.zip external_llvm-b1928704201034c785a26296a49f69355eb56a05.tar.gz external_llvm-b1928704201034c785a26296a49f69355eb56a05.tar.bz2 |
Rename LineProfiling to GCOVProfiling to more accurately represent what it
does. Also mostly implement it. Still a work-in-progress, but generates legal
output on crafted test cases.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129630 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/libprofile/GCDAProfiling.c | 104 | ||||
-rw-r--r-- | runtime/libprofile/LineProfiling.c | 40 | ||||
-rw-r--r-- | runtime/libprofile/libprofile.exports | 7 |
3 files changed, 108 insertions, 43 deletions
diff --git a/runtime/libprofile/GCDAProfiling.c b/runtime/libprofile/GCDAProfiling.c new file mode 100644 index 0000000..ee48ab5 --- /dev/null +++ b/runtime/libprofile/GCDAProfiling.c @@ -0,0 +1,104 @@ +/*===- GCDAProfiling.c - Support library for GCDA file emission -----------===*\ +|* +|* The LLVM Compiler Infrastructure +|* +|* This file is distributed under the University of Illinois Open Source +|* License. See LICENSE.TXT for details. +|* +|*===----------------------------------------------------------------------===*| +|* +|* This file implements the call back routines for the gcov profiling +|* instrumentation pass. Link against this library when running code through +|* the -insert-gcov-profiling LLVM pass. +|* +|* We emit files in a corrupt version of GCOV's "gcda" file format. These files +|* are only close enough that LCOV will happily parse them. Anything that lcov +|* ignores is missing. +|* +\*===----------------------------------------------------------------------===*/ + +#include "llvm/Support/DataTypes.h" +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +// #define DEBUG_GCDAPROFILING + +/* + * --- GCOV file format I/O primitives --- + */ + +static FILE *output_file = NULL; + +static void write_int32(uint32_t i) { + fwrite(&i, 4, 1, output_file); +} + +static void write_int64(uint64_t i) { + uint32_t lo, hi; + lo = i & 0x00000000ffffffff; + hi = i & 0xffffffff00000000; + + write_int32(lo); + write_int32(hi); +} + +/* + * --- LLVM line counter API --- + */ + +/* A file in this case is a translation unit. Each .o file built with line + * profiling enabled will emit to a different file. Only one file may be + * started at a time. + */ +void llvm_gcda_start_file(const char *filename) { + output_file = fopen(filename, "w+"); + + /* gcda file, version 404*, stamp LLVM. */ + fwrite("adcg*404MVLL", 12, 1, output_file); + +#ifdef DEBUG_GCDAPROFILING + printf("[%s]\n", filename); +#endif +} + +void llvm_gcda_emit_function(uint32_t ident) { +#ifdef DEBUG_GCDAPROFILING + printf("function id=%x\n", ident); +#endif + + /* function tag */ + fwrite("\0\0\0\1", 4, 1, output_file); + write_int32(2); + write_int32(ident); + write_int32(0); +} + +void llvm_gcda_emit_arcs(uint32_t num_counters, uint64_t *counters) { + uint32_t i; + /* counter #1 (arcs) tag */ + fwrite("\0\0\xa1\1", 4, 1, output_file); + write_int32(num_counters * 2); + for (i = 0; i < num_counters; ++i) { + write_int64(counters[i]); + } + +#ifdef DEBUG_GCDAPROFILING + printf(" %u arcs\n", num_counters); + for (i = 0; i < num_counters; ++i) { + printf(" %llu\n", (unsigned long long)counters[i]); + } +#endif +} + +void llvm_gcda_end_file() { + /* Write out EOF record. */ + fwrite("\0\0\0\0\0\0\0\0", 8, 1, output_file); + fclose(output_file); + output_file = NULL; + +#ifdef DEBUG_GCDAPROFILING + printf("-----\n"); +#endif +} diff --git a/runtime/libprofile/LineProfiling.c b/runtime/libprofile/LineProfiling.c deleted file mode 100644 index 9db789e..0000000 --- a/runtime/libprofile/LineProfiling.c +++ /dev/null @@ -1,40 +0,0 @@ -/*===- LineProfiling.c - Support library for line profiling ---------------===*\ -|* -|* The LLVM Compiler Infrastructure -|* -|* This file is distributed under the University of Illinois Open Source -|* License. See LICENSE.TXT for details. -|* -|*===----------------------------------------------------------------------===*| -|* -|* This file implements the call back routines for the line profiling -|* instrumentation pass. Link against this library when running code through -|* the -insert-line-profiling LLVM pass. -|* -\*===----------------------------------------------------------------------===*/ - -#include <stdlib.h> -#include <stdio.h> -#include <stdint.h> - -#include "llvm/Support/DataTypes.h" - -/* A file in this case is a translation unit. Each .o file built with line - * profiling enabled will emit to a different file. Only one file may be - * started at a time. - */ -void llvm_prof_linectr_start_file(const char *orig_filename) { - printf("[%s]\n", orig_filename); -} - -/* Emit data about a counter to the data file. */ -void llvm_prof_linectr_emit_counter(const char *dir, const char *file, - uint32_t line, uint32_t column, - uint64_t *counter) { - printf("%s/%s:%u:%u %llu\n", dir, file, line, column, - (unsigned long long)(*counter)); -} - -void llvm_prof_linectr_end_file() { - printf("-----\n"); -} diff --git a/runtime/libprofile/libprofile.exports b/runtime/libprofile/libprofile.exports index fb04ea3..aca563f 100644 --- a/runtime/libprofile/libprofile.exports +++ b/runtime/libprofile/libprofile.exports @@ -5,6 +5,7 @@ llvm_start_basic_block_tracing llvm_trace_basic_block llvm_increment_path_count llvm_decrement_path_count -llvm_prof_linectr_start_file -llvm_prof_linectr_emit_counter -llvm_prof_linectr_end_file +llvm_gcda_start_file +llvm_gcda_emit_function +llvm_gcda_emit_arcs +llvm_gcda_end_file |