blob: 9698599606e071e9472b20953e051de0783e684a [file] [log] [blame]
Diego Novilloeae95142015-07-09 17:21:52 +00001/*===- InstrProfilingUtil.h - Support library for PGO instrumentation -----===*\
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#ifndef PROFILE_INSTRPROFILINGUTIL_H
11#define PROFILE_INSTRPROFILINGUTIL_H
12
Sean Silva6470f762016-03-02 22:05:46 +000013#include <stddef.h>
Xinliang David Li5cd1f942016-06-06 03:17:58 +000014#include <stdio.h>
Sean Silva6470f762016-03-02 22:05:46 +000015
Diego Novilloeae95142015-07-09 17:21:52 +000016/*! \brief Create a directory tree. */
17void __llvm_profile_recursive_mkdir(char *Pathname);
18
Xinliang David Li5cd1f942016-06-06 03:17:58 +000019/*! Open file \c Filename for read+write with write
20 * lock for exclusive access. The caller will block
21 * if the lock is already held by another process. */
22FILE *lprofOpenFileEx(const char *Filename);
Sean Silva6470f762016-03-02 22:05:46 +000023/* PS4 doesn't have getenv. Define a shim. */
Paul Robinson595b9692016-05-16 17:22:32 +000024#if __ORBIS__
Sean Silva6470f762016-03-02 22:05:46 +000025static inline char *getenv(const char *name) { return NULL; }
Paul Robinson595b9692016-05-16 17:22:32 +000026#endif /* #if __ORBIS__ */
Sean Silva6470f762016-03-02 22:05:46 +000027
Xinliang David Lid4c5e272016-07-19 20:31:46 +000028/* GCOV_PREFIX and GCOV_PREFIX_STRIP support */
29/* Return the path prefix specified by GCOV_PREFIX environment variable.
30 * If GCOV_PREFIX_STRIP is also specified, the strip level (integer value)
31 * is returned via \c *PrefixStrip. The prefix length is stored in *PrefixLen.
32 */
33const char *lprofGetPathPrefix(int *PrefixStrip, size_t *PrefixLen);
34/* Apply the path prefix specified in \c Prefix to path string in \c PathStr,
35 * and store the result to buffer pointed to by \c Buffer. If \c PrefixStrip
36 * is not zero, path prefixes are stripped from \c PathStr (the level of
37 * stripping is specified by \c PrefixStrip) before \c Prefix is added.
38 */
39void lprofApplyPathPrefix(char *Dest, const char *PathStr, const char *Prefix,
40 size_t PrefixLen, int PrefixStrip);
41
Xinliang David Lib6d43b72016-07-19 20:48:00 +000042/* Returns a pointer to the first occurrence of \c DIR_SEPARATOR char in
43 * the string \c Path, or NULL if the char is not found. */
44const char *lprofFindFirstDirSeparator(const char *Path);
45/* Returns a pointer to the last occurrence of \c DIR_SEPARATOR char in
46 * the string \c Path, or NULL if the char is not found. */
47const char *lprofFindLastDirSeparator(const char *Path);
48
Xinliang David Li44fd3882016-03-06 04:52:45 +000049int lprofGetHostName(char *Name, int Len);
50
Filipe Cabecinhas19aeaf72016-03-07 13:42:17 +000051unsigned lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV);
Xinliang David Li21d38c52016-05-16 23:01:03 +000052void *lprofPtrFetchAdd(void **Mem, long ByteIncr);
Xinliang David Licf2f8292016-03-06 00:55:20 +000053
Rong Xucf1f6fb2017-03-17 18:41:33 +000054/* Temporarily suspend SIGKILL. Return value of 1 means a restore is needed.
55 * Other return values mean no restore is needed.
56 */
57int lprofSuspendSigKill();
58
59/* Restore previously suspended SIGKILL. */
60void lprofRestoreSigKill();
61
Xinliang David Li21d38c52016-05-16 23:01:03 +000062#endif /* PROFILE_INSTRPROFILINGUTIL_H */