-
-
Notifications
You must be signed in to change notification settings - Fork 45
Add perf monitoring trace for case list loading time #3297
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
Changes from all commits
131392c
a6dc921
27b88c8
fee3802
bce4173
1cf88be
bb78a56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package org.commcare.google.services.analytics | ||
|
|
||
| import com.google.firebase.perf.FirebasePerformance | ||
| import com.google.firebase.perf.metrics.Trace | ||
| import org.commcare.android.logging.ReportingUtils | ||
| import org.javarosa.core.services.Logger | ||
|
|
||
| object CCPerfMonitoring { | ||
| // Traces | ||
| // Measures the duration of synchronous case list loading | ||
| const val TRACE_SYNC_ENTITY_LIST_LOADING = "sync_case_list_loading" | ||
|
|
||
| // Attributes | ||
| const val ATTR_NUM_CASES_LOADED = "number_of_cases_loaded" | ||
|
|
||
| fun startTracing (traceName: String): Trace? { | ||
| try { | ||
| val trace = FirebasePerformance.getInstance().newTrace(traceName) | ||
| trace.putAttribute(CCAnalyticsParam.CCHQ_DOMAIN, ReportingUtils.getDomain()) | ||
| trace.putAttribute(CCAnalyticsParam.CC_APP_ID, ReportingUtils.getAppId()) | ||
| trace.putAttribute(CCAnalyticsParam.CC_APP_NAME, ReportingUtils.getAppName()) | ||
| trace.putAttribute(CCAnalyticsParam.USERNAME, ReportingUtils.getUser()) | ||
| trace.start(); | ||
| return trace | ||
| } catch (exception: Exception) { | ||
| Logger.exception("Error starting perf trace: $traceName", exception) | ||
| } | ||
| return null | ||
shubham1g5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| fun stopTracing(trace: Trace?) { | ||
| try { | ||
| trace?.stop(); | ||
| } catch (exception: Exception) { | ||
| Logger.exception("Error starting perf trace: ${trace?.name}", exception) | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,12 @@ | |
|
|
||
| import android.util.Pair; | ||
|
|
||
| import com.google.firebase.perf.metrics.Trace; | ||
|
|
||
| import org.commcare.android.logging.ForceCloseLogger; | ||
| import org.commcare.cases.entity.Entity; | ||
| import org.commcare.cases.entity.EntityLoadingProgressListener; | ||
| import org.commcare.google.services.analytics.CCPerfMonitoring; | ||
| import org.commcare.logging.XPathErrorLogger; | ||
| import org.commcare.suite.model.Detail; | ||
| import org.commcare.suite.model.EntityDatum; | ||
|
|
@@ -50,7 +53,20 @@ public EntityLoaderTask(Detail detail, @Nullable EntityDatum entityDatum, Evalua | |
| @Override | ||
| protected Pair<List<Entity<TreeReference>>, List<TreeReference>> doInBackground(TreeReference... nodeset) { | ||
| try { | ||
| return entityLoaderHelper.loadEntities(nodeset[0], this); | ||
| // Capture sync_case_list_loading trace for performance monitoring | ||
| Trace trace = null; | ||
| if (!entityLoaderHelper.isAsyncNodeEntityFactory()) { | ||
| trace = CCPerfMonitoring.INSTANCE.startTracing(CCPerfMonitoring.TRACE_SYNC_ENTITY_LIST_LOADING); | ||
| } | ||
| Pair<List<Entity<TreeReference>>, List<TreeReference>> entities = entityLoaderHelper.loadEntities( | ||
| nodeset[0], this); | ||
|
|
||
| if (trace != null && !entityLoaderHelper.isAsyncNodeEntityFactory()) { | ||
| trace.putAttribute(CCPerfMonitoring.ATTR_NUM_CASES_LOADED, | ||
| String.valueOf((entities == null || entities.first == null ? 0 : entities.first.size()))); | ||
| CCPerfMonitoring.INSTANCE.stopTracing(trace); | ||
|
Comment on lines
+65
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. think all trace handling should be as fail safe as possible, as such think we should pass the attributes as a dictionary to the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I made this change on a different branch (for another trace), I will push PR this separately |
||
| } | ||
| return entities; | ||
| } catch (XPathException xe) { | ||
| XPathErrorLogger.INSTANCE.logErrorToCurrentApp(xe); | ||
| Logger.exception("Error during EntityLoaderTask: " + ForceCloseLogger.getStackTrace(xe), xe); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually i think we should be using the same list of attributes as we send to analytics user properties here, think app id is definitely a big one that we should be including here.