Skip to content

[lldb-dap] Add timestamps to protocol logs #93540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2024
Merged

[lldb-dap] Add timestamps to protocol logs #93540

merged 1 commit into from
May 29, 2024

Conversation

labath
Copy link
Collaborator

@labath labath commented May 28, 2024

I've found them very useful as a rudimentary form of benchmark.

I've found them very useful as a rudimentary form of benchmark.
@labath labath requested a review from JDevlieghere as a code owner May 28, 2024 12:18
@llvmbot llvmbot added the lldb label May 28, 2024
@llvmbot
Copy link
Member

llvmbot commented May 28, 2024

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

Changes

I've found them very useful as a rudimentary form of benchmark.


Full diff: https://github.com/llvm/llvm-project/pull/93540.diff

1 Files Affected:

  • (modified) lldb/tools/lldb-dap/DAP.cpp (+9-4)
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index c7eb3db4304a9..d419f821999e6 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -103,7 +103,9 @@ void DAP::SendJSON(const llvm::json::Value &json) {
   SendJSON(json_str);
 
   if (log) {
-    *log << "<-- " << std::endl
+    auto now = std::chrono::duration<double>(
+        std::chrono::system_clock::now().time_since_epoch());
+    *log << llvm::formatv("{0:f9} <-- ", now.count()).str() << std::endl
          << "Content-Length: " << json_str.size() << "\r\n\r\n"
          << llvm::formatv("{0:2}", json).str() << std::endl;
   }
@@ -130,9 +132,12 @@ std::string DAP::ReadJSON() {
   if (!input.read_full(log.get(), length, json_str))
     return json_str;
 
-  if (log)
-    *log << "--> " << std::endl << "Content-Length: " << length << "\r\n\r\n";
-
+  if (log) {
+    auto now = std::chrono::duration<double>(
+        std::chrono::system_clock::now().time_since_epoch());
+    *log << llvm::formatv("{0:f9} --> ", now.count()).str() << std::endl
+         << "Content-Length: " << length << "\r\n\r\n";
+  }
   return json_str;
 }
 

@@ -103,7 +103,9 @@ void DAP::SendJSON(const llvm::json::Value &json) {
SendJSON(json_str);

if (log) {
*log << "<-- " << std::endl
auto now = std::chrono::duration<double>(
std::chrono::system_clock::now().time_since_epoch());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be better to use steady_clock? that's more stable for benchmarking

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for a benchmark yes, but this is only a "benchmark" (with very large quotes). Like, I won't be using this during daylight savings switchover, and I don't think it's suitable for anything automated. And it's kinda nice it matches the time stamps for regular lldb logs (I literally copied this code from there).

Copy link
Member

@walter-erquinigo walter-erquinigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good then!

@labath labath merged commit 2cfea14 into llvm:main May 29, 2024
7 checks passed
vg0204 pushed a commit to vg0204/llvm-project that referenced this pull request May 29, 2024
I've found them very useful as a rudimentary form of benchmark.
@labath labath deleted the stamp branch June 7, 2024 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants