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: Send app data size in app context #2197

Closed
wants to merge 17 commits into from

Conversation

kevinrenskers
Copy link
Contributor

@kevinrenskers kevinrenskers commented Sep 20, 2022

📜 Description

Calculate the size of the home directory (which is what "Documents & Data" is), in the background, every minute. And send it as part of the app context.

Screen Shot 2022-09-20 at 15 35 27

💡 Motivation and Context

Closes #1664

💚 How did you test it?

WIP

📝 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

* master:
  meta: Automatically manage signing (#2184)
  fix: Support for arm64 architecture (#2185)
  meta: Contributing md lint fixes (#2186)
  feat: Add flush (#2140)
* master:
  chore: Update SauceLabs config (#2194)
  ref: Specifically remove notification observers (#2193)
  docs: Fix network option code docs (#2192)
  test: Fix dispatch failure on M1 (#2189)
  ci: Clear test-server cache when files change (#2188)
@github-actions
Copy link

github-actions bot commented Sep 20, 2022

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

Generated by 🚫 dangerJS against 8053df7

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 like the approach. We need to make sure that this doesn't blow up and we need to add tests.

@@ -816,6 +827,7 @@ - (void)removeExtraDeviceContextFromEvent:(SentryEvent *)event
key:@"app"
block:^(NSMutableDictionary *app) {
[app removeObjectForKey:SentryDeviceContextAppMemoryKey];
[app removeObjectForKey:@"data_storage"];
Copy link
Member

Choose a reason for hiding this comment

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

m: How did you come up with that value? Is it the same as on some other platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can see, it doesn't exist for other platforms yet, it is undocumented. I said the same in the ticket.

}

// Code from https://github.com/NikolaiRuhe/NRFoundation/blob/master/NRFoundation/NRFileManager.m
- (long long)readAppDataSize
Copy link
Member

Choose a reason for hiding this comment

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

m: While I have nothing against reusing open source code, how did you validate that it works properly? How big is the overhead of this for an iOS app? I think we should use a profiler to check its overhead. We should also try this for a big app with loads of files.

Firefox is using the code here https://github.com/mozilla-mobile/firefox-ios/blob/9c933bae94d324eee0ecaec1c63822c3522a3262/Shared/Extensions/NSFileManagerExtensions.swift, so that's already a good resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I validated it by running the code and comparing the value to the actual folder that it checked. And this function was linked from the issue itself. Of course there is going to be overhead, that is why we do it in a background thread, once a minute.

As far as I can see from reading the docs, you can't get it much simpler than this: we get the contents of the folder (recursively), pre-fetch things like the file size, and fall back to getting the size manually if needed.

Copy link
Member

Choose a reason for hiding this comment

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

If the overhead is significant, we should consider making this optional or not doing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even though it's in a background thread already? Overhead of course gets bigger the more files the app stores, but at that point that is probably exactly the info the developer wants to have.

We could add an option for it in SentryOptions, default it to true, but I honestly don't see the downside of doing this once a minute in a background thread.

^{ self.appDataSize = [self readAppDataSize]; });
}

// Code from https://github.com/NikolaiRuhe/NRFoundation/blob/master/NRFoundation/NRFileManager.m
Copy link
Member

Choose a reason for hiding this comment

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

m: As the repo has no license, I think we should add a link to the issue explaining that it is licensed under MIP 2.0., see NikolaiRuhe/NRFoundation#2. @bruno-garcia is that fine?

Base automatically changed from feat/more-device-context to master September 22, 2022 09:04
@brustolin
Copy link
Contributor

We could use a file observer to monitor file changes. Here is a sample https://github.com/tblank555/iMonitorMyFiles/blob/master/iMonitorMyFiles/Classes/TABFileMonitor.m

@kevinrenskers kevinrenskers deleted the feat/1664-app-data-size branch September 22, 2022 12:47
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.

Add how much space an app takes up on the user's device
3 participants