summaryrefslogtreecommitdiff
path: root/profilers
diff options
context:
space:
mode:
authorPhil Nguyen <philnguyen@google.com>2022-03-28 18:21:31 -0700
committerTreeHugger Robot <treehugger-gerrit@google.com>2022-03-30 23:57:45 +0000
commitf8e1c7960b6f2693d425beb5d1b161aba918900e (patch)
treea0c74d680932f33c9ac19842ff8af1e3f89ac388 /profilers
parent0a84e163873cff573f934a70a291763546b09ea8 (diff)
downloadidea-f8e1c7960b6f2693d425beb5d1b161aba918900e.tar.gz
Convert IdeProfilerServices to Kotlin
Bug: n/a Test: existing Change-Id: I816d9f9aacba818d75dd9f2d55d1ca5b0c19e669
Diffstat (limited to 'profilers')
-rw-r--r--profilers/src/com/android/tools/profilers/IdeProfilerServices.kt (renamed from profilers/src/com/android/tools/profilers/IdeProfilerServices.java)127
-rw-r--r--profilers/testSrc/com/android/tools/profilers/FakeIdeProfilerServices.java2
2 files changed, 60 insertions, 69 deletions
diff --git a/profilers/src/com/android/tools/profilers/IdeProfilerServices.java b/profilers/src/com/android/tools/profilers/IdeProfilerServices.kt
index 1eb013c9f8d..aa5f48cd3f0 100644
--- a/profilers/src/com/android/tools/profilers/IdeProfilerServices.java
+++ b/profilers/src/com/android/tools/profilers/IdeProfilerServices.kt
@@ -13,117 +13,108 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.tools.profilers;
-
-import com.android.tools.idea.codenavigation.CodeNavigator;
-import com.android.tools.profilers.analytics.FeatureTracker;
-import com.android.tools.profilers.appinspection.AppInspectionMigrationServices;
-import com.android.tools.profilers.cpu.config.ProfilingConfiguration;
-import com.android.tools.profilers.perfetto.traceprocessor.TraceProcessorService;
-import com.android.tools.profilers.stacktrace.NativeFrameSymbolizer;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Executor;
-import java.util.function.Consumer;
-import java.util.function.Function;
-import java.util.function.Supplier;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-public interface IdeProfilerServices {
+package com.android.tools.profilers
+
+import com.android.tools.idea.codenavigation.CodeNavigator
+import com.android.tools.profilers.analytics.FeatureTracker
+import com.android.tools.profilers.appinspection.AppInspectionMigrationServices
+import com.android.tools.profilers.cpu.config.ProfilingConfiguration
+import com.android.tools.profilers.perfetto.traceprocessor.TraceProcessorService
+import com.android.tools.profilers.stacktrace.NativeFrameSymbolizer
+import java.io.File
+import java.io.FileOutputStream
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.Executor
+import java.util.function.Consumer
+import java.util.function.Function
+import java.util.function.Supplier
+
+interface IdeProfilerServices {
/**
* Executor to run the tasks that should get back to the main thread.
*/
- @NotNull
- Executor getMainExecutor();
+ val mainExecutor: Executor
/**
* Executor to run the tasks that should run in a thread from the pool.
*/
- @NotNull
- Executor getPoolExecutor();
+ val poolExecutor: Executor
/**
* Compute expensive intermediate value on "pool", then resume it on "main"
*/
- default<R> void runAsync(@NotNull Supplier<R> supplier, @NotNull Consumer<R> consumer) {
+ @JvmDefault
+ fun <R> runAsync(supplier: Supplier<R>, consumer: Consumer<R>) {
CompletableFuture
- .supplyAsync(supplier, getPoolExecutor())
- .whenComplete((result, action) -> getMainExecutor().execute(() -> consumer.accept(result)));
+ .supplyAsync(supplier, poolExecutor)
+ .whenComplete { result: R , action -> mainExecutor.execute { consumer.accept(result) } }
}
/**
* @return all classes that belong to the current project (excluding dependent libraries).
*/
- @NotNull
- Set<String> getAllProjectClasses();
+ val allProjectClasses: Set<String>
/**
* Saves a file to the file system and have IDE internal state reflect this file addition.
*
* @param file File to save to.
- * @param fileOutputStreamConsumer {@link Consumer} to write the file contents into the supplied {@link FileOutputStream}.
+ * @param fileOutputStreamConsumer [Consumer] to write the file contents into the supplied [FileOutputStream].
* @param postRunnable A callback for when the system finally finishes writing to and synchronizing the file.
*/
- void saveFile(@NotNull File file, @NotNull Consumer<FileOutputStream> fileOutputStreamConsumer, @Nullable Runnable postRunnable);
+ fun saveFile(file: File, fileOutputStreamConsumer: Consumer<FileOutputStream>, postRunnable: Runnable?)
/**
* Returns a symbolizer wrapper that can be used for converting a module offset to a
- * {@link com.android.tools.profiler.proto.MemoryProfiler.NativeCallStack}.
+ * [com.android.tools.profiler.proto.MemoryProfiler.NativeCallStack].
*/
- @NotNull
- NativeFrameSymbolizer getNativeFrameSymbolizer();
+ val nativeFrameSymbolizer: NativeFrameSymbolizer
/**
* Returns a service that can navigate to a target code location.
- * <p>
+ *
+ *
* Implementors of this method should be sure to return the same instance each time, not a new
* instance per call.
*/
- @NotNull
- CodeNavigator getCodeNavigator();
+ val codeNavigator: CodeNavigator
/**
* Returns an opt-in service that can report when certain features were used.
- * <p>
+ *
+ *
* Implementors of this method should be sure to return the same instance each time, not a new
* instance per call.
*/
- @NotNull
- FeatureTracker getFeatureTracker();
+ val featureTracker: FeatureTracker
/**
* Either enable advanced profiling or present the user with UI to make enabling it easy.
- * <p>
+ *
+ *
* By default, advanced profiling features are not turned on, as they require instrumenting the
* user's code, which at the very least requires a rebuild. Moreover, this may even potentially
* interfere with the user's app logic or slow it down.
- * <p>
+ *
+ *
* If this method is called, it means the user has expressed an intention to enable advanced
* profiling. It is up to the implementor of this method to help the user accomplish this
* request.
*/
- void enableAdvancedProfiling();
-
- @NotNull
- FeatureConfig getFeatureConfig();
+ fun enableAdvancedProfiling()
+ val featureConfig: FeatureConfig
/**
* Allows the profiler to cache settings within the current studio session.
* e.g. settings are only preserved across profiling sessions within the same studio instance.
*/
- @NotNull
- ProfilerPreferences getTemporaryProfilerPreferences();
+ val temporaryProfilerPreferences: ProfilerPreferences
/**
* Allows the profiler to cache settings across multiple studio sessions.
* e.g. settings are preserved when studio restarts.
*/
- @NotNull
- ProfilerPreferences getPersistentProfilerPreferences();
+ val persistentProfilerPreferences: ProfilerPreferences
/**
* Displays a yes/no dialog warning the user and asking them if they want to proceed.
@@ -133,7 +124,7 @@ public interface IdeProfilerServices {
* @param yesCallback callback to be run if user clicks "Yes"
* @param noCallback callback to be run if user clicks "No"
*/
- void openYesNoDialog(String message, String title, Runnable yesCallback, Runnable noCallback);
+ fun openYesNoDialog(message: String, title: String, yesCallback: Runnable, noCallback: Runnable)
/**
* Opens a dialog asking the user to select items from the listbox.
@@ -144,57 +135,57 @@ public interface IdeProfilerServices {
* @param listBoxPresentationAdapter adapter that takes in an option and returns a string to be presented to the user.
* @return The option the user selected. If the user cancels the return value will be null.
*/
- @Nullable
- <T> T openListBoxChooserDialog(@NotNull String title,
- @Nullable String message,
- @NotNull List<T> options,
- @NotNull Function<T, String> listBoxPresentationAdapter);
+ fun <T> openListBoxChooserDialog(
+ title: String,
+ message: String?,
+ options: List<@JvmSuppressWildcards T>,
+ listBoxPresentationAdapter: Function<T, String>
+ ): T?
/**
* Returns the profiling configurations saved by the user for a project.
* apiLevel is the Android API level for the selected device, so that it return only
* the appropriate configurations that are available to run on a particular device.
*/
- List<ProfilingConfiguration> getUserCpuProfilerConfigs(int apiLevel);
+ fun getUserCpuProfilerConfigs(apiLevel: Int): List<ProfilingConfiguration>
/**
* Returns the default profiling configurations.
* apiLevel is the Android API level for the selected device, so that it return only
* the appropriate configurations that are available to run on a particular device.
*/
- List<ProfilingConfiguration> getDefaultCpuProfilerConfigs(int apiLevel);
+ fun getDefaultCpuProfilerConfigs(apiLevel: Int): List<ProfilingConfiguration>
/**
* Whether a native CPU profiling configuration is preferred over a Java one.
* Native configurations can be preferred for native projects, for instance.
*/
- boolean isNativeProfilingConfigurationPreferred();
+ val isNativeProfilingConfigurationPreferred: Boolean
/**
* Get the native memory sampling rate based on the current configuration.
*/
- int getNativeMemorySamplingRateForCurrentConfig();
+ val nativeMemorySamplingRateForCurrentConfig: Int
/**
* Pops up a toast that contains information contained in the notification,
* which should particularly draw attention to warning and error messages.
*/
- void showNotification(@NotNull Notification notification);
+ fun showNotification(notification: Notification)
/**
* Returns a list of symbol directories for a specific arch type.
*/
- @NotNull
- List<String> getNativeSymbolsDirectories();
+ val nativeSymbolsDirectories: List<String>
/**
- * Returns a instance for the {@link TraceProcessorService} to be used to communicate with the TraceProcessor daemon in order to
+ * Returns a instance for the [TraceProcessorService] to be used to communicate with the TraceProcessor daemon in order to
* parse and query Perfetto traces.
*/
- @NotNull TraceProcessorService getTraceProcessorService();
+ val traceProcessorService: TraceProcessorService
/**
* Returns the API for app inspection migration preferences.
*/
- @NotNull AppInspectionMigrationServices getAppInspectionMigrationServices();
-}
+ val appInspectionMigrationServices: AppInspectionMigrationServices
+} \ No newline at end of file
diff --git a/profilers/testSrc/com/android/tools/profilers/FakeIdeProfilerServices.java b/profilers/testSrc/com/android/tools/profilers/FakeIdeProfilerServices.java
index 2561730ad36..e508b1ffd83 100644
--- a/profilers/testSrc/com/android/tools/profilers/FakeIdeProfilerServices.java
+++ b/profilers/testSrc/com/android/tools/profilers/FakeIdeProfilerServices.java
@@ -50,7 +50,7 @@ import java.util.function.Supplier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-public final class FakeIdeProfilerServices implements IdeProfilerServices {
+public class FakeIdeProfilerServices implements IdeProfilerServices {
public static final String FAKE_ART_SAMPLED_NAME = "Sampled";