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

feat: Update view hierarchy attachment format to Json #2491

Merged
merged 28 commits into from
Dec 20, 2022

Conversation

brustolin
Copy link
Contributor

@brustolin brustolin commented Dec 5, 2022

📜 Description

Change view hierarchy format to conform to RFC 33

💡 Motivation and Context

close #2467

💚 How did you test it?

Unit tests

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • Review from the native team if needed
  • No breaking changes

🔮 Next steps

@github-actions
Copy link

github-actions bot commented Dec 5, 2022

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 193a2f7

@codecov
Copy link

codecov bot commented Dec 5, 2022

Codecov Report

Merging #2491 (193a2f7) into 8.0.0 (1018de3) will increase coverage by 0.10%.
The diff coverage is 95.63%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##            8.0.0    #2491      +/-   ##
==========================================
+ Coverage   78.94%   79.04%   +0.10%     
==========================================
  Files         240      243       +3     
  Lines       22124    22259     +135     
  Branches     9768     9839      +71     
==========================================
+ Hits        17466    17595     +129     
- Misses       4206     4213       +7     
+ Partials      452      451       -1     
Impacted Files Coverage Δ
Sources/Sentry/PrivateSentrySDKOnly.m 91.17% <0.00%> (-4.21%) ⬇️
Sources/Sentry/SentryEnvelope.m 88.55% <83.33%> (-0.84%) ⬇️
Sources/Sentry/SentryAttachment.m 92.85% <87.50%> (-7.15%) ⬇️
Sources/Sentry/SentryViewHierarchy.m 98.97% <98.87%> (+52.82%) ⬆️
Sources/Sentry/SentryCrashReportSink.m 88.88% <100.00%> (ø)
Sources/Sentry/SentryEnvelopeAttachmentHeader.m 100.00% <100.00%> (ø)
Sources/Sentry/SentryEnvelopeItemHeader.m 100.00% <100.00%> (ø)
Sources/Sentry/SentryScope.m 96.72% <100.00%> (+0.10%) ⬆️
Sources/Sentry/SentrySerialization.m 87.84% <100.00%> (+0.13%) ⬆️
Sources/Sentry/SentryViewHierarchyIntegration.m 88.88% <100.00%> (-0.86%) ⬇️
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1018de3...193a2f7. Read the comment docs.

@github-actions
Copy link

github-actions bot commented Dec 5, 2022

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1196.53 ms 1209.35 ms 12.82 ms
Size 20.75 KiB 404.20 KiB 383.44 KiB

Baseline results on branch: 8.0.0

Startup times

Revision Plain With Sentry Diff
5da2d48 1209.52 ms 1232.16 ms 22.64 ms
9f8d429 1239.57 ms 1255.12 ms 15.55 ms
3fdb749 1227.42 ms 1248.48 ms 21.06 ms
b9c9598 1232.86 ms 1253.84 ms 20.98 ms
b696ae1 1229.64 ms 1246.94 ms 17.30 ms
d8c347f 1240.53 ms 1257.70 ms 17.17 ms
459ae5e 1223.84 ms 1250.14 ms 26.31 ms
a8ac44f 1198.63 ms 1231.08 ms 32.45 ms
a0c8696 1239.33 ms 1261.92 ms 22.59 ms
88ac2c2 1223.04 ms 1243.12 ms 20.08 ms

App size

Revision Plain With Sentry Diff
5da2d48 20.75 KiB 383.77 KiB 363.01 KiB
9f8d429 20.75 KiB 383.40 KiB 362.65 KiB
3fdb749 20.75 KiB 383.81 KiB 363.06 KiB
b9c9598 20.75 KiB 383.77 KiB 363.01 KiB
b696ae1 20.75 KiB 383.77 KiB 363.01 KiB
d8c347f 20.75 KiB 383.77 KiB 363.02 KiB
459ae5e 20.75 KiB 383.50 KiB 362.75 KiB
a8ac44f 20.75 KiB 405.17 KiB 384.41 KiB
a0c8696 20.75 KiB 383.89 KiB 363.14 KiB
88ac2c2 20.75 KiB 373.61 KiB 352.86 KiB

Previous results on branch: feat/view-hierarchy

Startup times

Revision Plain With Sentry Diff
fbb44fb 1217.22 ms 1239.00 ms 21.78 ms
4ffd327 1217.31 ms 1248.26 ms 30.95 ms
e9ee171 1203.84 ms 1237.76 ms 33.92 ms
2e2a243 1238.42 ms 1268.50 ms 30.08 ms
797af24 1243.04 ms 1279.43 ms 36.39 ms
806bdb8 1248.11 ms 1252.32 ms 4.21 ms
5551192 1188.55 ms 1234.82 ms 46.27 ms
b989d78 1196.17 ms 1241.08 ms 44.91 ms
ddb8e6c 1213.39 ms 1239.22 ms 25.83 ms

App size

Revision Plain With Sentry Diff
fbb44fb 20.75 KiB 405.61 KiB 384.85 KiB
4ffd327 20.75 KiB 406.30 KiB 385.54 KiB
e9ee171 20.75 KiB 384.62 KiB 363.86 KiB
2e2a243 20.75 KiB 406.25 KiB 385.50 KiB
797af24 20.75 KiB 406.78 KiB 386.03 KiB
806bdb8 20.75 KiB 406.69 KiB 385.93 KiB
5551192 20.75 KiB 406.30 KiB 385.54 KiB
b989d78 20.75 KiB 406.97 KiB 386.21 KiB
ddb8e6c 20.75 KiB 406.81 KiB 386.06 KiB

@brustolin brustolin changed the title feat: Update view hierarchy format feat: Update view hierarchy attachment format Dec 5, 2022
@brustolin brustolin marked this pull request as ready for review December 5, 2022 16:34
tryJson(sentrycrashjson_addFloatingPointElement(context, "x", view.frame.origin.x));
tryJson(sentrycrashjson_addFloatingPointElement(context, "y", view.frame.origin.y));
tryJson(sentrycrashjson_addFloatingPointElement(context, "alpha", view.alpha));
tryJson(sentrycrashjson_addBooleanElement(context, "visible", !view.hidden));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we not just using [NSJSONSerialization dataWithJSONObject:]? I don't really understand why we're creating JSON in such a strange way with sentrycrashjson_addFloatingPointElement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This way we can write directly to file, or to memory buffer, no need to first create a dictionary, and then serialize the dictionary.
This will be used during signal handling, the faster and less memory allocation being done the better.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but we already call into objective C code to make this work. We should only call async safe code in a signal handler, but as we are already violating that contract, I'm unsure if it's worth the effort. We call this only after SentryCrash wrote the crash report. In some cases, we will crash when calling into ObjC, but I think it doesn't matter how often we do it. Once is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is not about safety, because this code itself is called from an objc class. Is about performance, this is the fastest way to do it, and since we may deal of view hierarchy with hundreds of views, the faster the better.

Copy link
Member

Choose a reason for hiding this comment

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

How much faster? Do you have benchmarks?

Copy link
Member

Choose a reason for hiding this comment

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

You convinced me with during signal handling.

Copy link
Contributor

@kevinrenskers kevinrenskers left a comment

Choose a reason for hiding this comment

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

Personally I don't think the JSON code is a good thing to maintain, but if you say it makes a significant difference with CPU / memory usage, I guess it makes sense?

I also feel the goto code is a footgun, but I'll leave final judgement for @philipphofmann.

@brustolin
Copy link
Contributor Author

@kevinrenskers goto is just another language feature, like any other feature, you can use it right, you can use it wrong, thats what tests are for.

But in this case I have another solution, I will use it to make you happy! 😁

@kevinrenskers
Copy link
Contributor

Well I didn't deny the PR, like I said I'll just leave it up to Philipp :)

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

First pass. Still need to review a couple of files.

CHANGELOG.md Outdated Show resolved Hide resolved
Sources/Sentry/Public/SentryAttachment.h Outdated Show resolved Hide resolved
Sources/Sentry/SentryEnvelope.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryEnvelope.m Outdated Show resolved Hide resolved
Sources/Sentry/include/HybridPublic/SentryEnvelope.h Outdated Show resolved Hide resolved
Sources/Sentry/SentrySerialization.m Outdated Show resolved Hide resolved
Sources/Sentry/include/HybridPublic/SentryEnvelope.h Outdated Show resolved Hide resolved
Sources/Sentry/SentryEnvelope.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryEnvelope.m Outdated Show resolved Hide resolved
@philipphofmann
Copy link
Member

I also feel the goto code is a footgun, but I'll leave final judgement for @philipphofmann.

I also don't like goto in general, but let's see 😁

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

I'm unsure about writing the hierarchy with C APIs. I explained my concerns in my comment. Once we resolved that I'm going to give this another review.

Comment on lines +36 to +42
const char *path = [filePath UTF8String];
int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
if (fd < 0) {
SENTRY_LOG_DEBUG(@"Could not open file %s for writing: %s", path, strerror(errno));
return false;
}

Copy link
Member

Choose a reason for hiding this comment

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

m: Why don't we use ObjC here? SENTRY_LOG_DEBUG calls into ObjC code.

Copy link
Contributor Author

@brustolin brustolin Dec 9, 2022

Choose a reason for hiding this comment

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

Why don't we use ObjC here?

What do you mean? Almost everything here is objc.
If you're talking about the serialization approach in the other function, the explanation is here

tryJson(sentrycrashjson_addFloatingPointElement(context, "x", view.frame.origin.x));
tryJson(sentrycrashjson_addFloatingPointElement(context, "y", view.frame.origin.y));
tryJson(sentrycrashjson_addFloatingPointElement(context, "alpha", view.alpha));
tryJson(sentrycrashjson_addBooleanElement(context, "visible", !view.hidden));
Copy link
Member

Choose a reason for hiding this comment

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

Yes, but we already call into objective C code to make this work. We should only call async safe code in a signal handler, but as we are already violating that contract, I'm unsure if it's worth the effort. We call this only after SentryCrash wrote the crash report. In some cases, we will crash when calling into ObjC, but I think it doesn't matter how often we do it. Once is enough.

@@ -396,6 +396,19 @@ - (void)addAttachment:(SentryAttachment *)attachment
}
}

- (void)addCrashReportAttachmentInPath:(NSString *)filePath
{
if ([filePath.lastPathComponent isEqualToString:@"view-hierarchy.json"]) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please address this comment ⬆️

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

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

LGTM

@brustolin brustolin changed the title feat: Update view hierarchy attachment format feat: Update view hierarchy attachment format to Json Dec 16, 2022
@philipphofmann philipphofmann merged commit 1a18683 into 8.0.0 Dec 20, 2022
@philipphofmann philipphofmann deleted the feat/view-hierarchy branch December 20, 2022 09:20
@marandaneto
Copy link
Contributor

@philipphofmann @brustolin is there docs for that already?

@philipphofmann
Copy link
Member

I'm pretty sure there aren't. @brustolin, please add some after your PTO. I created an issue getsentry/sentry-docs#5984.

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.

Update view hierarchy format
6 participants