-
Notifications
You must be signed in to change notification settings - Fork 11
Metrics performance improvements #157
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a0d455a
Metrics speedup
konraddysput 2dca999
Optimize attributes conversions
33c5ccc
Add end of line to Tuple
095ee2a
Attributes getter and remove old not valid tests
2ac667f
Optimize attributes
ccca7dc
Remove debugging information and format file
5a4a7c9
Rollback MainActivity
79fa883
Merge branch 'master' into improvement/metrics-speedup
konraddysput 75a94f0
Reformat file. Bring previous metrics logic
5eab77b
Report data builder tests
330769b
Move application cache to singleton
ef6cd02
SkipNul, remove additional unique event and make application cache th…
b5565d9
Application metadata cache test
8f58ea5
Update ReportDataBuilder.java
konraddysput 1e1660b
Pull request updates: private constructor, move singleton method, for…
7871a13
Simplify BacktraceAttributes business logic
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
backtrace-library/src/main/java/backtraceio/library/common/ApplicationMetadataCache.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package backtraceio.library.common; | ||
|
||
import android.content.Context; | ||
import android.content.pm.PackageInfo; | ||
import android.content.pm.PackageManager; | ||
|
||
import backtraceio.library.logger.BacktraceLogger; | ||
|
||
public class ApplicationMetadataCache { | ||
|
||
private static final transient String LOG_TAG = ApplicationMetadataCache.class.getSimpleName(); | ||
|
||
private static ApplicationMetadataCache instance; | ||
|
||
/** | ||
* Cached application name | ||
*/ | ||
private String applicationName; | ||
|
||
/** | ||
* Cached application version | ||
*/ | ||
private String applicationVersion; | ||
|
||
/** | ||
* Cached package name | ||
*/ | ||
private String packageName; | ||
|
||
/** | ||
* Returns current application cache. This instance is a singleton since we can only operate | ||
* in a single application scope. | ||
* | ||
* @param context Application context | ||
* @return Application metadata cache | ||
*/ | ||
public static ApplicationMetadataCache getInstance(Context context) { | ||
BartoszLitwiniuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (instance == null) { | ||
instance = new ApplicationMetadataCache(context); | ||
} | ||
return instance; | ||
perf2711 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
perf2711 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final Context context; | ||
|
||
public ApplicationMetadataCache(Context context) { | ||
konraddysput marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.context = context; | ||
} | ||
|
||
/** | ||
* Retrieves application name from context. The name will be cached over checks | ||
* | ||
* @return application name | ||
*/ | ||
public String getApplicationName() { | ||
if (!BacktraceStringHelper.isNullOrEmpty(applicationName)) { | ||
return applicationName; | ||
} | ||
|
||
applicationName = context.getApplicationInfo().loadLabel(context.getPackageManager()).toString(); | ||
BartoszLitwiniuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return applicationName; | ||
} | ||
|
||
/** | ||
* Retrieves application version from the context. If the version name is not defined, the version code will be used instead. | ||
* | ||
* @return current application version. | ||
*/ | ||
public String getApplicationVersion() { | ||
if (!BacktraceStringHelper.isNullOrEmpty(applicationVersion)) { | ||
return applicationVersion; | ||
} | ||
try { | ||
PackageInfo info = context.getPackageManager() | ||
.getPackageInfo(context.getPackageName(), 0); | ||
applicationVersion = BacktraceStringHelper.isNullOrEmpty(info.versionName) ? String.valueOf(info.versionCode) : info.versionName; | ||
BartoszLitwiniuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return applicationVersion; | ||
} catch (PackageManager.NameNotFoundException e) { | ||
BacktraceLogger.e(LOG_TAG, "Could not resolve application version", e); | ||
return ""; | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves package name from the context. | ||
* | ||
* @return current package name. | ||
*/ | ||
public String getPackageName() { | ||
if (!BacktraceStringHelper.isNullOrEmpty(packageName)) { | ||
return packageName; | ||
} | ||
packageName = context.getApplicationContext().getPackageName(); | ||
BartoszLitwiniuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return packageName; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
backtrace-library/src/main/java/backtraceio/library/models/Tuple.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package backtraceio.library.models; | ||
|
||
public class Tuple<T1, T2> { | ||
konraddysput marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public final T1 first; | ||
public final T2 second; | ||
|
||
public Tuple(T1 first, T2 second) { | ||
this.first = first; | ||
this.second = second; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ace-library/src/main/java/backtraceio/library/models/attributes/ReportDataAttributes.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package backtraceio.library.models.attributes; | ||
|
||
import java.util.HashMap; | ||
|
||
public class ReportDataAttributes { | ||
private final HashMap<String, String> reportAttributes = new HashMap<>(); | ||
konraddysput marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private final HashMap<String, Object> reportAnnotations = new HashMap<>(); | ||
|
||
|
||
public void addAnnotation(String key, Object value) { | ||
reportAnnotations.put(key, value); | ||
} | ||
|
||
public void addAttribute(String key, String value) { | ||
reportAttributes.put(key, value); | ||
} | ||
|
||
public HashMap<String, String> getAttributes() { | ||
return reportAttributes; | ||
} | ||
|
||
public HashMap<String, Object> getAnnotations() { | ||
return reportAnnotations; | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
backtrace-library/src/main/java/backtraceio/library/models/attributes/ReportDataBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package backtraceio.library.models.attributes; | ||
|
||
import java.util.Map; | ||
|
||
import backtraceio.library.common.TypeHelper; | ||
|
||
public class ReportDataBuilder { | ||
|
||
/** | ||
* Divide custom user attributes into primitive and complex attributes and add to this object. By default nullable values will be included. | ||
* | ||
* @param attributes client's attributes | ||
* @return Report data attributes divided into attributes and annotations | ||
*/ | ||
public static ReportDataAttributes getReportAttributes(Map<String, Object> attributes) { | ||
return getReportAttributes(attributes, false); | ||
} | ||
|
||
/** | ||
* Divide custom user attributes into primitive and complex attributes and add to this object | ||
* | ||
* @param attributes client's attributes | ||
* @param skipNullable define attributes behavior on nullable value. By default all nullable attributes | ||
* will be included in the report. For some features like metrics, we don't want to send | ||
* nullable values, because they can generate invalid behavior/incorrect information. | ||
* @return Report data attributes divided into attributes and annotations | ||
*/ | ||
public static ReportDataAttributes getReportAttributes(Map<String, Object> attributes, boolean skipNullable) { | ||
perf2711 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ReportDataAttributes reportDataAttributes = new ReportDataAttributes(); | ||
|
||
if (attributes == null) { | ||
return reportDataAttributes; | ||
} | ||
|
||
for (Map.Entry<String, Object> entry : attributes.entrySet()) { | ||
String key = entry.getKey(); | ||
Object value = entry.getValue(); | ||
if (value == null) { | ||
if (!skipNullable) { | ||
reportDataAttributes.addAttribute(key, null); | ||
} | ||
continue; | ||
} | ||
if (TypeHelper.isPrimitiveOrPrimitiveWrapperOrString(value.getClass())) { | ||
reportDataAttributes.addAttribute(key, value.toString()); | ||
} else { | ||
reportDataAttributes.addAnnotation(key, value); | ||
} | ||
} | ||
|
||
return reportDataAttributes; | ||
|
||
konraddysput marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.