Skip to content

Conversation

KrX3D
Copy link

@KrX3D KrX3D commented Apr 19, 2025

Fix for #4647

Adds the hostname (serverDescription) to the send output.

Output before:

Apr 16 20:46:20 Segment geometry: 0,30 -> 0,1

With this fix:

Apr 19 16:06:20 EleksTube Wifi state: 3

So now the syslog server creates only one file syslog-EleksTube.log instead of multiple (see picture in #4647)

Summary by CodeRabbit

  • Refactor
    • Improved network debug output by buffering messages and sending them in batches, resulting in more organized and grouped UDP debug logs.
    • Enhanced hostname resolution efficiency for debug output.
    • Reduced network traffic by minimizing the number of UDP packets sent during debugging.

Copy link
Contributor

coderabbitai bot commented Apr 19, 2025

Walkthrough

The changes refactor the UDP debug output logic in the NetworkDebugPrinter class. Hostname resolution is now handled by a dedicated resolveHostName() method, eliminating duplicate code. Output is buffered in an internal string, and a new flushBuffer() method sends the accumulated data via UDP, prefixing it with serverDescription. The write methods are modified to append data to the buffer and trigger flushing when a newline is encountered or the buffer exceeds a maximum size. The header file is updated to declare the new buffer, buffer size constant, and private methods.

Changes

Files Change Summary
wled00/net_debug.cpp Refactored UDP debug output: added resolveHostName() for hostname resolution, flushBuffer() for sending and clearing buffer, and updated write methods to use buffered output with conditional flushing instead of immediate UDP sends.
wled00/net_debug.h Added private buffer, buffer size constant, and declarations for resolveHostName() and flushBuffer() methods in the NetworkDebugPrinter class.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d0355b5 and 087a62a.

📒 Files selected for processing (1)
  • wled00/net_debug.cpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • wled00/net_debug.cpp

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
wled00/net_debug.cpp (1)

43-63: Improved multi-byte write implementation.

The buffer-based approach is well implemented, with appropriate handling of newlines and buffer size limits. The code effectively processes the input buffer and flushes at logical points.

One minor improvement opportunity: consider moving the hasNewline tracking to a local scope if it's only needed for the final check.

  // Check if we can find a newline in the buffer
- bool hasNewline = false;
  size_t lastNewlinePos = 0;
  
  for (size_t i = 0; i < size; i++) {
    buffer += (char)buf[i];
    if (buf[i] == '\n') {
-     hasNewline = true;
      lastNewlinePos = i;
      flushBuffer();
    }
  }
  
  // If buffer is large but no newline was found, flush anyway
- if (!hasNewline && buffer.length() >= MAX_BUFFER_SIZE) {
+ if (buffer.length() >= MAX_BUFFER_SIZE) {
    flushBuffer();
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02f14ba and d0355b5.

📒 Files selected for processing (2)
  • wled00/net_debug.cpp (2 hunks)
  • wled00/net_debug.h (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
wled00/net_debug.cpp (1)
wled00/net_debug.h (2)
  • c (16-16)
  • buf (17-17)
🔇 Additional comments (4)
wled00/net_debug.h (1)

11-14: Good additions for implementing buffered network debug output.

The new buffer, size limit, and private methods provide a clean structure for improving the network debug functionality. Using a buffer with conditional flushing will reduce network overhead compared to sending individual packets for each character or small write.

wled00/net_debug.cpp (3)

5-17: Well-organized hostname resolution.

This helper method centralizes the hostname resolution logic that was likely duplicated in the previous implementation. Good use of conditional compilation for different platforms.


19-28: Well-implemented buffer flushing with hostname prefix.

The flushBuffer method effectively accomplishes the PR objective by adding the hostname (serverDescription) as a prefix to each debug message. Good job checking for empty buffer to avoid unnecessary network operations.


30-41: Effective buffering implementation for single character writes.

The single-character write method now buffers characters and flushes at appropriate points (newlines or size limits), which is more efficient than sending individual UDP packets.

@blazoncek
Copy link
Collaborator

Thank you. This seems like a good improvement on a first glance.

Would you care to take a look at implementing QuickDebug by @gmag11 as proposed in #3396 ?
That could be a huge benefit for debugging purposes.

@KrX3D
Copy link
Author

KrX3D commented Apr 19, 2025

Would you care to take a look at implementing QuickDebug by @gmag11 as proposed in #3396 ? That could be a huge benefit for debugging purposes.

yeah i can take a look, but cant promise when, since i got a couple other things to do at the moment.

@netmindz
Copy link
Member

The title and description don't really match you code changes. Adding a buffer is a significant change to behavior and resolving your hostname for every message will give poor performance

@KrX3D
Copy link
Author

KrX3D commented Apr 23, 2025

Hi, so i will revert the net debug back to the original. I created a seperate syslog.h/.cpp which can used and is able to use the format RFC3164/5424 or even send it raw like in the net debug (using a bufer)

also being able to change the ip,port etc is now possible from the gui

i will update this PR in the next days with the new files

@KrX3D
Copy link
Author

KrX3D commented Apr 26, 2025

Hi, im closing this since like i said i created something seperate to the net debug here:
#4664

for syslog there is also an option RAW which should send like the net debug the output

@KrX3D KrX3D closed this Apr 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants