Skip to content
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

Trace deadline violations #457

Merged
merged 5 commits into from
Jul 1, 2024
Merged

Trace deadline violations #457

merged 5 commits into from
Jul 1, 2024

Conversation

petervdonovan
Copy link
Contributor

@petervdonovan petervdonovan commented Jun 28, 2024

This allows deadline violations to be traced using a format that is similar to regular reaction executions. I am not sure if we want to mainline it, but we could do so backwards-compatibly.

This branch is based on initialize-master-thread-id-windows, which would need to be merged first.

Summary by CodeRabbit

  • New Features

    • Enhanced tracing capabilities for reactions, providing better visibility into the system's behavior by marking the start and end of reactions.
  • Improvements

    • Improved deadline violation handling by adding detailed trace points, making it easier to diagnose and resolve issues.

Copy link
Contributor

coderabbitai bot commented Jun 28, 2024

Walkthrough

The changes add tracing points in various files to enhance monitoring of reactions within the system. Specifically, tracepoint_reaction_starts and tracepoint_reaction_ends are inserted before and after critical operations to log the starts and ends of reactions, incorporating the reaction's deadline for improved logging precision.

Changes

File Change Summary
core/reactor.c Added tracing points before and after invoking the deadline violation handler for reactions.
core/reactor_common.c Added tracing points before and after a code block within schedule_output_reactions function.
core/threaded/reactor_threaded.c Added tracing points before and after handling deadline violations in _lf_worker_handle_deadline_violation_for_reaction.
include/core/tracepoint.h Updated tracepoint_reaction_starts and tracepoint_reaction_ends macros to include reaction->deadline parameter.

Sequence Diagram(s)

sequenceDiagram
    participant Environment
    participant Reaction
    participant Monitor

    Environment->>+Reaction: Invoke deadline violation handler
    Reaction->>+Monitor: tracepoint_reaction_starts(reaction, deadline)
    Reaction-->>-Monitor: tracepoint_reaction_ends(reaction, deadline)
    Reaction-->>-Environment: Return from handler
Loading
sequenceDiagram
    participant ScheduleFunc as schedule_output_reactions
    participant Monitor

    ScheduleFunc->>+Monitor: tracepoint_reaction_starts(downstream_to_execute_now, deadline)
    ScheduleFunc-->>-Monitor: tracepoint_reaction_ends(downstream_to_execute_now, deadline)
Loading

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are currently opted into early access features by default.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@petervdonovan petervdonovan requested a review from cmnrd June 28, 2024 06:57
Copy link
Contributor

@cmnrd cmnrd left a comment

Choose a reason for hiding this comment

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

Changes look good, but why does this remove the lf_check_deadline API function? This doesn't seem backwards compatible, or is it?

@petervdonovan
Copy link
Contributor Author

Changes look good, but why does this remove the lf_check_deadline API function? This doesn't seem backwards compatible, or is it?

Ah, I forgot that this was a user-facing API and mistook it for dead code. I'll fix that.

Copy link
Contributor

@cmnrd cmnrd left a comment

Choose a reason for hiding this comment

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

Looks good! Should we get this merged?

@petervdonovan petervdonovan added the feature New feature label Jul 1, 2024
@petervdonovan
Copy link
Contributor Author

petervdonovan commented Jul 1, 2024

Looks good! Should we get this merged?

OK. I don't think it strictly needs to be merged, but I think that merging it probably will not break things for anyone (unless they are depending on very specific properties of the tracing output) and will make observability a little simpler to maintain. Let's merge this if we can easily do so.

If/when we merge this, I would recommend doing a squash to keep the version history clean. This branch was a little messy.

@petervdonovan petervdonovan marked this pull request as ready for review July 1, 2024 05:27
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d22db97 and 4729ee0.

Files selected for processing (4)
  • core/reactor.c (1 hunks)
  • core/reactor_common.c (2 hunks)
  • core/threaded/reactor_threaded.c (2 hunks)
  • include/core/tracepoint.h (2 hunks)
Additional comments not posted (5)
core/reactor.c (1)

167-175: Ensure consistent usage of tracepoints.

The tracepoints tracepoint_reaction_starts and tracepoint_reaction_ends are correctly placed around the deadline violation handler. Ensure that similar tracepoints are used consistently in other parts of the code where reactions are invoked.

Verification successful

Tracepoints are used consistently around reaction handlers.

The tracepoints tracepoint_reaction_starts and tracepoint_reaction_ends are consistently placed around reaction handlers in core/reactor.c, core/reactor_common.c, and core/threaded/reactor_threaded.c.

  • core/reactor.c
  • core/reactor_common.c
  • core/threaded/reactor_threaded.c
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the consistent usage of tracepoints in the codebase.

# Test: Search for the usage of tracepoint_reaction_starts and tracepoint_reaction_ends.
rg --type c $'tracepoint_reaction_starts'
rg --type c $'tracepoint_reaction_ends'

Length of output: 1337



Script:

#!/bin/bash
# Extract surrounding lines of the tracepoint usage in core/reactor.c
rg --type c -A 3 -B 3 'tracepoint_reaction_starts' core/reactor.c
rg --type c -A 3 -B 3 'tracepoint_reaction_ends' core/reactor.c

# Extract surrounding lines of the tracepoint usage in core/reactor_common.c
rg --type c -A 3 -B 3 'tracepoint_reaction_starts' core/reactor_common.c
rg --type c -A 3 -B 3 'tracepoint_reaction_ends' core/reactor_common.c

# Extract surrounding lines of the tracepoint usage in core/threaded/reactor_threaded.c
rg --type c -A 3 -B 3 'tracepoint_reaction_starts' core/threaded/reactor_threaded.c
rg --type c -A 3 -B 3 'tracepoint_reaction_ends' core/threaded/reactor_threaded.c

Length of output: 2811

include/core/tracepoint.h (1)

116-117: Verify the correctness of the added parameter.

The reaction->deadline parameter has been added to the tracepoint_reaction_ends macro. Ensure that this parameter is correctly used in the call_tracepoint function.

Verification successful

The added parameter reaction->deadline is correctly passed and used in the call_tracepoint function.

The reaction->deadline parameter in the tracepoint_reaction_ends macro corresponds to the extra_delay parameter in the call_tracepoint function, which is correctly used to set the extra_delay field in the trace record.

  • call_tracepoint function in core/tracepoint.c
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the added parameter in the call_tracepoint function.

# Test: Search for the call_tracepoint function definition and verify the usage of the reaction->deadline parameter.
rg --type c $'void call_tracepoint'

Length of output: 278



Script:

#!/bin/bash
# Description: Verify the usage of the reaction->deadline parameter in the call_tracepoint function implementation.

# Search for the implementation of the call_tracepoint function and display its content.
rg --type c --context 10 'void call_tracepoint' core/tracepoint.c

Length of output: 865



Script:

#!/bin/bash
# Description: Retrieve the complete implementation of the call_tracepoint function to verify the usage of the extra_delay parameter.

# Get the complete implementation of the call_tracepoint function.
rg --type c --context 50 'void call_tracepoint' core/tracepoint.c

Length of output: 4436

core/reactor_common.c (1)

Line range hint 827-836: Ensure consistent usage of tracepoints.

The tracepoints tracepoint_reaction_starts and tracepoint_reaction_ends are correctly placed around the deadline violation handler. Ensure that similar tracepoints are used consistently in other parts of the code where reactions are invoked.

Verification successful

The tracepoints tracepoint_reaction_starts and tracepoint_reaction_ends are used in multiple files, which suggests an effort to maintain consistency. The next step is to verify that these tracepoints are correctly placed around reaction invocations in each of these files.


Tracepoints are used consistently and correctly.

The tracepoints tracepoint_reaction_starts and tracepoint_reaction_ends are consistently placed around reaction invocations and deadline violation handlers in the files core/reactor.c, core/reactor_common.c, and core/threaded/reactor_threaded.c.

  • core/reactor.c: Lines around tracepoints are consistent with reaction invocations.
  • core/reactor_common.c: Lines around tracepoints are consistent with reaction invocations.
  • core/threaded/reactor_threaded.c: Lines around tracepoints are consistent with reaction invocations.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the consistent usage of tracepoints in the codebase.

# Test: Search for the usage of tracepoint_reaction_starts and tracepoint_reaction_ends.
rg --type c $'tracepoint_reaction_starts'
rg --type c $'tracepoint_reaction_ends'

Length of output: 1337



Script:

#!/bin/bash
# Description: Verify the placement of tracepoints around reaction invocations.

# Extract lines around tracepoint_reaction_starts and tracepoint_reaction_ends in core/reactor.c
rg --type c -A 5 -B 5 'tracepoint_reaction_starts' core/reactor.c
rg --type c -A 5 -B 5 'tracepoint_reaction_ends' core/reactor.c

# Extract lines around tracepoint_reaction_starts and tracepoint_reaction_ends in core/reactor_common.c
rg --type c -A 5 -B 5 'tracepoint_reaction_starts' core/reactor_common.c
rg --type c -A 5 -B 5 'tracepoint_reaction_ends' core/reactor_common.c

# Extract lines around tracepoint_reaction_starts and tracepoint_reaction_ends in core/threaded/reactor_threaded.c
rg --type c -A 5 -B 5 'tracepoint_reaction_starts' core/threaded/reactor_threaded.c
rg --type c -A 5 -B 5 'tracepoint_reaction_ends' core/threaded/reactor_threaded.c

Length of output: 4261

core/threaded/reactor_threaded.c (2)

732-732: Add a newline before the tracepoint for better readability.

Adding a newline before the tracepoint improves readability and separates the logical blocks of code.

+ 
  tracepoint_reaction_starts(env, reaction, worker_number);

Line range hint 732-743: Ensure tracepoints are correctly placed around the deadline violation handler.

The tracepoints should accurately mark the start and end of the deadline violation handler execution. Verify that these tracepoints are correctly placed and that the reaction->deadline_violation_handler is correctly invoked between them.

Comment on lines +106 to +107
call_tracepoint(reaction_starts, reaction->self, env->current_tag, worker, worker, reaction->number, NULL, NULL, \
reaction->deadline)
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Discrepancy in tracepoint_reaction_starts macro

The reaction->deadline parameter has been added to the tracepoint_reaction_starts macro, but it is not used in the call_tracepoint function. This discrepancy could lead to potential issues or unused parameters.

  • tracepoint_reaction_starts macro includes reaction->deadline.
  • call_tracepoint function signature does not include a corresponding parameter for reaction->deadline.

Please ensure that the reaction->deadline parameter is correctly integrated into the call_tracepoint function or remove it from the macro if it is unnecessary.

Analysis chain

Verify the correctness of the added parameter.

The reaction->deadline parameter has been added to the tracepoint_reaction_starts macro. Ensure that this parameter is correctly used in the call_tracepoint function.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of the added parameter in the call_tracepoint function.

# Test: Search for the call_tracepoint function definition and verify the usage of the reaction->deadline parameter.
rg --type c $'void call_tracepoint'

Length of output: 278



Script:

#!/bin/bash
# Extract the full definition of the call_tracepoint function from both files.
ast-grep --lang c --pattern $'void call_tracepoint($_, $_, $_, $_, $_, $_, $$$) { $$$ }' --json

Length of output: 99



Script:

#!/bin/bash
# Extract the lines surrounding the call_tracepoint function definition to inspect its parameters and body.
rg --context 10 'void call_tracepoint' include/core/tracepoint.h core/tracepoint.c

Length of output: 3131

@lhstrh lhstrh merged commit eca4bc8 into main Jul 1, 2024
47 of 48 checks passed
@lhstrh lhstrh deleted the trace-deadline-violations branch July 1, 2024 07:31
EhsanKhodadad pushed a commit to EhsanKhodadad/reactor-c that referenced this pull request Aug 1, 2024
* Record reaction start/end when calling violation handler

* Update tracepoint macro

* Do not delete check_deadline API function

* Format

---------

Co-authored-by: Christian Menard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants