-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from Automattic/performance-improvements
Move decorating events with mutable device info to a background thread
- Loading branch information
Showing
8 changed files
with
186 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 @@ | ||
/build |
This file contains 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,37 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile | ||
|
||
-dontobfuscate | ||
|
||
-ignorewarnings | ||
|
||
-keepattributes *Annotation* | ||
|
||
-dontnote junit.framework.** | ||
-dontnote junit.runner.** | ||
|
||
-dontwarn androidx.test.** | ||
-dontwarn org.junit.** | ||
-dontwarn org.hamcrest.** | ||
-dontwarn com.squareup.javawriter.JavaWriter | ||
|
||
-keepclasseswithmembers @org.junit.runner.RunWith public class * |
This file contains 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,59 @@ | ||
plugins { | ||
id("com.android.library") | ||
id("androidx.benchmark") | ||
id("org.jetbrains.kotlin.android") | ||
} | ||
|
||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
|
||
android { | ||
namespace = "com.automattic.tracks.benchmark" | ||
compileSdk = 34 | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
|
||
defaultConfig { | ||
minSdk = 24 | ||
|
||
testInstrumentationRunner = "androidx.benchmark.junit4.AndroidBenchmarkRunner" | ||
} | ||
|
||
testBuildType = "release" | ||
buildTypes { | ||
debug { | ||
// Since isDebuggable can"t be modified by gradle for library modules, | ||
// it must be done in a manifest - see src/androidTest/AndroidManifest.xml | ||
isMinifyEnabled = true | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"benchmark-proguard-rules.pro" | ||
) | ||
} | ||
release { | ||
isDefault = true | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
androidTestImplementation("androidx.test:runner:1.5.2") | ||
androidTestImplementation("androidx.test.ext:junit:1.1.5") | ||
androidTestImplementation("junit:junit:4.13.2") | ||
androidTestImplementation("androidx.benchmark:benchmark-junit4:1.2.4") | ||
|
||
// Add your dependencies here. Note that you cannot benchmark code | ||
// in an app module this way - you will need to move any code you | ||
// want to benchmark to a library module: | ||
// https://developer.android.com/studio/projects/android-library#Convert | ||
androidTestImplementation(project(":AutomatticTracks")) | ||
} |
This file contains 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,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<!-- | ||
Important: disable debugging for accurate performance results | ||
In a com.android.library project, this flag must be disabled from this | ||
manifest, as it is not possible to override this flag from Gradle. | ||
--> | ||
<application | ||
android:debuggable="false" | ||
tools:ignore="HardcodedDebugMode" | ||
tools:replace="android:debuggable" /> | ||
</manifest> |
44 changes: 44 additions & 0 deletions
44
benchmark/src/androidTest/java/com/automattic/tracks/benchmark/TrackingMethodsBenchmark.kt
This file contains 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,44 @@ | ||
package com.automattic.tracks.benchmark | ||
|
||
import android.app.Activity | ||
import androidx.benchmark.junit4.BenchmarkRule | ||
import androidx.benchmark.junit4.measureRepeated | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.automattic.android.tracks.TracksClient | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import java.lang.reflect.Field | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class TrackingMethodsBenchmark { | ||
@get:Rule | ||
val activityRule = ActivityScenarioRule(SampleActivity::class.java) | ||
|
||
@get:Rule | ||
val benchmarkRule = BenchmarkRule() | ||
|
||
private lateinit var tracksClient: TracksClient | ||
|
||
@Before | ||
fun setUp() { | ||
activityRule.scenario.onActivity { | ||
tracksClient = TracksClient.getClient(it) | ||
} | ||
|
||
val field: Field = TracksClient::class.java.getDeclaredField("mTracksRestEndpointURL") | ||
field.isAccessible = true | ||
field.set(tracksClient, "https://not-a-real-url.test") | ||
} | ||
|
||
@Test | ||
fun basicTrackMethod() { | ||
benchmarkRule.measureRepeated { | ||
tracksClient.track("test1_test2_final", "user", TracksClient.NosaraUserType.ANON) | ||
} | ||
} | ||
|
||
class SampleActivity : Activity() | ||
} |
This file contains 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,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.BLUETOOTH" /> | ||
|
||
<application android:usesCleartextTraffic="true"> | ||
<activity | ||
android:name=".TrackingMethodsBenchmark$SampleActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> |
This file contains 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