OR-Tools  8.2
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"
23
24namespace google {
25namespace logging_internal {
26
27const char* ProgramInvocationShortName();
28
30
32
34
36
37unsigned int GetTID();
38
39const 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.)
43const 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.
49template <typename T>
50inline 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
62void DumpStackTraceToString(std::string* stacktrace);
63
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
77void SetCrashReason(const CrashReason* r);
78
79void InitGoogleLoggingUtilities(const char* argv0);
81
82} // namespace logging_internal
83} // namespace google
84
85#endif // OR_TOOLS_BASE_LOGGING_UTILITIES_H_
int int32
int64_t int64
void DumpStackTraceToString(std::string *stacktrace)
T sync_val_compare_and_swap(T *ptr, T oldval, T newval)
void InitGoogleLoggingUtilities(const char *argv0)
const char * ProgramInvocationShortName()
const std::string & MyUserName()
void SetCrashReason(const CrashReason *r)
int64 UsecToCycles(int64 usec)
const char * const_basename(const char *filepath)