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

.NET profiler improvements & test fixes #2968

Merged
merged 42 commits into from
Dec 22, 2023
Merged

Conversation

vaind
Copy link
Collaborator

@vaind vaind commented Dec 13, 2023

  • Make profiler startup non-blocking by default, with an option to block up to the given timeout.
  • Tune tests to reduce flakiness
  • null-check on TraceEvent thread()
  • if option profiling sampling is on, but no integration was added or ios aot, diagnostic warn user telling them how to fix.

#skip-changelog

@vaind vaind marked this pull request as draft December 13, 2023 19:47
@vaind vaind changed the title .NET profiler fixes .NET profiler test fixes Dec 14, 2023
@vaind vaind changed the title .NET profiler test fixes .NET profiler improvements & test fixes Dec 18, 2023

return new SampleProfilerSession(stopWatch, session, eventSource, logger);
// Process() blocks until the session is stopped so we need to run it on a separate thread.
Task.Factory.StartNew(eventSource.Process, TaskCreationOptions.LongRunning);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to observe any exception of this and log? I think right this it'll end up on UnobservedExceptionHandler

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's logged below on line 74

I've added a test case Profiler_ThrowingOnSessionStartup_DoesntBreakSentryInit to make sure an exception thrown inside profiler session init doesn't break Sentry init

Copy link
Member

@bruno-garcia bruno-garcia Dec 22, 2023

Choose a reason for hiding this comment

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

Sorry I don't get it (line 74 is above this). But I mean if the callback running concurrently throws (eventSource.Process, if that throws? We can ContinuesWith at the end of StartNew for example, or have a callback with a trycatch before we call eentSource.Process?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I get what you mean now. I was confused at first because this bit of code hasn't actually changed so I thought you're talking about sth else.

In case Process() throws: yes, I think it'd get handled by UnobservedExceptionHandler.

I've added ContinueWith()

src/Sentry.Profiling/SampleProfilerSession.cs Outdated Show resolved Hide resolved
src/Sentry.Profiling/SamplingTransactionProfiler.cs Outdated Show resolved Hide resolved
src/Sentry.Profiling/SamplingTransactionProfilerFactory.cs Outdated Show resolved Hide resolved
src/Sentry.Profiling/SamplingTransactionProfilerFactory.cs Outdated Show resolved Hide resolved
src/Sentry.Profiling/SamplingTransactionProfilerFactory.cs Outdated Show resolved Hide resolved
src/Sentry.Profiling/ProfilingIntegration.cs Show resolved Hide resolved
src/Sentry.Profiling/ProfilingIntegration.cs Outdated Show resolved Hide resolved
src/Sentry.Profiling/SampleProfilerSession.cs Outdated Show resolved Hide resolved
src/Sentry.Profiling/SampleProfilerSession.cs Outdated Show resolved Hide resolved

return new SampleProfilerSession(stopWatch, session, eventSource, logger);
// Process() blocks until the session is stopped so we need to run it on a separate thread.
Task.Factory.StartNew(eventSource.Process, TaskCreationOptions.LongRunning);
Copy link
Member

@bruno-garcia bruno-garcia Dec 22, 2023

Choose a reason for hiding this comment

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

Sorry I don't get it (line 74 is above this). But I mean if the callback running concurrently throws (eventSource.Process, if that throws? We can ContinuesWith at the end of StartNew for example, or have a callback with a trycatch before we call eentSource.Process?

var frame = profile.Frames[profileToVerify.Stacks[0][i]];
frame.Module = frame.Module.Replace("System.Private.CoreLib.il", "System.Private.CoreLib");
profileToVerify.Frames.Add(frame);
factory._sessionTask.Wait(60_000);
Copy link
Member

Choose a reason for hiding this comment

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

Waits up to a minute for one test and still times out? This is def far from ideal. Skipping in CI is OK but is this going to be flaky locally?
Hard to believe it can take more than 1 minute to startup

@vaind vaind marked this pull request as ready for review December 22, 2023 12:18
src/Sentry.Profiling/SampleProfileBuilder.cs Outdated Show resolved Hide resolved
src/Sentry.Profiling/SampleProfilerSession.cs Outdated Show resolved Hide resolved
{
if (_.Exception?.InnerException is { } e)
{
logger?.LogWarning("Error during sampler profiler EventPipeSession processing.", e);
Copy link
Member

Choose a reason for hiding this comment

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

Will conflict now I imagine, since we merged ur PR reordering

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, I should have looked for usages on the other PR too... All the usages passing an exception got picked up by the generic method so they didn't fail. I've fixed it in this branch with hope it gets merged soon also those fixes are unrelated. If it doesn't get merged, I can cherry-pick the commit to a new PR.

}
catch (Exception e)
{
_testOutputLogger.LogWarning("Caught an exception in a test block that is allowed to fail when in CI.", e);
Copy link
Member

Choose a reason for hiding this comment

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

Do we know what this exception will be? That would allow us to validate this in CI (timeout is OK but else it's not?)

@bruno-garcia bruno-garcia removed the request for review from Giorgi December 22, 2023 13:21
vaind and others added 9 commits December 22, 2023 16:39
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
* Set in_foreground app context

* Update Changelog

* Check OS

* Update verify tests

* Update remaining verify tests

* Remove redundant code.

* Update app context tests

* Catch IsOSPlatform failure

* Update CHANGELOG.md

Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>

* Refactor active window check.

* Add a comment

---------

Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
* Attach screenshot

* Add AttachScreenshots option default value test

* Update changelog

* Update changelog

* Add AttachScreenshots to bindable options.

* Add AttachScreenshots to verify

* Fix verify test

* Remove default for AttachScreenshots

* Use hint for screenshot attachments

* Update CHANGELOG.md

Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>

* Add screenshot processor on options

* Add comment, skip on Windows

* Move try/catch outside #if

* Don't add screenshot processor to scope.

* Log if screenshot cannot be captured.

* Add tests

* Find envelope by id.

* Assert attachment item only on mobile.

* Initialize ActivityStateManager

* Capture screen on UI thread.

* Init platform

* Move init to MainApplication

* Use extension methods on SentryOptions for logging

Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>

* Add missing using

* Init platform in lifecycle events

* Remove MainApplication from device tests

* Write to logcat

* Rename Property

* Pass AttachScreenshot to native sdk options.

* Move CaptureFailed outside of #Debug

* Remove leftover code

* Remove Logcat logging

* Update CHANGELOG.md

Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>

* Use blocking call on main thread

* Set debug mode to make logs work

* Update src/Sentry.Maui/SentryMauiOptions.cs

Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>

* Remove try catch from screen capture

* Rename file to match class name

---------

Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
Co-authored-by: GitHub <noreply@github.com>
@bruno-garcia bruno-garcia merged commit b734248 into main Dec 22, 2023
19 checks passed
@bruno-garcia bruno-garcia deleted the chore/profiling-fixes branch December 22, 2023 22:36
vaind added a commit that referenced this pull request Dec 27, 2023
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.

4 participants