RUM-11990: Defer requestProfiling to next app launch#2950
Conversation
6fe7292 to
1846513
Compare
|
🎯 Code Coverage 🔗 Commit SHA: c4f87a2 | Docs | Was this helpful? Give us feedback! |
1846513 to
d595d0e
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## feature/perfetto-profiling #2950 +/- ##
==============================================================
+ Coverage 70.89% 70.90% +0.01%
==============================================================
Files 839 842 +3
Lines 30579 30616 +37
Branches 5192 5204 +12
==============================================================
+ Hits 21676 21706 +30
- Misses 7428 7430 +2
- Partials 1475 1480 +5
🚀 New features to boost your workflow:
|
d595d0e to
da6a14c
Compare
| } | ||
|
|
||
| companion object { | ||
| internal const val DATADOG_PREFERENCES_FILE_NAME = "dd_prefs" |
There was a problem hiding this comment.
Just a heads up.
There is this comment in the RFC about the case when we have multiple instances of the SDK in the app.
Currently they will use the same shared preferences which is probably not good. We might need to parametrize this with sdkInstanceName string.
Not a blocking comment for this PR. Maybe you'll come up with better ideas.
There was a problem hiding this comment.
+1 on this: what we are missing is multiple SDK cores support.
To start recording we need that any of the cores requested it (at least with current configuration where sampling rate is hardcoded), so this is probably fine for the flag to be shared, but we need to:
- make sure that after recording is done it is sent to the proper core which requested it.
- make sure that we don't run several profiles in parallel.
There was a problem hiding this comment.
I agree, I think the multiple SDK core issue is not mainly on SharedPreference flag, but on the ProfilingFeature implementation about writing and uploading events as you said. For the dogfooding it's not an issue, I create a ticket to handle it in as a separate task
0xnm
left a comment
There was a problem hiding this comment.
I think what we are missing is multiple SDK cores support, we need to refine this flow.
| * An implementation of [PreferencesStorage] that uses Android's [SharedPreferences] as storage | ||
| * backend. | ||
| */ | ||
| class SharedPreferencesStorage(context: Context) : PreferencesStorage { |
There was a problem hiding this comment.
public class is exposing internal interface, there should be warning about this. We need to make interface public as well then.
| * An implementation of [PreferencesStorage] that uses Android's [SharedPreferences] as storage | ||
| * backend. | ||
| */ | ||
| class SharedPreferencesStorage(context: Context) : PreferencesStorage { |
There was a problem hiding this comment.
minor: let's make it clear what we expect application context here
| class SharedPreferencesStorage(context: Context) : PreferencesStorage { | |
| class SharedPreferencesStorage(appContext: Context) : PreferencesStorage { |
| } | ||
|
|
||
| companion object { | ||
| internal const val DATADOG_PREFERENCES_FILE_NAME = "dd_prefs" |
There was a problem hiding this comment.
+1 on this: what we are missing is multiple SDK cores support.
To start recording we need that any of the cores requested it (at least with current configuration where sampling rate is hardcoded), so this is probably fine for the flag to be shared, but we need to:
- make sure that after recording is done it is sent to the proper core which requested it.
- make sure that we don't run several profiles in parallel.
e8d21b1 to
7dbecec
Compare
9774f31 to
5509e32
Compare
| * An implementation of [PreferencesStorage] that uses Android's [SharedPreferences] as storage | ||
| * backend. | ||
| */ | ||
| class SharedPreferencesStorage(appContext: Context) : PreferencesStorage { |
There was a problem hiding this comment.
one downside is that we will trigger Strict Mode violation, because we need to read from disk on I/O thread, but I guess we don't have any other choice.
| /** | ||
| * Put a string value in the storage. | ||
| */ | ||
| fun getString(key: String): String? |
There was a problem hiding this comment.
we are not supplying any default value here as we do with getInt and getBoolean methods?
| private const val KEY_PROFILING_ENABLED = "dd_profiling_enabled" | ||
|
|
||
| internal fun setProfilingFlag(appContext: Context) { | ||
| SharedPreferencesStorage(appContext).putBoolean(KEY_PROFILING_ENABLED, true) |
There was a problem hiding this comment.
minor: each instance creation will involve doing appContext.getSharedPreferences call, which is probably doing I/O, so ideally we could create an instance only once if it is a concern
There was a problem hiding this comment.
Update ProfilingStage to singleton with unit test
c4f87a2
5509e32 to
c4f87a2
Compare
| // Reset the singleton | ||
| val storageField = ProfilingStorage::class.java.getDeclaredField("sharedPreferencesStorage") | ||
| storageField.isAccessible = true | ||
| storageField.set(ProfilingStorage, null) |
There was a problem hiding this comment.
minor: probably it is better to do it in the AfterEach (or maybe even in both BeforeEach and AfterEach), because we will leave the object with state set and this object may be used in another test class.
| val isEnabled = ProfilingStorage.isProfilingEnabled(mockContext) | ||
|
|
||
| // Then | ||
| Assertions.assertThat(isEnabled).isTrue() |
| latch.await(5, TimeUnit.SECONDS) | ||
|
|
||
| // Then | ||
| verify(mockContext, times(1)).getSharedPreferences( |
There was a problem hiding this comment.
| verify(mockContext, times(1)).getSharedPreferences( | |
| verify(mockContext).getSharedPreferences( |
46d5192
into
feature/perfetto-profiling
What does this PR do?
This PR enables the profiling request as early as possible during the app launch:
DdProfilingContentProviderto start the profiling request.ProfilingStorageto read/save/clean the profiling flag to defer the profiling request to the next app launch.Motivation
RUM-11990
Additional Notes
Profiling Sampling rate is not covered by this PR.
Review checklist (to be filled by reviewers)