-
Notifications
You must be signed in to change notification settings - Fork 0
Add profiler plugin for each platform #15
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
+5,493
−1,672
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
879b0ef
rewrite profiler plugin. add kotlin implementation
tmarmer 5af5769
fix build issues for profiler plugin
tmarmer 31e5ec6
fix mobile profiler plugin. update profiler plugin view to use flame …
tmarmer ff03e75
add basic rendering for profiler data
tmarmer 95ed927
centralize getNowTime and mock its usage
tmarmer 2ee169e
return to using rootNode in plugin. code cleanup
tmarmer 095f297
add raw data tab to profiler plugin
tmarmer 934ca81
add clear option for profiler
tmarmer 12966c1
split swift implementation into swiftui and ios plugins
tmarmer 05fcf05
update snapshots and fix lint issues
tmarmer 2032182
reorganize helper functions in profiler plugin
tmarmer 6241156
bump codecov orb to 6.0.0 and remove commented android orb
sugarmanz 1800f0c
fix incorrect plugin target refs in profiler ios/swiftui BUILD
sugarmanz 2f58791
author profiler flow as DSL content package
sugarmanz 9d4d682
add android profiler plugin
sugarmanz e0b5b1b
fix profiler iOS module imports and SPM targets
sugarmanz 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
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,3 @@ | ||
| export const getNowTime = globalThis.performance | ||
| ? () => globalThis.performance.now() | ||
| : () => Date.now(); | ||
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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export { generateUUID } from "./uuid"; | ||
| export { genDataChangeTransaction } from "./genDataChangeTransaction"; | ||
| export { getNowTime } from "./getNowTime"; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Android lib that consumes jvm similar to how react consumes core | ||
| load("@rules_jvm_external//:defs.bzl", "artifact") | ||
| load("//helpers:android.bzl", "kt_android") | ||
|
|
||
| main_exports = [ | ||
| "//devtools/plugin/android:plugin-android", | ||
| ] | ||
|
|
||
| main_deps = main_exports + [ | ||
| "//devtools/plugins/profiler/jvm:profiler-plugin", | ||
| ] | ||
|
|
||
| main_resources = [] | ||
|
|
||
| test_deps = [ | ||
| "//helpers:kotlin_serialization", | ||
| artifact("com.intuit.playerui:testutils"), | ||
| artifact("com.intuit.playerui:j2v8-all"), | ||
| ] | ||
|
|
||
| kt_android( | ||
| name = "profiler-android", | ||
| group = "com.intuit.playerui.plugins.devtools.profiler", | ||
| main_deps = main_deps, | ||
| main_exports = main_exports, | ||
| main_resources = main_resources, | ||
| unit_test_deps = test_deps, | ||
| unit_test_package = "com.intuit.playerui.plugins.devtools.profiler", | ||
| ) | ||
|
|
||
| alias( | ||
| name = "android", | ||
| actual = "profiler-android", | ||
| ) |
14 changes: 14 additions & 0 deletions
14
devtools/plugins/profiler/android/src/main/AndroidManifest.xml
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,14 @@ | ||
| <manifest package="com.intuit.playerui.plugins.devtools.profiler" | ||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools"> | ||
|
|
||
| <uses-sdk android:minSdkVersion="24" /> | ||
|
|
||
| <!-- Resolve a conflict issue while building with Bazel. --> | ||
| <application> | ||
| <provider | ||
| android:name="androidx.startup.InitializationProvider" | ||
| android:authorities="${applicationId}.androidx-startup" | ||
| tools:node="remove" /> | ||
| </application> | ||
| </manifest> |
29 changes: 29 additions & 0 deletions
29
...ain/kotlin/com/intuit/playerui/plugins/devtools/profiler/ProfilerAndroidDevtoolsPlugin.kt
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,29 @@ | ||
| package com.intuit.playerui.plugins.devtools.profiler | ||
|
|
||
| import androidx.annotation.StyleRes | ||
| import com.intuit.playerui.android.AndroidPlayer | ||
| import com.intuit.playerui.core.bridge.runtime.Runtime | ||
| import com.intuit.playerui.devtools.AndroidDevtoolsPlugin | ||
| import com.intuit.playerui.plugins.devtools.profiler.ProfilerDevtoolsPlugin.Module.ProfilerDevtoolsPlugin | ||
|
|
||
| public class ProfilerAndroidDevtoolsPlugin( | ||
| private val id: String, | ||
| @StyleRes private val overlayStyle: Int? = R.style.ProfilerAndroidDevtoolsPlugin, | ||
| ) : AndroidDevtoolsPlugin<ProfilerDevtoolsPlugin>() { | ||
| override fun Runtime<*>.buildCorePlugin(): ProfilerDevtoolsPlugin = | ||
| ProfilerDevtoolsPlugin( | ||
| ProfilerDevtoolsPlugin.Options(id, this@ProfilerAndroidDevtoolsPlugin), | ||
| ) | ||
|
|
||
| override fun apply(androidPlayer: AndroidPlayer) { | ||
| if (!checkIfDevtoolsIsActive()) return | ||
|
|
||
| super.apply(androidPlayer) | ||
|
|
||
| overlayStyle?.let(::listOf)?.let { | ||
| androidPlayer.hooks.context.tap(this::class.simpleName!!) { _, context -> | ||
| androidPlayer.getCachedStyledContext(context, it) | ||
| } | ||
| } | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
devtools/plugins/profiler/android/src/main/res/values/styles.xml
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,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <style name="ProfilerAndroidDevtoolsPlugin"> | ||
| <item name="android:background">#330000FF</item> | ||
| </style> | ||
| </resources> |
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,47 @@ | ||
| load("@npm//:defs.bzl", "npm_link_all_packages") | ||
| load("@rules_player//javascript:defs.bzl", "js_pipeline") | ||
| load("@rules_player//player:defs.bzl", "dsl_compile", create_base_dsl_config = "create_base_config") | ||
| load("//helpers:defs.bzl", "tsup_config", "vitest_config") | ||
|
|
||
| npm_link_all_packages(name = "node_modules") | ||
|
|
||
| tsup_config(name = "tsup_config") | ||
|
|
||
| vitest_config(name = "vitest_config") | ||
|
|
||
| create_base_dsl_config( | ||
| name = "dsl_config", | ||
| presets = [], | ||
| ) | ||
|
|
||
| entrypoint = ["src/flow.tsx"] | ||
|
|
||
| dsl_compile( | ||
| name = "compiled_flow", | ||
| srcs = entrypoint, | ||
| config = ":dsl_config", | ||
| data = glob( | ||
| ["src/**"], | ||
| entrypoint, | ||
| ) + [ | ||
| "//:node_modules/@devtools-ui/plugin", | ||
| "//:node_modules/@player-tools/dsl", | ||
| "//:node_modules/@player-ui/common-types-plugin", | ||
| "//:node_modules/react", | ||
| ], | ||
| input_dir = "src", | ||
| output_dir = "_generated", | ||
| skip_test = True, | ||
| ) | ||
|
|
||
| js_pipeline( | ||
| package_name = "@player-devtools/profiler-plugin-content", | ||
| srcs = [ | ||
| "src/constants.ts", | ||
| "src/index.ts", | ||
| ":compiled_flow", | ||
| ], | ||
| deps = [ | ||
| ":node_modules/@player-devtools/types", | ||
| ], | ||
| ) |
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,8 @@ | ||
| { | ||
| "name": "@player-devtools/profiler-plugin-content", | ||
| "version": "0.0.0-PLACEHOLDER", | ||
| "main": "src/index.ts", | ||
| "dependencies": { | ||
| "@player-devtools/types": "workspace:*" | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
devtools/plugins/profiler/content/src/common/ProfilerFooter.tsx
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,30 @@ | ||
| import React from "react"; | ||
| import { Collection, Action, Text } from "@devtools-ui/plugin"; | ||
| import { expression as e } from "@player-tools/dsl"; | ||
| import type { Expression } from "@player-tools/dsl"; | ||
| import { INTERACTIONS } from "../constants"; | ||
| import { bindings } from "../schema"; | ||
|
|
||
| const toggleProfiling = e`conditional(${bindings.profiling} === true, publish('${INTERACTIONS.STOP_PROFILING}'), publish('${INTERACTIONS.START_PROFILING}'))`; | ||
|
|
||
| const toggleLabel = e`conditional(${bindings.profiling} === true, 'Stop', 'Start')`; | ||
|
|
||
| const reset = e`publish('${INTERACTIONS.RESET_PROFILING}')`; | ||
|
|
||
| /** Shared footer with a Start/Stop toggle and a Reset action. */ | ||
| export const ProfilerFooter = ( | ||
| <Collection> | ||
| <Collection.Values> | ||
| <Action exp={toggleProfiling as Expression}> | ||
| <Action.Label> | ||
| <Text>{toggleLabel}</Text> | ||
| </Action.Label> | ||
| </Action> | ||
| <Action exp={reset as Expression}> | ||
| <Action.Label> | ||
| <Text>Reset</Text> | ||
| </Action.Label> | ||
| </Action> | ||
| </Collection.Values> | ||
| </Collection> | ||
| ); |
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,41 @@ | ||
| import React from "react"; | ||
| import { Navigation, Action, Text, StackedView } from "@devtools-ui/plugin"; | ||
| import { VIEWS_IDS } from "../constants"; | ||
|
|
||
| /** Display labels for the navigation actions, keyed by view id. */ | ||
| const NAV_LABELS: Record<string, string> = { | ||
| [VIEWS_IDS.PROFILE]: "Flame Graph", | ||
| [VIEWS_IDS.RAW]: "Raw", | ||
| }; | ||
|
|
||
| const Nav = () => ( | ||
| <Navigation> | ||
| <Navigation.Values> | ||
| {Object.values(VIEWS_IDS).map((viewId) => ( | ||
| <Action key={viewId} value={viewId}> | ||
| <Action.Label> | ||
| <Text>{NAV_LABELS[viewId] ?? viewId}</Text> | ||
| </Action.Label> | ||
| </Action> | ||
| ))} | ||
| </Navigation.Values> | ||
| </Navigation> | ||
| ); | ||
|
|
||
| export const Screen = ({ | ||
| main, | ||
| footer, | ||
| id, | ||
| }: { | ||
| id: string; | ||
| main: React.ReactNode; | ||
| footer?: React.ReactNode; | ||
| }) => ( | ||
| <StackedView id={id}> | ||
| <StackedView.Header> | ||
| <Nav /> | ||
| </StackedView.Header> | ||
| <StackedView.Main>{main}</StackedView.Main> | ||
| {footer && <StackedView.Footer>{footer}</StackedView.Footer>} | ||
| </StackedView> | ||
| ); |
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,2 @@ | ||
| export * from "./Screen"; | ||
| export * from "./ProfilerFooter"; |
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,12 @@ | ||
| export const PLUGIN_ID = "player-ui-profiler-plugin"; | ||
|
|
||
| export const VIEWS_IDS = { | ||
| PROFILE: "Profile", | ||
| RAW: "Raw", | ||
| }; | ||
|
|
||
| export const INTERACTIONS = { | ||
| START_PROFILING: "start-profiling", | ||
| STOP_PROFILING: "stop-profiling", | ||
| RESET_PROFILING: "reset-profiling", | ||
| }; |
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,19 @@ | ||
| import { PLUGIN_ID } from "./constants"; | ||
| import { navigation } from "./navigation"; | ||
| import { schema } from "./schema"; | ||
| import { views } from "./views"; | ||
|
|
||
| export default { | ||
| id: PLUGIN_ID, | ||
| views, | ||
| navigation, | ||
| schema, | ||
| data: { | ||
| profiling: false, | ||
| displayFlameGraph: false, | ||
| rootNode: { | ||
| value: 0, | ||
| }, | ||
| rawNodes: [], | ||
| }, | ||
| }; |
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,22 @@ | ||
| import type { PluginData } from "@player-devtools/types"; | ||
| import { PLUGIN_ID } from "./constants"; | ||
|
|
||
| // Generated via dsl_compile target | ||
| import flow from "../_generated/flow.json"; | ||
|
|
||
| declare global { | ||
| const __VERSION__: string; | ||
| } | ||
|
|
||
| const PLUGIN_VERSION = | ||
| typeof __VERSION__ !== "undefined" ? __VERSION__ : "unstamped"; | ||
|
|
||
| export const ProfilerPluginData: PluginData = { | ||
| id: PLUGIN_ID, | ||
| name: "Player UI Profiler", | ||
| description: "Standard Player UI Profiler", | ||
| version: PLUGIN_VERSION, | ||
| flow, | ||
| }; | ||
|
|
||
| export * from "./constants"; |
27 changes: 27 additions & 0 deletions
27
devtools/plugins/profiler/content/src/navigation/index.tsx
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 @@ | ||
| import { VIEWS_IDS } from "../constants"; | ||
|
|
||
| const transitions = Object.entries(VIEWS_IDS).reduce( | ||
| (acc, [key, value]) => ({ | ||
| ...acc, | ||
| [value]: key, | ||
| }), | ||
| {} as Record<string, string>, | ||
| ); | ||
|
|
||
| export const navigation = { | ||
| BEGIN: "Plugin", | ||
| Plugin: { | ||
| startState: Object.keys(VIEWS_IDS)[0], | ||
| ...Object.entries(VIEWS_IDS).reduce( | ||
| (acc, [key, value]) => ({ | ||
| ...acc, | ||
| [key]: { | ||
| state_type: "VIEW", | ||
| ref: value, | ||
| transitions, | ||
| }, | ||
| }), | ||
| {} as Record<string, unknown>, | ||
| ), | ||
| }, | ||
| }; |
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.
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.
performanceisn't available on the ios and kotlin integrations, so it's preferred for accuracy butDate.nowstill works.