FARGOS/VISTA Object Management Environment Core  ..
FARGOS/VISTA Object Management Environment Core Table of Contents
flush_profilers.h
Go to the documentation of this file.
1 #ifndef _FLUSH_PROFILERS_H_
2 #define _FLUSH_PROFILERS_H_ "$Id: flush_profilers.h 316 2020-03-26 16:18:40Z geoff $"
4 
6 #ifndef _WIN32
7 #include <stdio.h>
8 #include <unistd.h>
9 #include <dlfcn.h>
10 
30 inline void flushProfilingBuffers(int forceExit) {
31  typedef void (*voidFuncCallFP)();
32 
33  void *dlHandle = dlopen(0, RTLD_LAZY);
34  /* Based on implementation in gcc-V.N.x/libgcc/config/arc/gmon/gcmon.c:
35  * _mcleanup() would be the normal routine, but it disables profiling,
36  * writes the data and frees buffers.
37  * __write_profiling() just writes current image if profiling was
38  * enabled and doesn't change any state.
39  */
40  void *monitorCleanup = dlsym(dlHandle, "__write_profiling");
41  if (monitorCleanup != 0) {
42  voidFuncCallFP rout = (voidFuncCallFP) monitorCleanup;
43  (*rout)();
44  } else {
45  fprintf(stderr, "no __write_profiling symbol located\n");
46  /* try _mcleanup() as fallback, but it can only be called once */
47  static bool didCleanup = false;
48  if (didCleanup == false) { /* never called */
49  monitorCleanup = dlsym(dlHandle, "_mcleanup");
50  if (monitorCleanup != 0) {
51  voidFuncCallFP rout = (voidFuncCallFP) monitorCleanup;
52  didCleanup = true; /* don't call this again */
53  (*rout)();
54  } else {
55  fprintf(stderr, "no _mcleanup symbol located\n");
56  }
57  }
58  }
59 
60  void *gcovFlush = dlsym(dlHandle, "__gcov_flush");
61  if (gcovFlush != 0) {
62  voidFuncCallFP rout = (voidFuncCallFP) gcovFlush;
63  (*rout)();
64  } else {
65  fprintf(stderr, "no __gcov_flush symbol located\n");
66  }
67  dlclose(dlHandle);
68  switch (forceExit) {
69  case 1:
70  _exit(1);
71  break;
72  case 2:
73  exit(1);
74  break;
75  default:
76  break;
77  }
78 }
79 
82 #define FLUSH_PROFILING_BUFFERS(forceExit) flushProfilingBuffers(forceExit)
83 
84 #else
85 // Win32 doesn't support profiling
86 // The _exit() semantics might be more closely achieved by TerminateProcess()
87 #define FLUSH_PROFILING_BUFFERS(forceExit) do { \
88  if (forceExit == 1) TerminateProcess(GetCurrentProcess(), 1); \
89  if (forceExit == 2) ExitProcess(1); \
90 } while (0)
91 
92 #endif
93 
94 #endif
95 
96 /* vim: set expandtab shiftwidth=4 tabstop=4: */
stderr
#define stderr
Definition: tmp.o.cpp:3115
flushProfilingBuffers
void flushProfilingBuffers(int forceExit)
Flush profiling buffers - POSIX-specific.
Definition: flush_profilers.h:30
Generated: Tue Jul 28 2020 16:03:25
Support Information