Skip to content
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

feat: release-profiler on web #44432

Merged
merged 21 commits into from
Jul 22, 2024

Conversation

kirillzyusko
Copy link
Contributor

@kirillzyusko kirillzyusko commented Jun 26, 2024

Details

Added an ability to profile web release apps.

Warning

You'll need to add 'Document-Policy': 'js-profiling' to responses to make profiler working.

Fixed Issues

$ #43363
PROPOSAL: N/A

Tests

  • Press cmd+d to open popup
  • Toggle "Use profiling"
  • Record interactions
  • Press cmd+d to open popup
  • Toggle "Use profiling"
  • symbolicate profiling trace
  • open is speedscope.app

Offline tests

N/A

QA Steps

N/A

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
    • MacOS: Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop

@kirillzyusko kirillzyusko changed the title feat: release-profiler on web [WIP] feat: release-profiler on web Jun 26, 2024
@kirillzyusko kirillzyusko changed the title [WIP] feat: release-profiler on web feat: release-profiler on web Jul 5, 2024
@kirillzyusko kirillzyusko marked this pull request as ready for review July 5, 2024 11:18
@kirillzyusko kirillzyusko requested a review from a team as a code owner July 5, 2024 11:18
@melvin-bot melvin-bot bot requested review from jayeshmangwani and removed request for a team July 5, 2024 11:18
Copy link

melvin-bot bot commented Jul 5, 2024

@jayeshmangwani Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@jayeshmangwani
Copy link
Contributor

@kirillzyusko Unit tests are failing in the PR.

@kirillzyusko
Copy link
Contributor Author

@jayeshmangwani thank you for pointing it out! I fixed that!

@jayeshmangwani
Copy link
Contributor

@kirillzyusko IMO, the share option here should be for the native platforms (Android and iOS) only. We are doing the same with the Share logs option too.
Screenshot 2024-07-08 at 6 53 09 PM

@kirillzyusko
Copy link
Contributor Author

@jayeshmangwani do you want to rename "Share" to "Download"? Or do you want to remove that button at all?

If we remove and will start automatic download, then I'm not sure such concurrent downloads will be handled correctly 🤔

@jayeshmangwani
Copy link
Contributor

Or do you want to remove that button at all?

I was thinking of removing it, as the Use profiling toggle should work the same way as the Client side logging toggle. When disabled, we download the file on web/desktop and display the Share button on native devices. However, I'm not entirely sure about this. @muttmuure Can you please suggest what you think about showing the Share button?

@jayeshmangwani
Copy link
Contributor

@kirillzyusko We will proceed with the existing functionality added in the PR. The Profiling Share button for the web/desktop will download the file. We also need the same functionality for client-side logging. If possible, can we please add a share button to client logs in this PR that downloads the file?

@kirillzyusko
Copy link
Contributor Author

If possible, can we please add a share button to client logs in this PR that downloads the file?

@jayeshmangwani I added it here: c2d7c31

However I think it's slightly incorrect... This button on web:

image

will trigger a download of additional App_info file that has following content:

{
    "appVersion": "9.0.4-7",
    "environment": "development",
    "platform": "web",
    "totalMemory": "7.45 GiB",
    "usedMemory": "1.36 GiB"
}

This file is an additional file for profiler stack trace, but it's not mandatory - and thus we give user an ability to download it on demand. But the trace file will be downloaded automatically.

So... Should I revert changes that I made? 😅

@jayeshmangwani
Copy link
Contributor

So... Should I revert changes that I made? 😅

😅 In my opinion, when we press the Profile Trace Share button, the Profile_trace_for_9.0.6-1.cpuprofile and _App_Info_9.0.6-1.json files should be downloaded (similar to iOS)

@kirillzyusko
Copy link
Contributor Author

😅 In my opinion, when we press the Profile Trace Share button, the Profile_trace_for_9.0.6-1.cpuprofile and _App_Info_9.0.6-1.json files should be downloaded (similar to iOS)

@jayeshmangwani the small problem here is that react-native-profiler-release had following API stopProfiling(saveToDownloads) -> pathToDownloads. And such API allowed you to re-use existing file.

But the problem is that in browser we don't have a direct access to FS, so we have to download file (and we can do that only once - at least that' how we designed the API): https://github.com/margelo/react-native-release-profiler/blob/80ff24f4ad7354c0b04047ed59e915735b986ea1/src/index.web.tsx#L84-L90

I'll be glad to unify the approach across platforms, but we need to keep in mind, that browser doesn't have FS nad Share API, so we are polyfilling them here 🤷‍♂️

@muttmuure
Copy link
Contributor

That makes sense, it would be nice to have consistency across platforms but I think we can live without it if it means getting this out

@kirillzyusko
Copy link
Contributor Author

@muttmuure @jayeshmangwani so, should I revert changes that I made for "client-side logging" functionality? Or we can review the PR with these changes?

@jayeshmangwani
Copy link
Contributor

@kirillzyusko For the web: I think we should hide the share option for Profile Trace, as the share button does not download the profiling file but instead downloads the App_info file.

For 'client-side logging,' we should keep the share button, as it downloads the file correctly.

@kirillzyusko
Copy link
Contributor Author

@jayeshmangwani got you - re-worked the code so that it meets your expectations 😊

@jayeshmangwani
Copy link
Contributor

@kirillzyusko Thanks for making the changes 🙏

Do we have to do any extra steps to load a file in speedscope.app? I captured a file on the web and tried to open it, but I'm getting a warning: Unrecognized format! See documentation about supported formats.

Screenshot 2024-07-16 at 1 05 28 AM

File:
test.cpuprofile

const [sharePath, setSharePath] = useState('');
const [totalMemory, setTotalMemory] = useState(0);
const [usedMemory, setUsedMemory] = useState(0);
const {translate} = useLocalize();

// eslint-disable-next-line @lwc/lwc/no-async-await
const stop = useCallback(async () => {
const path = await stopProfiling(getPlatform() === CONST.PLATFORM.IOS);
setPathIOS(path);
const path = await stopProfiling(getPlatform() === CONST.PLATFORM.IOS || getPlatform() === CONST.PLATFORM.WEB, newFileName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the condition getPlatform() === CONST.PLATFORM.WEB here?

For stopProfiling true/false both values are downloading the file in the Downloads folder for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, gotcha. I was suggesting that to avoid the platform-specific code in the file, though we can pass the saveToDownloads value from the platform-specific files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though we can pass the saveToDownloads value from the platform-specific files

Should I re-work this part as you are suggesting? 👀

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine here. We were already using getPlatform() === CONST.PLATFORM.IOS. Sorry for the confusion. Please leave it as it is for now.

@kirillzyusko
Copy link
Contributor Author

Do we have to do any extra steps to load a file in speedscope.app? I captured a file on the web and tried to open it, but I'm getting a warning: Unrecognized format! See documentation about supported formats.

@jayeshmangwani Yes, you need to run npm run symbolicate-release:web and it'll convert from Hermes stacktrace format to Google Chrome format 👀

Copy link
Contributor

@stitesExpensify stitesExpensify left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@stitesExpensify stitesExpensify merged commit cec2514 into Expensify:main Jul 22, 2024
18 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/stitesExpensify in version: 9.0.11-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

francoisl added a commit that referenced this pull request Jul 23, 2024
…on-web"

This reverts commit cec2514, reversing
changes made to 485332d.
srikarparsi added a commit that referenced this pull request Jul 23, 2024
[CP Staging] Revert "Merge pull request #44432 from margelo/feat/release-profiler-on-web"
OSBotify pushed a commit that referenced this pull request Jul 23, 2024
[CP Staging] Revert "Merge pull request #44432 from margelo/feat/release-profiler-on-web"

(cherry picked from commit 29cc7c1)
@OSBotify
Copy link
Contributor

🚀 Cherry-picked to staging by https://github.com/francoisl in version: 9.0.11-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes.

try {
const data = await fs.promises.readFile(resolvedPath);
callback({
mimeType: 'text/html',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I believe this may have caused issue #46048 by overriding the Content-Type response header for non-html responses.

kirillzyusko added a commit to margelo/expensify-app-fork that referenced this pull request Jul 24, 2024
…release-profiler-on-web""

This reverts commit d50f007.
@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/francoisl in version: 9.0.11-5 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/stitesExpensify in version: 9.0.12-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@kirillzyusko kirillzyusko mentioned this pull request Jul 25, 2024
48 tasks
@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/stitesExpensify in version: 9.0.13-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

kirillzyusko added a commit to margelo/expensify-app-fork that referenced this pull request Jul 31, 2024
…release-profiler-on-web""

This reverts commit d50f007.
kirillzyusko added a commit to margelo/expensify-app-fork that referenced this pull request Aug 2, 2024
…release-profiler-on-web""

This reverts commit d50f007.
@OSBotify
Copy link
Contributor

OSBotify commented Aug 6, 2024

🚀 Deployed to staging by https://github.com/stitesExpensify in version: 9.0.17-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Aug 7, 2024

🚀 Deployed to production by https://github.com/marcaaron in version: 9.0.17-2 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

2 similar comments
@OSBotify
Copy link
Contributor

OSBotify commented Aug 8, 2024

🚀 Deployed to production by https://github.com/marcaaron in version: 9.0.17-2 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Aug 8, 2024

🚀 Deployed to production by https://github.com/marcaaron in version: 9.0.17-2 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants