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

[DevTools] RFC: log profiling events under __PROFILE__ flag #22167

Closed
wants to merge 2 commits into from

Conversation

jstejada
Copy link
Contributor

Summary

This commit is being used as proposal for adding a logger (EventLogger) that records events happening in the DevTools runtime. In particular, this code was used for collecting profiling data to measure the performance of parseHookNames.

The current EventLogger can be extended to log and collect different types of events that we can statically enforce with Flow (e.g. for performance metrics, or for other relevant product measurements), and which can then be accessed by various means. Right now, they are just stored in a global constant, but in the future they could be logged to other logging systems (e.g. external logging systems).

Note that when __PROFILE__ flag is disabled, all of the event logging will be disabled and stripped from the build.

Test Plan

  • yarn flow
  • yarn test
  • yarn test-build-devtools
  • used this code to collect performance data for parseNamedHooks.

@@ -10,6 +10,9 @@
// Flip this flag to true to enable verbose console debug logging.
export const __DEBUG__ = false;

// Flip this flag to true to enable performance logging to console.
export const __PROFILE__ = false;
Copy link
Contributor

@bvaughn bvaughn Aug 24, 2021

Choose a reason for hiding this comment

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

Don't have time to review this full PR now, but a quick thought: The __PROFILE__ flag has a specific meaning for React builds already. (There's even a global __PROFILE__ flag defined for DevTools too, in the Webpack configs.)

I think this functionality is a bit different. Maybe we should use a different name to avoid confusion?

@jstejada
Copy link
Contributor Author

oops, a few unrelated changes got added to this PR (some refactoring of the calls to originalPositionFor) it's still good to take a look but i'll split those up

@facebook facebook deleted a comment from supinda2499 Aug 24, 2021
import type {SourceConsumer} from '../astUtils';

const MAX_SOURCE_LENGTH = 100_000_000;

if (__PROFILE__) {
global.__loggerEvents = [];
Copy link
Contributor

@bvaughn bvaughn Aug 24, 2021

Choose a reason for hiding this comment

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

I'm wondering why we are using a global here?

Seems like we could use our feature flag system to create a proper logging (enabled for Facebook builds only) that could batch and flush these to some internal logging system.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah the global was just for manual testing purposes. we don't have to land this global, but i would imagine as a follow up we would do this:

Seems like we could use our feature flag system to create a proper logging (enabled for Facebook builds only) that could batch and flush these to some internal logging system.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough! Works fine for a POC 😁

I think I'd probably want to do this design work as part of the initial PR rather than a follow up though.

@@ -104,12 +128,73 @@ const originalURLToMetadataCache: LRUCache<
},
});

function withSyncProfiling<TReturn>(
Copy link
Contributor

Choose a reason for hiding this comment

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

This function and the withCallbackProfiling function below could be part of such a logger. (Maybe non-Facebook builds would just get a no-op logger that does nothing.)

@supinda2499
Copy link

supinda2499 commented Aug 25, 2021 via email

@jstejada
Copy link
Contributor Author

jstejada commented Sep 9, 2021

abandoning in favor of #22276

@jstejada jstejada closed this Sep 9, 2021
@jstejada jstejada deleted the profiling branch September 10, 2021 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants