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

Add fallback name for main thread in profiling data #2939

Merged
merged 2 commits into from
Jul 5, 2023

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Jun 29, 2023

What does this PR do?:

This PR adds a fallback name of "main" to the main Ruby thread.

The main Ruby thread is first thread created in the VM, and the one that is returned by Thread.main (when in the main Ractor).

Motivation:

As more profiling features start to show the name in the UX, it's annoying to often have the main thread not have a name.

Additional Notes:

This PR sits atop #2937 to avoid any merge conflicts (since both touch labels and the ThreadContext collector state), but is otherwise completely independent of that one.

How to test the change?:

This change includes test coverage.

You can see it in action by profiling a Ruby app that never names its main thread, and then confirming that profiling data for that thread is shown under the name main in the Datadog UX.

**What does this PR do?**:

This PR adds a fallback name of "main" to the main Ruby thread.

The main Ruby thread is first thread created in the VM, and the one
that is returned by `Thread.main` (when in the main Ractor).

**Motivation**:

As more profiling features start to show the name in the UX, it's
annoying to often have the main thread not have a name.

**Additional Notes**:

This PR sits atop #2937 to avoid any merge conflicts (since
both touch labels and the `ThreadContext` collector state), but
is otherwise completely independent of that one.

**How to test the change?**:

This change includes test coverage.

You can see it in action by profiling a Ruby app that never names its
main thread, and then confirming that profiling data for that thread
is shown under the name `main` in the Datadog UX.
@ivoanjo ivoanjo requested a review from a team June 29, 2023 15:25
@github-actions github-actions bot added the profiling Involves Datadog profiling label Jun 29, 2023
Copy link
Member

@GustavoCaso GustavoCaso left a comment

Choose a reason for hiding this comment

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

🚢

Base automatically changed from ivoanjo/prof-7440-basic-timeline to master July 5, 2023 14:21
gcc version 10.2.1 20210110 (Debian 10.2.1-6), used on our Ruby 2.7
images at time of writing, was incorrectly triggering a warning on this
code, and since in CI we compile with `-Werror` (we turn warnings into
errors), this was breaking.

This is not the first time we've seen gcc tripping around structure
initializers, so I'm not entirely surprised.

Shuffling the code around a bit made the warning go away.

Full details:
```
compiling ../../../../ext/ddtrace_profiling_native_extension/collectors_thread_context.c
../../../../ext/ddtrace_profiling_native_extension/collectors_thread_context.c: In function 'trigger_sample_for_thread':
../../../../ext/ddtrace_profiling_native_extension/collectors_thread_context.c:661:5: error: missing initializer for field 'num' of 'ddog_prof_Label' [-Werror=missing-field-initializers]
  661 |     };
      |     ^
In file included from /usr/local/bundle/gems/libdatadog-2.0.0.1.0-x86_64-linux/vendor/libdatadog-2.0.0/x86_64-linux/libdatadog-x86_64-unknown-linux-gnu/lib/pkgconfig/../../include/datadog/profiling.h:12,
                 from ../../../../ext/ddtrace_profiling_native_extension/collectors_stack.h:3,
                 from ../../../../ext/ddtrace_profiling_native_extension/collectors_thread_context.c:5:
/usr/local/bundle/gems/libdatadog-2.0.0.1.0-x86_64-linux/vendor/libdatadog-2.0.0/x86_64-linux/libdatadog-x86_64-unknown-linux-gnu/lib/pkgconfig/../../include/datadog/common.h:389:11: note: 'num' declared here
  389 |   int64_t num;
      |           ^~~
cc1: all warnings being treated as errors
```
@codecov-commenter
Copy link

Codecov Report

Merging #2939 (c00d287) into master (b9f6b9a) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2939      +/-   ##
==========================================
- Coverage   98.00%   98.00%   -0.01%     
==========================================
  Files        1282     1282              
  Lines       71105    71111       +6     
  Branches     3277     3277              
==========================================
+ Hits        69686    69691       +5     
- Misses       1419     1420       +1     
Impacted Files Coverage Δ
...atadog/profiling/collectors/thread_context_spec.rb 98.25% <100.00%> (+0.01%) ⬆️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ivoanjo ivoanjo merged commit e04c477 into master Jul 5, 2023
@ivoanjo ivoanjo deleted the ivoanjo/default-name-for-main-thread branch July 5, 2023 15:47
@github-actions github-actions bot added this to the 1.13.0 milestone Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
profiling Involves Datadog profiling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants