Skip to content

Commit

Permalink
fix: wrong incremental_marking_duration_last_record value
Browse files Browse the repository at this point in the history
PR-URL: #182
  • Loading branch information
hyj1991 committed Jun 10, 2022
1 parent b2acf60 commit 9e9349b
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 64 deletions.
96 changes: 94 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
BSD 2-Clause License

Copyright (c) 2019, hyj1991
All rights reserved.
xprofiler is licensed for use as follows:

"""
Copyright xprofiler contributors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand All @@ -23,3 +25,93 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

The xprofiler license applies to all parts of xprofiler that are not externally
maintained libraries.

The externally maintained libraries used by xprofiler are:

- [nlohmann/json](https://github.com/nlohmann/json/blob/develop/LICENSE.MIT), located at src/library/json.hpp, is licensed as follows:
"""
MIT License

Copyright (c) 2013-2022 Niels Lohmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

- [Percona-Lab/coredumper](https://github.com/Percona-Lab/coredumper), located at src/platform/unix/core/linux/, is licensed as follows:
"""
Copyright (c) 2005-2007, Google Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

- [Node.js](https://github.com/nodejs/node), located at:
- src/library/printf-inl.h
- src/library/printf.h
- src/library/writer.cc
- src/library/writer.h
is licensed as follows:
"""
Copyright Node.js contributors. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
"""
5 changes: 3 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"conditions": [
["OS == 'linux'", {
"cflags": [
"-O2",
"-O3",
"-std=c++14",
"-Wno-sign-compare",
"-Wno-cast-function-type",
Expand All @@ -78,6 +78,7 @@
["OS == 'mac'", {
"xcode_settings": {
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
"GCC_OPTIMIZATION_LEVEL": "3",
"OTHER_CFLAGS": [
"-std=c++14",
"-Wconversion",
Expand All @@ -101,7 +102,7 @@
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": "2",
"Optimization": "2",
"Optimization": "3",
},
},
"defines": [
Expand Down
116 changes: 116 additions & 0 deletions src/library/printf-inl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#ifndef XPROFILER_SRC_LIBRARY_PRINT_INL_H
#define XPROFILER_SRC_LIBRARY_PRINT_INL_H
#include "printf.h"
#include "util.h"

namespace xprofiler {
struct ToStringHelper {
template <typename T>
static std::string Convert(const T& value, std::string (T::*to_string)()
const = &T::ToString) {
return (value.*to_string)();
}
template <typename T,
typename test_for_number = typename std::enable_if<
std::is_arithmetic<T>::value, bool>::type,
typename dummy = bool>
static std::string Convert(const T& value) {
return std::to_string(value);
}
static std::string Convert(const char* value) {
return value != nullptr ? value : "(null)";
}
static std::string Convert(const std::string& value) { return value; }
static std::string Convert(bool value) { return value ? "true" : "false"; }
template <unsigned BASE_BITS, typename T,
typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
static std::string BaseConvert(const T& value) {
auto v = static_cast<uint64_t>(value);
char ret[3 * sizeof(T)];
char* ptr = ret + 3 * sizeof(T) - 1;
*ptr = '\0';
const char* digits = "0123456789abcdef";
do {
unsigned digit = v & ((1 << BASE_BITS) - 1);
*--ptr = (BASE_BITS < 4 ? static_cast<char>('0' + digit) : digits[digit]);
} while ((v >>= BASE_BITS) != 0);
return ptr;
}
template <unsigned BASE_BITS, typename T,
typename std::enable_if<!std::is_integral<T>::value, int>::type = 0>
static std::string BaseConvert(T value) {
return Convert(std::forward<T>(value));
}
};

template <typename T>
std::string ToString(const T& value) {
return ToStringHelper::Convert(value);
}

template <unsigned BASE_BITS, typename T>
std::string ToBaseString(const T& value) {
return ToStringHelper::BaseConvert<BASE_BITS>(value);
}

inline std::string SPrintFImpl(const char* format) {
const char* p = strchr(format, '%');
if (LIKELY(p == nullptr)) return format;
CHECK_EQ(p[1], '%'); // Only '%%' allowed when there are no arguments.

return std::string(format, p + 1) + SPrintFImpl(p + 2);
}

template <typename Arg, typename... Args>
std::string SPrintFImpl( // NOLINT(runtime/string)
const char* format, Arg&& arg, Args&&... args) {
const char* p = strchr(format, '%');
if (p == nullptr) return "";
std::string ret(format, p);
// Ignore long / size_t modifiers
while (strchr("lz", *++p) != nullptr) {
}
switch (*p) {
case '%': {
return ret + '%' +
SPrintFImpl(p + 1, std::forward<Arg>(arg),
std::forward<Args>(args)...);
}
default: {
return ret + '%' +
SPrintFImpl(p, std::forward<Arg>(arg),
std::forward<Args>(args)...);
}
case 'f':
case 'd':
case 'i':
case 'u':
case 's':
ret += ToString(arg);
break;
case 'o':
ret += ToBaseString<3>(arg);
break;
case 'x':
ret += ToBaseString<4>(arg);
break;
case 'p': {
CHECK(std::is_pointer<typename std::remove_reference<Arg>::type>::value);
char out[20];
int n = snprintf(out, sizeof(out), "%p",
*reinterpret_cast<const void* const*>(&arg));
CHECK_GE(n, 0);
ret += out;
break;
}
}
return ret + SPrintFImpl(p + 1, std::forward<Args>(args)...);
}

template <typename... Args>
std::string SPrintF( // NOLINT(runtime/string)
const char* format, Args&&... args) {
return SPrintFImpl(format, std::forward<Args>(args)...);
}
} // namespace xprofiler
#endif
9 changes: 9 additions & 0 deletions src/library/printf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef XPROFILER_SRC_LIBRARY_PRINT_H
#define XPROFILER_SRC_LIBRARY_PRINT_H
#include <string>

namespace xprofiler {
template <typename... Args>
inline std::string SPrintF(const char* format, Args&&... args);
} // namespace xprofiler
#endif
4 changes: 2 additions & 2 deletions src/logbypass/cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace xprofiler {

#define INIT_CPU_AVERAGE(period) double cpu_##period##_average = 0.0;

#define ALINODE_LOG_KEY(period) "cpu_" #period ": %.2lf"
#define ALINODE_LOG_KEY(period) "cpu_" #period ": %lf"

#define XPROFILER_LOG_KEY(period) "cpu_" #period ": %lf"

Expand Down Expand Up @@ -76,7 +76,7 @@ void WriteCpuUsageInPeriod(bool log_format_alinode) {
Info("other",
#undef EXTRA_SYMBOL
#define EXTRA_SYMBOL ", "
"cpu_usage(%%) now: %.2lf, " PERIOD_LIST(ALINODE_LOG_KEY),
"cpu_usage(%%) now: %lf, " PERIOD_LIST(ALINODE_LOG_KEY),
#undef EXTRA_SYMBOL
#define EXTRA_SYMBOL ,
cpu_now, PERIOD_LIST(CPU_AVERAGE_VAL));
Expand Down
4 changes: 2 additions & 2 deletions src/logbypass/http.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void WriteHttpStatus(EnvironmentData* env_data, bool log_format_alinode,
"live_http_request: %d, "
"http_request_handled: %d, "
"http_response_sent: %d, "
"http_rt: %.2lf",
"http_rt: %lf",
http_statistics->live_http_request,
http_statistics->http_response_sent,
http_statistics->http_response_sent, rt);
Expand All @@ -116,7 +116,7 @@ void WriteHttpStatus(EnvironmentData* env_data, bool log_format_alinode,
"http_response_sent: %d, "
"http_request_timeout: %d, "
"http_patch_timeout: %d, "
"http_rt: %.2lf",
"http_rt: %lf",
format.c_str(), http_statistics->live_http_request,
http_statistics->http_response_close,
http_statistics->http_response_sent,
Expand Down
58 changes: 10 additions & 48 deletions src/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ using v8::Local;
using v8::String;
using v8::Value;

static const int kMaxMessageLength = 2048;
static const int kMaxFormatLength = 2048;

static void WriteToFile(const LOG_LEVEL output_level, char* log) {
static void WriteToFile(const LOG_LEVEL output_level, const char* log) {
// get time of date
char time_string_day[32];
time_t tt = time(NULL);
Expand Down Expand Up @@ -66,9 +65,8 @@ static void WriteToFile(const LOG_LEVEL output_level, char* log) {
}
}

static void Log(const LOG_LEVEL output_level, const char* type,
ThreadId thread_id, const char* format,
va_list* arglist = nullptr) {
void Log(const LOG_LEVEL output_level, const char* type, ThreadId thread_id,
const char* message) {
LOG_LEVEL level = GetLogLevel();
if (level < output_level) {
return;
Expand Down Expand Up @@ -111,26 +109,18 @@ static void Log(const LOG_LEVEL output_level, const char* type,
string pid = to_string(GetPid());
string tid = to_string(static_cast<long>(thread_id));

// add log prefix
char tmp_format[kMaxFormatLength];
// compose log
char tmp_log[kMaxFormatLength];
if (log_format_alinode) {
snprintf(tmp_format, sizeof(tmp_format), "[%s] [%s] [%s] [%s] %s\n",
snprintf(tmp_log, sizeof(tmp_log), "[%s] [%s] [%s] [%s] %s\n",
time_string_ms_alinode, level_string.c_str(), type, pid.c_str(),
format);
message);
} else {
snprintf(tmp_format, sizeof(tmp_format),
"[%s] [%s] [%s] [%s] [%s] [%s] %s\n", time_string_ms,
level_string.c_str(), type, pid.c_str(), tid.c_str(),
XPROFILER_VERSION, format);
snprintf(tmp_log, sizeof(tmp_log), "[%s] [%s] [%s] [%s] [%s] [%s] %s\n",
time_string_ms, level_string.c_str(), type, pid.c_str(),
tid.c_str(), XPROFILER_VERSION, message);
}

// compose log
char tmp_log[kMaxMessageLength];
if (arglist != nullptr)
vsnprintf(tmp_log, sizeof(tmp_log), tmp_format, *arglist);
else
snprintf(tmp_log, sizeof(tmp_log), "%s", tmp_format);

// get log type
switch (GetLogType()) {
// tty
Expand All @@ -147,34 +137,6 @@ static void Log(const LOG_LEVEL output_level, const char* type,
}
}

/* native logger */

#define NATIVE_LOGGERS(V) \
V(Info, LOG_INFO) \
V(Error, LOG_ERROR) \
V(Debug, LOG_DEBUG)

#define DEFINE_LOGGER(name, level) \
void name(const char* component, const char* format, ...) { \
va_list args; \
va_start(args, format); \
Log(LOG_LEVEL::level, component, 0, format, &args); \
va_end(args); \
}
NATIVE_LOGGERS(DEFINE_LOGGER);
#undef DEFINE_LOGGER

#define DEFINE_LOGGER(name, level) \
void name##T(const char* component, ThreadId thread_id, const char* format, \
...) { \
va_list args; \
va_start(args, format); \
Log(LOG_LEVEL::level, component, thread_id, format, &args); \
va_end(args); \
}
NATIVE_LOGGERS(DEFINE_LOGGER);
#undef DEFINE_LOGGER

#define JS_LOG_WITH_LEVEL(level) \
if (!info[0]->IsString() || !info[1]->IsString()) { \
ThrowTypeError( \
Expand Down
Loading

0 comments on commit 9e9349b

Please sign in to comment.