-
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 7 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
74 changes: 74 additions & 0 deletions
74
backtrace-library/src/main/java/backtraceio/library/common/ApplicationHelper.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,74 @@ | ||
package backtraceio.library.common; | ||
konraddysput marked this conversation as resolved.
Show resolved
Hide resolved
BartoszLitwiniuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import android.content.Context; | ||
import android.content.pm.PackageInfo; | ||
import android.content.pm.PackageManager; | ||
|
||
import backtraceio.library.logger.BacktraceLogger; | ||
|
||
public class ApplicationHelper { | ||
BartoszLitwiniuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private static final transient String LOG_TAG = ApplicationHelper.class.getSimpleName(); | ||
/** | ||
* Cached application name | ||
*/ | ||
private static String applicationName; | ||
|
||
/** | ||
* Cached application version | ||
*/ | ||
private static String applicationVersion; | ||
|
||
/** | ||
* Cached package name | ||
*/ | ||
private static String packageName; | ||
|
||
/** | ||
* Retrieves application name from context. The name will be cached over checks | ||
* @param context application context | ||
* @return application name | ||
*/ | ||
public static String getApplicationName(Context context) { | ||
BartoszLitwiniuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if(!BacktraceStringHelper.isNullOrEmpty(applicationName)) { | ||
return applicationName; | ||
} | ||
|
||
applicationName = context.getApplicationInfo().loadLabel(context.getPackageManager()).toString(); | ||
return applicationName; | ||
} | ||
|
||
/** | ||
* Retrieves application version from the context. If the version name is not defined, the version code will be used instead. | ||
* @param context application context | ||
* @return current application version. | ||
*/ | ||
public static String getApplicationVersion(Context context) { | ||
if(!BacktraceStringHelper.isNullOrEmpty(applicationVersion)) { | ||
return applicationVersion; | ||
} | ||
try { | ||
konraddysput marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PackageInfo info = context.getPackageManager() | ||
.getPackageInfo(context.getPackageName(), 0); | ||
applicationVersion = BacktraceStringHelper.isNullOrEmpty(info.versionName) ? String.valueOf(info.versionCode) : info.versionName; | ||
|
||
return applicationVersion; | ||
} catch (PackageManager.NameNotFoundException e) { | ||
BacktraceLogger.e(LOG_TAG, "Could not resolve application version", e); | ||
return ""; | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves package name from the context. | ||
* @param context application context | ||
* @return current package name. | ||
*/ | ||
public static String getPackageName(Context context) { | ||
if(!BacktraceStringHelper.isNullOrEmpty(packageName)) { | ||
return packageName; | ||
} | ||
packageName = context.getApplicationContext().getPackageName(); | ||
|
||
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; | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
backtrace-library/src/main/java/backtraceio/library/models/json/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,40 @@ | ||
package backtraceio.library.models.json; | ||
konraddysput marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import backtraceio.library.common.TypeHelper; | ||
import backtraceio.library.models.Tuple; | ||
|
||
public class ReportDataBuilder { | ||
|
||
/** | ||
* Divide custom user attributes into primitive and complex attributes and add to this object | ||
* | ||
* @param attributes client's attributes | ||
*/ | ||
public static Tuple<Map<String, String>, Map<String, Object>> getReportAttribues(Map<String, Object> attributes) { | ||
konraddysput marked this conversation as resolved.
Show resolved
Hide resolved
perf2711 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
HashMap<String, String> reportAttributes = new HashMap<>(); | ||
HashMap<String, Object> reportAnnotations = new HashMap<>(); | ||
|
||
if(attributes == null) { | ||
konraddysput marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return new Tuple<>(reportAttributes, reportAnnotations); | ||
} | ||
|
||
for (Map.Entry<String, Object> entry : attributes.entrySet()) { | ||
Object value = entry.getValue(); | ||
if (value == null) { | ||
reportAttributes.put(entry.getKey(), "null"); | ||
konraddysput marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue; | ||
} | ||
Class type = value.getClass(); | ||
if (TypeHelper.isPrimitiveOrPrimitiveWrapperOrString(type)) { | ||
reportAttributes.put(entry.getKey(), value.toString()); | ||
} else { | ||
reportAnnotations.put(entry.getKey(), value); | ||
} | ||
} | ||
|
||
return new Tuple<>(reportAttributes, reportAnnotations); | ||
|
||
} | ||
} |
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.