blob: 5f9c4f2e388a396f3613aacb871fbb7c6ce699f1 [file] [log] [blame]
Chris Lattnera9a30282003-10-28 18:56:51 +00001/*===-- FunctionProfiling.c - Support library for function profiling ------===*\
2|*
3|* The LLVM Compiler Infrastructure
4|*
5|* This file was developed by the LLVM research group and is distributed under
6|* the University of Illinois Open Source License. See LICENSE.TXT for details.
7|*
8|*===----------------------------------------------------------------------===*|
9|*
10|* This file implements the call back routines for the function profiling
11|* instrumentation pass. This should be used with the
12|* -insert-function-profiling LLVM pass.
13|*
14\*===----------------------------------------------------------------------===*/
15
16#include "Profiling.h"
17#include <stdlib.h>
18
19static unsigned *ArrayStart;
20static unsigned NumElements;
21
22/* FuncProfAtExitHandler - When the program exits, just write out the profiling
23 * data.
24 */
25static void FuncProfAtExitHandler() {
26 /* Just write out the data we collected.
27 */
28 write_profiling_data(Function, ArrayStart, NumElements);
29}
30
31
32/* llvm_start_func_profiling - This is the main entry point of the function
33 * profiling library. It is responsible for setting up the atexit handler.
34 */
Chris Lattneraffce4f2004-02-10 17:36:25 +000035int llvm_start_func_profiling(int argc, const char **argv,
36 unsigned *arrayStart, unsigned numElements) {
37 int Ret = save_arguments(argc, argv);
Chris Lattnera9a30282003-10-28 18:56:51 +000038 ArrayStart = arrayStart;
39 NumElements = numElements;
40 atexit(FuncProfAtExitHandler);
Chris Lattneraffce4f2004-02-10 17:36:25 +000041 return Ret;
Chris Lattnera9a30282003-10-28 18:56:51 +000042}