OR-Tools  8.1
logging_utilities.h
Go to the documentation of this file.
1 // Copyright 2010-2018 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #ifndef OR_TOOLS_BASE_LOGGING_UTILITIES_H_
15 #define OR_TOOLS_BASE_LOGGING_UTILITIES_H_
16 
17 #include <string>
18 
19 #include "absl/base/internal/sysinfo.h" // for GetTID().
20 #include "absl/base/macros.h"
21 #include "absl/synchronization/mutex.h"
22 #include "ortools/base/logging.h"
23 
24 namespace google {
25 namespace logging_internal {
26 
27 const char* ProgramInvocationShortName();
28 
30 
32 
34 
36 
37 unsigned int GetTID();
38 
39 const std::string& MyUserName();
40 
41 // Get the part of filepath after the last path separator.
42 // (Doesn't modify filepath, contrary to basename() in libgen.h.)
43 const char* const_basename(const char* filepath);
44 
45 // Wrapper of __sync_val_compare_and_swap. If the GCC extension isn't
46 // defined, we try the CPU specific logics (we only support x86 and
47 // x86_64 for now) first, then use a naive implementation, which has a
48 // race condition.
49 template <typename T>
50 inline T sync_val_compare_and_swap(T* ptr, T oldval, T newval) {
51 #if defined(__GNUC__)
52  return __sync_val_compare_and_swap(ptr, oldval, newval);
53 #else
54  T ret = *ptr;
55  if (ret == oldval) {
56  *ptr = newval;
57  }
58  return ret;
59 #endif
60 }
61 
62 void DumpStackTraceToString(std::string* stacktrace);
63 
64 struct CrashReason {
66 
67  const char* filename;
69  const char* message;
70 
71  // We'll also store a bit of stack trace context at the time of crash as
72  // it may not be available later on.
73  void* stack[32];
74  int depth;
75 };
76 
77 void SetCrashReason(const CrashReason* r);
78 
79 void InitGoogleLoggingUtilities(const char* argv0);
81 
82 } // namespace logging_internal
83 } // namespace google
84 
85 #endif // OR_TOOLS_BASE_LOGGING_UTILITIES_H_
google::logging_internal::CrashReason::filename
const char * filename
Definition: logging_utilities.h:67
google::logging_internal::IsGoogleLoggingInitialized
bool IsGoogleLoggingInitialized()
Definition: logging_utilities.cc:223
google::logging_internal::CrashReason::message
const char * message
Definition: logging_utilities.h:69
logging.h
google::logging_internal::ProgramInvocationShortName
const char * ProgramInvocationShortName()
Definition: logging_utilities.cc:214
google::logging_internal::sync_val_compare_and_swap
T sync_val_compare_and_swap(T *ptr, T oldval, T newval)
Definition: logging_utilities.h:50
int64
int64_t int64
Definition: integral_types.h:34
int32
int int32
Definition: integral_types.h:33
google::logging_internal::GetMainThreadPid
int32 GetMainThreadPid()
Definition: logging_utilities.cc:236
google::logging_internal::MyUserName
const std::string & MyUserName()
Definition: logging_utilities.cc:247
google::logging_internal::GetTID
unsigned int GetTID()
Definition: logging_utilities.cc:227
google::logging_internal::SetCrashReason
void SetCrashReason(const CrashReason *r)
Definition: logging_utilities.cc:299
google::logging_internal::CrashReason::line_number
int line_number
Definition: logging_utilities.h:68
google::logging_internal::CycleClock_Now
int64 CycleClock_Now()
Definition: logging_utilities.cc:231
google::logging_internal::CrashReason::stack
void * stack[32]
Definition: logging_utilities.h:73
google::logging_internal::DumpStackTraceToString
void DumpStackTraceToString(std::string *stacktrace)
Definition: logging_utilities.cc:291
google::logging_internal::CrashReason::depth
int depth
Definition: logging_utilities.h:74
google::logging_internal::ShutdownGoogleLoggingUtilities
void ShutdownGoogleLoggingUtilities()
Definition: logging_utilities.cc:317
google::logging_internal::const_basename
const char * const_basename(const char *filepath)
Definition: logging_utilities.cc:238
google::logging_internal::UsecToCycles
int64 UsecToCycles(int64 usec)
Definition: logging_utilities.cc:233
google
Definition: log_severity.h:24
google::logging_internal::InitGoogleLoggingUtilities
void InitGoogleLoggingUtilities(const char *argv0)
Definition: logging_utilities.cc:304
google::logging_internal::CrashReason::CrashReason
CrashReason()
Definition: logging_utilities.h:65
google::logging_internal::CrashReason
Definition: logging_utilities.h:64