Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 1 | /*===- InstrProfilingFile.c - Write instrumentation to a file -------------===*\ |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 2 | |* |
| 3 | |* The LLVM Compiler Infrastructure |
| 4 | |* |
| 5 | |* This file is distributed under the University of Illinois Open Source |
| 6 | |* License. See LICENSE.TXT for details. |
| 7 | |* |
| 8 | \*===----------------------------------------------------------------------===*/ |
| 9 | |
| 10 | #include "InstrProfiling.h" |
Xinliang David Li | 1d8d46a | 2015-11-18 21:08:03 +0000 | [diff] [blame] | 11 | #include "InstrProfilingInternal.h" |
Xinliang David Li | 6e55716 | 2015-11-18 21:11:46 +0000 | [diff] [blame] | 12 | #include "InstrProfilingUtil.h" |
Joerg Sonnenberger | ef24b41 | 2015-03-09 11:23:29 +0000 | [diff] [blame] | 13 | #include <errno.h> |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <stdlib.h> |
Duncan P. N. Exon Smith | e5edc88 | 2014-03-21 00:27:48 +0000 | [diff] [blame] | 16 | #include <string.h> |
Xinliang David Li | 71eddbf | 2016-05-20 04:52:27 +0000 | [diff] [blame] | 17 | #ifdef _MSC_VER |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 18 | /* For _alloca. */ |
Xinliang David Li | 71eddbf | 2016-05-20 04:52:27 +0000 | [diff] [blame] | 19 | #include <malloc.h> |
Xinliang David Li | fb320a1 | 2016-05-20 05:40:07 +0000 | [diff] [blame] | 20 | #endif |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 21 | #if defined(_WIN32) |
| 22 | #include "WindowsMMap.h" |
| 23 | /* For _chsize_s */ |
| 24 | #include <io.h> |
| 25 | #else |
| 26 | #include <sys/file.h> |
| 27 | #include <sys/mman.h> |
| 28 | #include <unistd.h> |
| 29 | #if defined(__linux__) |
| 30 | #include <sys/types.h> |
| 31 | #endif |
| 32 | #endif |
Xinliang David Li | 71eddbf | 2016-05-20 04:52:27 +0000 | [diff] [blame] | 33 | |
Xinliang David Li | 153e8b6 | 2016-06-10 20:35:01 +0000 | [diff] [blame] | 34 | /* From where is profile name specified. |
| 35 | * The order the enumerators define their |
| 36 | * precedence. Re-order them may lead to |
| 37 | * runtime behavior change. */ |
| 38 | typedef enum ProfileNameSpecifier { |
| 39 | PNS_unknown = 0, |
| 40 | PNS_default, |
| 41 | PNS_command_line, |
| 42 | PNS_environment, |
| 43 | PNS_runtime_api |
| 44 | } ProfileNameSpecifier; |
| 45 | |
| 46 | static const char *getPNSStr(ProfileNameSpecifier PNS) { |
| 47 | switch (PNS) { |
| 48 | case PNS_default: |
| 49 | return "default setting"; |
| 50 | case PNS_command_line: |
| 51 | return "command line"; |
| 52 | case PNS_environment: |
| 53 | return "environment variable"; |
| 54 | case PNS_runtime_api: |
| 55 | return "runtime API"; |
| 56 | default: |
| 57 | return "Unknown"; |
| 58 | } |
| 59 | } |
| 60 | |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 61 | #define MAX_PID_SIZE 16 |
Ying Yi | 2c614cf | 2016-08-10 10:48:02 +0000 | [diff] [blame] | 62 | /* Data structure holding the result of parsed filename pattern. */ |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 63 | typedef struct lprofFilename { |
| 64 | /* File name string possibly with %p or %h specifiers. */ |
| 65 | const char *FilenamePat; |
Xinliang David Li | 14c91c4 | 2016-08-02 19:34:00 +0000 | [diff] [blame] | 66 | /* A flag indicating if FilenamePat's memory is allocated |
| 67 | * by runtime. */ |
| 68 | unsigned OwnsFilenamePat; |
Xinliang David Li | eaf238d | 2016-07-20 04:26:09 +0000 | [diff] [blame] | 69 | const char *ProfilePathPrefix; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 70 | char PidChars[MAX_PID_SIZE]; |
| 71 | char Hostname[COMPILER_RT_MAX_HOSTLEN]; |
| 72 | unsigned NumPids; |
| 73 | unsigned NumHosts; |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 74 | /* When in-process merging is enabled, this parameter specifies |
| 75 | * the total number of profile data files shared by all the processes |
| 76 | * spawned from the same binary. By default the value is 1. If merging |
| 77 | * is not enabled, its value should be 0. This parameter is specified |
| 78 | * by the %[0-9]m specifier. For instance %2m enables merging using |
| 79 | * 2 profile data files. %1m is equivalent to %m. Also %m specifier |
| 80 | * can only appear once at the end of the name pattern. */ |
| 81 | unsigned MergePoolSize; |
Xinliang David Li | 153e8b6 | 2016-06-10 20:35:01 +0000 | [diff] [blame] | 82 | ProfileNameSpecifier PNS; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 83 | } lprofFilename; |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 84 | |
Vedant Kumar | 6ff82bd | 2016-10-18 00:02:28 +0000 | [diff] [blame] | 85 | COMPILER_RT_WEAK lprofFilename lprofCurFilename = {0, 0, 0, {0}, {0}, |
| 86 | 0, 0, 0, PNS_unknown}; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 87 | |
| 88 | int getpid(void); |
| 89 | static int getCurFilenameLength(); |
| 90 | static const char *getCurFilename(char *FilenameBuf); |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 91 | static unsigned doMerging() { return lprofCurFilename.MergePoolSize; } |
Joerg Sonnenberger | b1cc6d5 | 2014-05-20 16:37:07 +0000 | [diff] [blame] | 92 | |
Xinliang David Li | 2d5bf07 | 2015-11-21 04:16:42 +0000 | [diff] [blame] | 93 | /* Return 1 if there is an error, otherwise return 0. */ |
| 94 | static uint32_t fileWriter(ProfDataIOVec *IOVecs, uint32_t NumIOVecs, |
| 95 | void **WriterCtx) { |
| 96 | uint32_t I; |
| 97 | FILE *File = (FILE *)*WriterCtx; |
| 98 | for (I = 0; I < NumIOVecs; I++) { |
| 99 | if (fwrite(IOVecs[I].Data, IOVecs[I].ElmSize, IOVecs[I].NumElm, File) != |
| 100 | IOVecs[I].NumElm) |
| 101 | return 1; |
| 102 | } |
| 103 | return 0; |
Xinliang David Li | 1d8d46a | 2015-11-18 21:08:03 +0000 | [diff] [blame] | 104 | } |
Duncan P. N. Exon Smith | cf4bb96 | 2014-03-21 18:29:19 +0000 | [diff] [blame] | 105 | |
Xinliang David Li | cda3bc2 | 2015-12-29 23:54:41 +0000 | [diff] [blame] | 106 | COMPILER_RT_VISIBILITY ProfBufferIO * |
Xinliang David Li | cf1a8d6 | 2016-03-06 04:18:13 +0000 | [diff] [blame] | 107 | lprofCreateBufferIOInternal(void *File, uint32_t BufferSz) { |
Xinliang David Li | 609fae3 | 2016-05-13 18:26:26 +0000 | [diff] [blame] | 108 | FreeHook = &free; |
| 109 | DynamicBufferIOBuffer = (uint8_t *)calloc(BufferSz, 1); |
| 110 | VPBufferSize = BufferSz; |
| 111 | return lprofCreateBufferIO(fileWriter, File); |
| 112 | } |
| 113 | |
| 114 | static void setupIOBuffer() { |
| 115 | const char *BufferSzStr = 0; |
| 116 | BufferSzStr = getenv("LLVM_VP_BUFFER_SIZE"); |
| 117 | if (BufferSzStr && BufferSzStr[0]) { |
| 118 | VPBufferSize = atoi(BufferSzStr); |
| 119 | DynamicBufferIOBuffer = (uint8_t *)calloc(VPBufferSize, 1); |
| 120 | } |
Xinliang David Li | cda3bc2 | 2015-12-29 23:54:41 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 123 | /* Read profile data in \c ProfileFile and merge with in-memory |
| 124 | profile counters. Returns -1 if there is fatal error, otheriwse |
| 125 | 0 is returned. |
| 126 | */ |
| 127 | static int doProfileMerging(FILE *ProfileFile) { |
| 128 | uint64_t ProfileFileSize; |
| 129 | char *ProfileBuffer; |
| 130 | |
| 131 | if (fseek(ProfileFile, 0L, SEEK_END) == -1) { |
| 132 | PROF_ERR("Unable to merge profile data, unable to get size: %s\n", |
| 133 | strerror(errno)); |
| 134 | return -1; |
| 135 | } |
| 136 | ProfileFileSize = ftell(ProfileFile); |
| 137 | |
| 138 | /* Restore file offset. */ |
| 139 | if (fseek(ProfileFile, 0L, SEEK_SET) == -1) { |
| 140 | PROF_ERR("Unable to merge profile data, unable to rewind: %s\n", |
| 141 | strerror(errno)); |
| 142 | return -1; |
| 143 | } |
| 144 | |
| 145 | /* Nothing to merge. */ |
| 146 | if (ProfileFileSize < sizeof(__llvm_profile_header)) { |
| 147 | if (ProfileFileSize) |
| 148 | PROF_WARN("Unable to merge profile data: %s\n", |
| 149 | "source profile file is too small."); |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | ProfileBuffer = mmap(NULL, ProfileFileSize, PROT_READ, MAP_SHARED | MAP_FILE, |
| 154 | fileno(ProfileFile), 0); |
| 155 | if (ProfileBuffer == MAP_FAILED) { |
| 156 | PROF_ERR("Unable to merge profile data, mmap failed: %s\n", |
| 157 | strerror(errno)); |
| 158 | return -1; |
| 159 | } |
| 160 | |
| 161 | if (__llvm_profile_check_compatibility(ProfileBuffer, ProfileFileSize)) { |
| 162 | (void)munmap(ProfileBuffer, ProfileFileSize); |
| 163 | PROF_WARN("Unable to merge profile data: %s\n", |
| 164 | "source profile file is not compatible."); |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | /* Now start merging */ |
| 169 | __llvm_profile_merge_from_buffer(ProfileBuffer, ProfileFileSize); |
| 170 | (void)munmap(ProfileBuffer, ProfileFileSize); |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | /* Open the profile data for merging. It opens the file in r+b mode with |
| 176 | * file locking. If the file has content which is compatible with the |
| 177 | * current process, it also reads in the profile data in the file and merge |
| 178 | * it with in-memory counters. After the profile data is merged in memory, |
| 179 | * the original profile data is truncated and gets ready for the profile |
| 180 | * dumper. With profile merging enabled, each executable as well as any of |
| 181 | * its instrumented shared libraries dump profile data into their own data file. |
| 182 | */ |
| 183 | static FILE *openFileForMerging(const char *ProfileFileName) { |
| 184 | FILE *ProfileFile; |
| 185 | int rc; |
| 186 | |
| 187 | ProfileFile = lprofOpenFileEx(ProfileFileName); |
| 188 | if (!ProfileFile) |
| 189 | return NULL; |
| 190 | |
| 191 | rc = doProfileMerging(ProfileFile); |
| 192 | if (rc || COMPILER_RT_FTRUNCATE(ProfileFile, 0L) || |
| 193 | fseek(ProfileFile, 0L, SEEK_SET) == -1) { |
| 194 | PROF_ERR("Profile Merging of file %s failed: %s\n", ProfileFileName, |
| 195 | strerror(errno)); |
| 196 | fclose(ProfileFile); |
| 197 | return NULL; |
| 198 | } |
| 199 | fseek(ProfileFile, 0L, SEEK_SET); |
| 200 | return ProfileFile; |
| 201 | } |
| 202 | |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 203 | /* Write profile data to file \c OutputName. */ |
| 204 | static int writeFile(const char *OutputName) { |
Duncan P. N. Exon Smith | 4543aac | 2014-03-21 00:27:50 +0000 | [diff] [blame] | 205 | int RetVal; |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 206 | FILE *OutputFile; |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 207 | |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 208 | if (!doMerging()) |
| 209 | OutputFile = fopen(OutputName, "ab"); |
| 210 | else |
| 211 | OutputFile = openFileForMerging(OutputName); |
| 212 | |
Duncan P. N. Exon Smith | 4543aac | 2014-03-21 00:27:50 +0000 | [diff] [blame] | 213 | if (!OutputFile) |
| 214 | return -1; |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 215 | |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 216 | FreeHook = &free; |
| 217 | setupIOBuffer(); |
| 218 | RetVal = lprofWriteData(fileWriter, OutputFile, lprofGetVPDataReader()); |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 219 | |
| 220 | fclose(OutputFile); |
Duncan P. N. Exon Smith | 4543aac | 2014-03-21 00:27:50 +0000 | [diff] [blame] | 221 | return RetVal; |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 224 | static void truncateCurrentFile(void) { |
Vasileios Kalintiris | c9c7a3e | 2015-02-25 13:50:18 +0000 | [diff] [blame] | 225 | const char *Filename; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 226 | char *FilenameBuf; |
Vasileios Kalintiris | c9c7a3e | 2015-02-25 13:50:18 +0000 | [diff] [blame] | 227 | FILE *File; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 228 | int Length; |
Vasileios Kalintiris | c9c7a3e | 2015-02-25 13:50:18 +0000 | [diff] [blame] | 229 | |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 230 | Length = getCurFilenameLength(); |
| 231 | FilenameBuf = (char *)COMPILER_RT_ALLOCA(Length + 1); |
| 232 | Filename = getCurFilename(FilenameBuf); |
| 233 | if (!Filename) |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 234 | return; |
| 235 | |
Diego Novillo | eae9514 | 2015-07-09 17:21:52 +0000 | [diff] [blame] | 236 | /* Create the directory holding the file, if needed. */ |
Xinliang David Li | b6d43b7 | 2016-07-19 20:48:00 +0000 | [diff] [blame] | 237 | if (lprofFindFirstDirSeparator(Filename)) { |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 238 | char *Copy = (char *)COMPILER_RT_ALLOCA(Length + 1); |
| 239 | strncpy(Copy, Filename, Length + 1); |
Diego Novillo | eae9514 | 2015-07-09 17:21:52 +0000 | [diff] [blame] | 240 | __llvm_profile_recursive_mkdir(Copy); |
| 241 | } |
| 242 | |
Xinliang David Li | e3fc4d0 | 2016-07-21 03:38:07 +0000 | [diff] [blame] | 243 | /* By pass file truncation to allow online raw profile |
| 244 | * merging. */ |
| 245 | if (lprofCurFilename.MergePoolSize) |
| 246 | return; |
| 247 | |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 248 | /* Truncate the file. Later we'll reopen and append. */ |
Vasileios Kalintiris | c9c7a3e | 2015-02-25 13:50:18 +0000 | [diff] [blame] | 249 | File = fopen(Filename, "w"); |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 250 | if (!File) |
| 251 | return; |
| 252 | fclose(File); |
| 253 | } |
| 254 | |
Xinliang David Li | 153e8b6 | 2016-06-10 20:35:01 +0000 | [diff] [blame] | 255 | static const char *DefaultProfileName = "default.profraw"; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 256 | static void resetFilenameToDefault(void) { |
Xinliang David Li | 14c91c4 | 2016-08-02 19:34:00 +0000 | [diff] [blame] | 257 | if (lprofCurFilename.FilenamePat && lprofCurFilename.OwnsFilenamePat) { |
| 258 | free((void *)lprofCurFilename.FilenamePat); |
| 259 | } |
Xinliang David Li | 7f08d12 | 2016-05-25 17:30:15 +0000 | [diff] [blame] | 260 | memset(&lprofCurFilename, 0, sizeof(lprofCurFilename)); |
Xinliang David Li | 153e8b6 | 2016-06-10 20:35:01 +0000 | [diff] [blame] | 261 | lprofCurFilename.FilenamePat = DefaultProfileName; |
| 262 | lprofCurFilename.PNS = PNS_default; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 263 | } |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 264 | |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 265 | static int containsMergeSpecifier(const char *FilenamePat, int I) { |
| 266 | return (FilenamePat[I] == 'm' || |
| 267 | (FilenamePat[I] >= '1' && FilenamePat[I] <= '9' && |
| 268 | /* If FilenamePat[I] is not '\0', the next byte is guaranteed |
| 269 | * to be in-bound as the string is null terminated. */ |
| 270 | FilenamePat[I + 1] == 'm')); |
| 271 | } |
Xinliang David Li | 7f08d12 | 2016-05-25 17:30:15 +0000 | [diff] [blame] | 272 | |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 273 | /* Parses the pattern string \p FilenamePat and stores the result to |
| 274 | * lprofcurFilename structure. */ |
Xinliang David Li | 14c91c4 | 2016-08-02 19:34:00 +0000 | [diff] [blame] | 275 | static int parseFilenamePattern(const char *FilenamePat, |
| 276 | unsigned CopyFilenamePat) { |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 277 | int NumPids = 0, NumHosts = 0, I; |
Xinliang David Li | 7f08d12 | 2016-05-25 17:30:15 +0000 | [diff] [blame] | 278 | char *PidChars = &lprofCurFilename.PidChars[0]; |
| 279 | char *Hostname = &lprofCurFilename.Hostname[0]; |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 280 | int MergingEnabled = 0; |
Vasileios Kalintiris | c9c7a3e | 2015-02-25 13:50:18 +0000 | [diff] [blame] | 281 | |
Xinliang David Li | b061cdb | 2016-07-20 05:10:56 +0000 | [diff] [blame] | 282 | /* Clean up cached prefix. */ |
| 283 | if (lprofCurFilename.ProfilePathPrefix) |
| 284 | free((void *)lprofCurFilename.ProfilePathPrefix); |
| 285 | memset(&lprofCurFilename, 0, sizeof(lprofCurFilename)); |
| 286 | |
Xinliang David Li | 14c91c4 | 2016-08-02 19:34:00 +0000 | [diff] [blame] | 287 | if (lprofCurFilename.FilenamePat && lprofCurFilename.OwnsFilenamePat) { |
| 288 | free((void *)lprofCurFilename.FilenamePat); |
| 289 | } |
| 290 | |
| 291 | if (!CopyFilenamePat) |
| 292 | lprofCurFilename.FilenamePat = FilenamePat; |
| 293 | else { |
| 294 | lprofCurFilename.FilenamePat = strdup(FilenamePat); |
| 295 | lprofCurFilename.OwnsFilenamePat = 1; |
| 296 | } |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 297 | /* Check the filename for "%p", which indicates a pid-substitution. */ |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 298 | for (I = 0; FilenamePat[I]; ++I) |
| 299 | if (FilenamePat[I] == '%') { |
| 300 | if (FilenamePat[++I] == 'p') { |
Vedant Kumar | a06e8ca | 2016-01-29 23:52:11 +0000 | [diff] [blame] | 301 | if (!NumPids++) { |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 302 | if (snprintf(PidChars, MAX_PID_SIZE, "%d", getpid()) <= 0) { |
Bob Haarman | 9ee65ac | 2016-11-29 15:24:00 +0000 | [diff] [blame] | 303 | PROF_WARN("Unable to get pid for filename pattern %s. Using the " |
| 304 | "default name.", |
| 305 | FilenamePat); |
Vedant Kumar | a06e8ca | 2016-01-29 23:52:11 +0000 | [diff] [blame] | 306 | return -1; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 307 | } |
Vedant Kumar | a06e8ca | 2016-01-29 23:52:11 +0000 | [diff] [blame] | 308 | } |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 309 | } else if (FilenamePat[I] == 'h') { |
Vedant Kumar | a06e8ca | 2016-01-29 23:52:11 +0000 | [diff] [blame] | 310 | if (!NumHosts++) |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 311 | if (COMPILER_RT_GETHOSTNAME(Hostname, COMPILER_RT_MAX_HOSTLEN)) { |
Bob Haarman | 9ee65ac | 2016-11-29 15:24:00 +0000 | [diff] [blame] | 312 | PROF_WARN("Unable to get hostname for filename pattern %s. Using " |
| 313 | "the default name.", |
| 314 | FilenamePat); |
Vedant Kumar | a06e8ca | 2016-01-29 23:52:11 +0000 | [diff] [blame] | 315 | return -1; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 316 | } |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 317 | } else if (containsMergeSpecifier(FilenamePat, I)) { |
| 318 | if (MergingEnabled) { |
Vedant Kumar | 8e2dd51 | 2016-06-14 17:23:13 +0000 | [diff] [blame] | 319 | PROF_WARN("%%m specifier can only be specified once in %s.\n", |
| 320 | FilenamePat); |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 321 | return -1; |
| 322 | } |
| 323 | MergingEnabled = 1; |
| 324 | if (FilenamePat[I] == 'm') |
| 325 | lprofCurFilename.MergePoolSize = 1; |
| 326 | else { |
| 327 | lprofCurFilename.MergePoolSize = FilenamePat[I] - '0'; |
| 328 | I++; /* advance to 'm' */ |
| 329 | } |
Duncan P. N. Exon Smith | e5edc88 | 2014-03-21 00:27:48 +0000 | [diff] [blame] | 330 | } |
Vedant Kumar | a06e8ca | 2016-01-29 23:52:11 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Xinliang David Li | 7f08d12 | 2016-05-25 17:30:15 +0000 | [diff] [blame] | 333 | lprofCurFilename.NumPids = NumPids; |
| 334 | lprofCurFilename.NumHosts = NumHosts; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 335 | return 0; |
| 336 | } |
| 337 | |
Xinliang David Li | 153e8b6 | 2016-06-10 20:35:01 +0000 | [diff] [blame] | 338 | static void parseAndSetFilename(const char *FilenamePat, |
Xinliang David Li | 14c91c4 | 2016-08-02 19:34:00 +0000 | [diff] [blame] | 339 | ProfileNameSpecifier PNS, |
| 340 | unsigned CopyFilenamePat) { |
Xinliang David Li | 7f08d12 | 2016-05-25 17:30:15 +0000 | [diff] [blame] | 341 | |
Xinliang David Li | 153e8b6 | 2016-06-10 20:35:01 +0000 | [diff] [blame] | 342 | const char *OldFilenamePat = lprofCurFilename.FilenamePat; |
| 343 | ProfileNameSpecifier OldPNS = lprofCurFilename.PNS; |
| 344 | |
| 345 | if (PNS < OldPNS) |
| 346 | return; |
| 347 | |
| 348 | if (!FilenamePat) |
| 349 | FilenamePat = DefaultProfileName; |
| 350 | |
Xinliang David Li | 153e8b6 | 2016-06-10 20:35:01 +0000 | [diff] [blame] | 351 | if (OldFilenamePat && !strcmp(OldFilenamePat, FilenamePat)) { |
| 352 | lprofCurFilename.PNS = PNS; |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | /* When PNS >= OldPNS, the last one wins. */ |
Xinliang David Li | 14c91c4 | 2016-08-02 19:34:00 +0000 | [diff] [blame] | 357 | if (!FilenamePat || parseFilenamePattern(FilenamePat, CopyFilenamePat)) |
Xinliang David Li | 7f08d12 | 2016-05-25 17:30:15 +0000 | [diff] [blame] | 358 | resetFilenameToDefault(); |
Xinliang David Li | 153e8b6 | 2016-06-10 20:35:01 +0000 | [diff] [blame] | 359 | lprofCurFilename.PNS = PNS; |
Xinliang David Li | 7f08d12 | 2016-05-25 17:30:15 +0000 | [diff] [blame] | 360 | |
Xinliang David Li | 153e8b6 | 2016-06-10 20:35:01 +0000 | [diff] [blame] | 361 | if (!OldFilenamePat) { |
Xinliang David Li | e68df59 | 2016-09-22 21:00:29 +0000 | [diff] [blame] | 362 | if (getenv("LLVM_PROFILE_VERBOSE")) |
| 363 | PROF_NOTE("Set profile file path to \"%s\" via %s.\n", |
| 364 | lprofCurFilename.FilenamePat, getPNSStr(PNS)); |
Xinliang David Li | 153e8b6 | 2016-06-10 20:35:01 +0000 | [diff] [blame] | 365 | } else { |
Xinliang David Li | e68df59 | 2016-09-22 21:00:29 +0000 | [diff] [blame] | 366 | if (getenv("LLVM_PROFILE_VERBOSE")) |
| 367 | PROF_NOTE("Override old profile path \"%s\" via %s to \"%s\" via %s.\n", |
| 368 | OldFilenamePat, getPNSStr(OldPNS), lprofCurFilename.FilenamePat, |
| 369 | getPNSStr(PNS)); |
Xinliang David Li | 153e8b6 | 2016-06-10 20:35:01 +0000 | [diff] [blame] | 370 | } |
Xinliang David Li | 7f08d12 | 2016-05-25 17:30:15 +0000 | [diff] [blame] | 371 | |
Xinliang David Li | e3fc4d0 | 2016-07-21 03:38:07 +0000 | [diff] [blame] | 372 | truncateCurrentFile(); |
Xinliang David Li | 7f08d12 | 2016-05-25 17:30:15 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 375 | /* Return buffer length that is required to store the current profile |
| 376 | * filename with PID and hostname substitutions. */ |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 377 | /* The length to hold uint64_t followed by 2 digit pool id including '_' */ |
| 378 | #define SIGLEN 24 |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 379 | static int getCurFilenameLength() { |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 380 | int Len; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 381 | if (!lprofCurFilename.FilenamePat || !lprofCurFilename.FilenamePat[0]) |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 382 | return 0; |
Duncan P. N. Exon Smith | e5edc88 | 2014-03-21 00:27:48 +0000 | [diff] [blame] | 383 | |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 384 | if (!(lprofCurFilename.NumPids || lprofCurFilename.NumHosts || |
| 385 | lprofCurFilename.MergePoolSize)) |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 386 | return strlen(lprofCurFilename.FilenamePat); |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 387 | |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 388 | Len = strlen(lprofCurFilename.FilenamePat) + |
| 389 | lprofCurFilename.NumPids * (strlen(lprofCurFilename.PidChars) - 2) + |
| 390 | lprofCurFilename.NumHosts * (strlen(lprofCurFilename.Hostname) - 2); |
| 391 | if (lprofCurFilename.MergePoolSize) |
| 392 | Len += SIGLEN; |
| 393 | return Len; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* Return the pointer to the current profile file name (after substituting |
| 397 | * PIDs and Hostnames in filename pattern. \p FilenameBuf is the buffer |
| 398 | * to store the resulting filename. If no substitution is needed, the |
| 399 | * current filename pattern string is directly returned. */ |
| 400 | static const char *getCurFilename(char *FilenameBuf) { |
| 401 | int I, J, PidLength, HostNameLength; |
| 402 | const char *FilenamePat = lprofCurFilename.FilenamePat; |
| 403 | |
| 404 | if (!lprofCurFilename.FilenamePat || !lprofCurFilename.FilenamePat[0]) |
| 405 | return 0; |
| 406 | |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 407 | if (!(lprofCurFilename.NumPids || lprofCurFilename.NumHosts || |
| 408 | lprofCurFilename.MergePoolSize)) |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 409 | return lprofCurFilename.FilenamePat; |
| 410 | |
| 411 | PidLength = strlen(lprofCurFilename.PidChars); |
| 412 | HostNameLength = strlen(lprofCurFilename.Hostname); |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 413 | /* Construct the new filename. */ |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 414 | for (I = 0, J = 0; FilenamePat[I]; ++I) |
| 415 | if (FilenamePat[I] == '%') { |
| 416 | if (FilenamePat[++I] == 'p') { |
| 417 | memcpy(FilenameBuf + J, lprofCurFilename.PidChars, PidLength); |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 418 | J += PidLength; |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 419 | } else if (FilenamePat[I] == 'h') { |
| 420 | memcpy(FilenameBuf + J, lprofCurFilename.Hostname, HostNameLength); |
Vedant Kumar | a06e8ca | 2016-01-29 23:52:11 +0000 | [diff] [blame] | 421 | J += HostNameLength; |
Xinliang David Li | e2ce2e0 | 2016-06-08 23:43:56 +0000 | [diff] [blame] | 422 | } else if (containsMergeSpecifier(FilenamePat, I)) { |
| 423 | char LoadModuleSignature[SIGLEN]; |
| 424 | int S; |
| 425 | int ProfilePoolId = getpid() % lprofCurFilename.MergePoolSize; |
| 426 | S = snprintf(LoadModuleSignature, SIGLEN, "%" PRIu64 "_%d", |
| 427 | lprofGetLoadModuleSignature(), ProfilePoolId); |
| 428 | if (S == -1 || S > SIGLEN) |
| 429 | S = SIGLEN; |
| 430 | memcpy(FilenameBuf + J, LoadModuleSignature, S); |
| 431 | J += S; |
| 432 | if (FilenamePat[I] != 'm') |
| 433 | I++; |
Vedant Kumar | a06e8ca | 2016-01-29 23:52:11 +0000 | [diff] [blame] | 434 | } |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 435 | /* Drop any unknown substitutions. */ |
| 436 | } else |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 437 | FilenameBuf[J++] = FilenamePat[I]; |
| 438 | FilenameBuf[J] = 0; |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 439 | |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 440 | return FilenameBuf; |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 443 | /* Returns the pointer to the environment variable |
| 444 | * string. Returns null if the env var is not set. */ |
| 445 | static const char *getFilenamePatFromEnv(void) { |
Eric Christopher | d641b53 | 2015-04-28 22:54:51 +0000 | [diff] [blame] | 446 | const char *Filename = getenv("LLVM_PROFILE_FILE"); |
Eric Christopher | d641b53 | 2015-04-28 22:54:51 +0000 | [diff] [blame] | 447 | if (!Filename || !Filename[0]) |
Xinliang David Li | 51fe002 | 2016-05-24 01:23:09 +0000 | [diff] [blame] | 448 | return 0; |
| 449 | return Filename; |
Eric Christopher | d641b53 | 2015-04-28 22:54:51 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Xinliang David Li | eaf238d | 2016-07-20 04:26:09 +0000 | [diff] [blame] | 452 | COMPILER_RT_VISIBILITY |
| 453 | const char *__llvm_profile_get_path_prefix(void) { |
| 454 | int Length; |
| 455 | char *FilenameBuf, *Prefix; |
| 456 | const char *Filename, *PrefixEnd; |
| 457 | |
| 458 | if (lprofCurFilename.ProfilePathPrefix) |
| 459 | return lprofCurFilename.ProfilePathPrefix; |
| 460 | |
| 461 | Length = getCurFilenameLength(); |
| 462 | FilenameBuf = (char *)COMPILER_RT_ALLOCA(Length + 1); |
| 463 | Filename = getCurFilename(FilenameBuf); |
| 464 | if (!Filename) |
| 465 | return "\0"; |
| 466 | |
| 467 | PrefixEnd = lprofFindLastDirSeparator(Filename); |
| 468 | if (!PrefixEnd) |
| 469 | return "\0"; |
| 470 | |
| 471 | Length = PrefixEnd - Filename + 1; |
| 472 | Prefix = (char *)malloc(Length + 1); |
| 473 | if (!Prefix) { |
| 474 | PROF_ERR("Failed to %s\n", "allocate memory."); |
| 475 | return "\0"; |
| 476 | } |
| 477 | memcpy(Prefix, Filename, Length); |
| 478 | Prefix[Length] = '\0'; |
| 479 | lprofCurFilename.ProfilePathPrefix = Prefix; |
| 480 | return Prefix; |
| 481 | } |
| 482 | |
Xinliang David Li | 51fe002 | 2016-05-24 01:23:09 +0000 | [diff] [blame] | 483 | /* This method is invoked by the runtime initialization hook |
| 484 | * InstrProfilingRuntime.o if it is linked in. Both user specified |
| 485 | * profile path via -fprofile-instr-generate= and LLVM_PROFILE_FILE |
| 486 | * environment variable can override this default value. */ |
Xinliang David Li | abfd553 | 2015-12-16 03:29:15 +0000 | [diff] [blame] | 487 | COMPILER_RT_VISIBILITY |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 488 | void __llvm_profile_initialize_file(void) { |
Xinliang David Li | e953933 | 2016-07-21 23:19:18 +0000 | [diff] [blame] | 489 | const char *EnvFilenamePat; |
| 490 | const char *SelectedPat = NULL; |
| 491 | ProfileNameSpecifier PNS = PNS_unknown; |
| 492 | int hasCommandLineOverrider = (INSTR_PROF_PROFILE_NAME_VAR[0] != 0); |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 493 | |
Xinliang David Li | e953933 | 2016-07-21 23:19:18 +0000 | [diff] [blame] | 494 | EnvFilenamePat = getFilenamePatFromEnv(); |
| 495 | if (EnvFilenamePat) { |
| 496 | SelectedPat = EnvFilenamePat; |
| 497 | PNS = PNS_environment; |
| 498 | } else if (hasCommandLineOverrider) { |
| 499 | SelectedPat = INSTR_PROF_PROFILE_NAME_VAR; |
| 500 | PNS = PNS_command_line; |
| 501 | } else { |
| 502 | SelectedPat = NULL; |
| 503 | PNS = PNS_default; |
| 504 | } |
| 505 | |
Xinliang David Li | 14c91c4 | 2016-08-02 19:34:00 +0000 | [diff] [blame] | 506 | parseAndSetFilename(SelectedPat, PNS, 0); |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Xinliang David Li | 51fe002 | 2016-05-24 01:23:09 +0000 | [diff] [blame] | 509 | /* This API is directly called by the user application code. It has the |
| 510 | * highest precedence compared with LLVM_PROFILE_FILE environment variable |
Xinliang David Li | 4151894 | 2016-05-24 02:37:07 +0000 | [diff] [blame] | 511 | * and command line option -fprofile-instr-generate=<profile_name>. |
Xinliang David Li | 51fe002 | 2016-05-24 01:23:09 +0000 | [diff] [blame] | 512 | */ |
Xinliang David Li | abfd553 | 2015-12-16 03:29:15 +0000 | [diff] [blame] | 513 | COMPILER_RT_VISIBILITY |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 514 | void __llvm_profile_set_filename(const char *FilenamePat) { |
Xinliang David Li | 14c91c4 | 2016-08-02 19:34:00 +0000 | [diff] [blame] | 515 | parseAndSetFilename(FilenamePat, PNS_runtime_api, 1); |
Eric Christopher | d641b53 | 2015-04-28 22:54:51 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 518 | /* The public API for writing profile data into the file with name |
| 519 | * set by previous calls to __llvm_profile_set_filename or |
| 520 | * __llvm_profile_override_default_filename or |
| 521 | * __llvm_profile_initialize_file. */ |
Xinliang David Li | abfd553 | 2015-12-16 03:29:15 +0000 | [diff] [blame] | 522 | COMPILER_RT_VISIBILITY |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 523 | int __llvm_profile_write_file(void) { |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 524 | int rc, Length; |
| 525 | const char *Filename; |
| 526 | char *FilenameBuf; |
Vasileios Kalintiris | c9c7a3e | 2015-02-25 13:50:18 +0000 | [diff] [blame] | 527 | |
Xinliang David Li | 3b2c002 | 2016-08-09 04:21:14 +0000 | [diff] [blame] | 528 | if (lprofProfileDumped()) { |
| 529 | PROF_NOTE("Profile data not written to file: %s.\n", |
| 530 | "already written"); |
| 531 | return 0; |
| 532 | } |
| 533 | |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 534 | Length = getCurFilenameLength(); |
| 535 | FilenameBuf = (char *)COMPILER_RT_ALLOCA(Length + 1); |
| 536 | Filename = getCurFilename(FilenameBuf); |
| 537 | |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 538 | /* Check the filename. */ |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 539 | if (!Filename) { |
Xinliang David Li | 690c31f | 2016-05-20 05:15:42 +0000 | [diff] [blame] | 540 | PROF_ERR("Failed to write file : %s\n", "Filename not set"); |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 541 | return -1; |
Xinliang David Li | 9ea3064 | 2015-12-03 18:31:59 +0000 | [diff] [blame] | 542 | } |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 543 | |
Xinliang David Li | d85c32c | 2016-01-08 23:42:28 +0000 | [diff] [blame] | 544 | /* Check if there is llvm/runtime version mismatch. */ |
Xinliang David Li | a692421 | 2016-01-08 23:31:57 +0000 | [diff] [blame] | 545 | if (GET_VERSION(__llvm_profile_get_version()) != INSTR_PROF_RAW_VERSION) { |
Xinliang David Li | 690c31f | 2016-05-20 05:15:42 +0000 | [diff] [blame] | 546 | PROF_ERR("Runtime and instrumentation version mismatch : " |
Xinliang David Li | a692421 | 2016-01-08 23:31:57 +0000 | [diff] [blame] | 547 | "expected %d, but get %d\n", |
| 548 | INSTR_PROF_RAW_VERSION, |
| 549 | (int)GET_VERSION(__llvm_profile_get_version())); |
| 550 | return -1; |
| 551 | } |
| 552 | |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 553 | /* Write profile data to the file. */ |
| 554 | rc = writeFile(Filename); |
Xinliang David Li | 9ea3064 | 2015-12-03 18:31:59 +0000 | [diff] [blame] | 555 | if (rc) |
Xinliang David Li | 315e49d | 2016-05-24 21:29:18 +0000 | [diff] [blame] | 556 | PROF_ERR("Failed to write file \"%s\": %s\n", Filename, strerror(errno)); |
Justin Bogner | 66fd5c9 | 2015-01-16 20:10:56 +0000 | [diff] [blame] | 557 | return rc; |
Duncan P. N. Exon Smith | 54cc0e2 | 2014-03-20 19:23:55 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Xinliang David Li | 3b2c002 | 2016-08-09 04:21:14 +0000 | [diff] [blame] | 560 | COMPILER_RT_VISIBILITY |
| 561 | int __llvm_profile_dump(void) { |
| 562 | if (!doMerging()) |
| 563 | PROF_WARN("Later invocation of __llvm_profile_dump can lead to clobbering " |
Nico Weber | 81291a0 | 2016-09-08 01:46:52 +0000 | [diff] [blame] | 564 | " of previously dumped profile data : %s. Either use %%m " |
Xinliang David Li | 3b2c002 | 2016-08-09 04:21:14 +0000 | [diff] [blame] | 565 | "in profile name or change profile name before dumping.\n", |
| 566 | "online profile merging is not on"); |
| 567 | int rc = __llvm_profile_write_file(); |
| 568 | lprofSetProfileDumped(); |
| 569 | return rc; |
| 570 | } |
| 571 | |
Xinliang David Li | 6fe18f4 | 2015-11-23 04:38:17 +0000 | [diff] [blame] | 572 | static void writeFileWithoutReturn(void) { __llvm_profile_write_file(); } |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 573 | |
Xinliang David Li | abfd553 | 2015-12-16 03:29:15 +0000 | [diff] [blame] | 574 | COMPILER_RT_VISIBILITY |
Duncan P. N. Exon Smith | 55e4d66 | 2014-05-17 01:27:30 +0000 | [diff] [blame] | 575 | int __llvm_profile_register_write_file_atexit(void) { |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 576 | static int HasBeenRegistered = 0; |
| 577 | |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 578 | if (HasBeenRegistered) |
| 579 | return 0; |
| 580 | |
Xinliang David Li | 4617aa7 | 2016-05-18 22:34:05 +0000 | [diff] [blame] | 581 | lprofSetupValueProfiler(); |
| 582 | |
Duncan P. N. Exon Smith | be0a5e1 | 2014-03-21 18:29:15 +0000 | [diff] [blame] | 583 | HasBeenRegistered = 1; |
| 584 | return atexit(writeFileWithoutReturn); |
Duncan P. N. Exon Smith | 8353a26 | 2014-03-19 22:10:27 +0000 | [diff] [blame] | 585 | } |