提交 c9e30e68 编写于 作者: S siyangy 提交者: Jiangtao Hu

Dreamview: Improve logging of websocket write

上级 b2dd5ff6
......@@ -259,17 +259,17 @@ inline Clock::Clock()
#define PERF_BLOCK_NO_THRESHOLD(message) PERF_BLOCK_WITH_THRESHOLD(message, 0)
#define PERF_BLOCK_WITH_THRESHOLD(message, threshold) \
using apollo::common::time::Clock; \
for (double block_start_time = 0; \
(block_start_time == 0 ? (block_start_time = Clock::NowInSecond()) \
: false); \
[block_start_time]() { \
double now = Clock::NowInSecond(); \
if (now - block_start_time > (threshold)) { \
ADEBUG << std::fixed << (message) << ": " << now - block_start_time \
<< "s."; \
} \
#define PERF_BLOCK_WITH_THRESHOLD(message, threshold) \
using apollo::common::time::Clock; \
for (double block_start_time = 0; \
(block_start_time == 0 ? (block_start_time = Clock::NowInSecond()) \
: false); \
[&]() { \
double now = Clock::NowInSecond(); \
if (now - block_start_time > (threshold)) { \
AINFO << std::fixed << (message) << ": " << now - block_start_time \
<< "s."; \
} \
}())
} // namespace time
} // namespace common
......
......@@ -19,12 +19,14 @@ limitations under the License.
#include <vector>
#include "modules/common/log.h"
#include "modules/common/util/string_util.h"
#include "modules/common/time/time.h"
#include "modules/common/util/string_util.h"
namespace apollo {
namespace dreamview {
using apollo::common::util::StrCat;
void WebSocketHandler::handleReadyState(CivetServer *server, Connection *conn) {
{
std::unique_lock<std::mutex> lock(mutex_);
......@@ -104,9 +106,10 @@ bool WebSocketHandler::SendData(const std::string &data, Connection *conn,
// Note that while we are holding the connection lock, the connection won't be
// closed and removed.
int ret;
PERF_BLOCK("Websocket write took too long", 0.5) {
PERF_BLOCK(StrCat("Writing ", data.size(), " bytes via websocket took"),
0.1) {
ret = mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, data.c_str(),
data.size());
data.size());
}
connection_lock->unlock();
......@@ -118,8 +121,8 @@ bool WebSocketHandler::SendData(const std::string &data, Connection *conn,
} else if (ret < 0) {
msg = "Send Error";
} else {
msg = apollo::common::util::StrCat("Expect to send ", data.size(),
" bytes. But sent ", ret, " bytes");
msg = StrCat("Expect to send ", data.size(), " bytes. But sent ", ret,
" bytes");
}
AWARN << "Failed to send data via websocket connection. Reason: " << msg;
return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册