Commit Graph

44 Commits

Author SHA1 Message Date
wenzhao.yin 50141f9d3f fix RCTPerfMonitor display unit error
Summary:The  RCTPerformanceLogger log the time in ms not us. Especially the unit of RCTPLBundleSize is byte.
Closes https://github.com/facebook/react-native/pull/5919

Differential Revision: D2982116

Pulled By: nicklockwood

fb-gh-sync-id: 18aad5ff2eb83c6f302b2c10382bf214b51df133
shipit-source-id: 18aad5ff2eb83c6f302b2c10382bf214b51df133
2016-02-26 04:54:32 -08:00
Nick Lockwood 0427c3d273 Added throttling on requests made by RCTImageLoader
Reviewed By: javache

Differential Revision: D2938143

fb-gh-sync-id: bac1185d4792dcca0012905126c9ef2aa45905d5
shipit-source-id: bac1185d4792dcca0012905126c9ef2aa45905d5
2016-02-16 12:42:34 -08:00
Pieter De Baets 84f51da123 Make JS async always the top thread in systrace
Reviewed By: tadeuzagallo

Differential Revision: D2905828

fb-gh-sync-id: b64cbe6b41771dc94d8d7e6d3610af845b4383f0
shipit-source-id: b64cbe6b41771dc94d8d7e6d3610af845b4383f0
2016-02-12 03:50:35 -08:00
Tadeu Zagallo c00049ce4f Expose flow events to JS + add JS -> Native flows
Summary:
public

Expose JS hooks to create flow events in systrace (the nice arrows to show async work flow) +
add support to the showing all the work enqueued from the JS thread as added in D2743733

Depends on D2743733

Reviewed By: jspahrsummers

Differential Revision: D2815293

fb-gh-sync-id: 4278f61a67a6e78cf2704bacce34b1389328c6df
2016-02-08 07:07:34 -08:00
Christopher Chedeau 58738483ab Stop spamming the logs
Summary:
We should have 0 logs at startup. In theory it could be useful to know if the profiler is enabled, but in practice 99% of the time you don't care and it ends up spamming you for no good reason. Then more people add logs and not only do the logs are not useful, they prevent people from actually using them when debugging.
Closes https://github.com/facebook/react-native/pull/5766

Reviewed By: svcscm

Differential Revision: D2902987

Pulled By: androidtrunkagent

fb-gh-sync-id: d47f8e58edf5f2c8e2a7a4373fd7d9036d2309a0
2016-02-04 15:33:35 -08:00
Pieter De Baets 41f5a21b56 Improve systrace markers
Reviewed By: jspahrsummers

Differential Revision: D2851737

fb-gh-sync-id: 4aa0872e7d56d59de2fa42b87a795b2d64e0faa0
2016-02-03 07:11:35 -08:00
Nick Lockwood 7419a82bd7 Handle bad JSON data without crashing
Summary:
public
NSJSONSerialization throws an exception when it encounters bad JSON data, including NaN values, which may not be a programming error.

This diff adds code to catch those exceptions and convert to an error. Also, if no error handling is in place, RCTJSONStringify will now display a redbox, and attempt to recover by sanitizing the JSON data and retrying.

Reviewed By: javache

Differential Revision: D2854778

fb-gh-sync-id: 18e6990af0d91083496d6a0b75c31a94ed9454a5
2016-01-26 06:13:29 -08:00
Tadeu Zagallo 473f9bca19 Update createView C function on profiler
Summary:
public

The props argument of the `-[RCTComponentData createView:props:]` method was removed,
but the C function used to swizzle it in the profiler wasn't updated.

Reviewed By: majak

Differential Revision: D2811228

fb-gh-sync-id: 8896638c77370142e29913b5fb80e7fd748254b5
2016-01-07 12:03:38 -08:00
Fada Chen 18cdead76b revert D2773664
Reviewed By: dwitte

Differential Revision: D2802582

fb-gh-sync-id: 39d59be297f0f23e6a4e40175ad30284766349cb
2016-01-04 23:52:51 -08:00
Tadeu Zagallo 89ae0e040d Expose flow events to JS + add JS -> Native flows
Summary:
public

Expose JS hooks to create flow events in systrace (the nice arrows to show async work flow) +
add support to the showing all the work enqueued from the JS thread as added in D2743733

Depends on D2743733

Reviewed By: jspahrsummers

Differential Revision: D2773664

fb-gh-sync-id: 4a8854b17b4741b882f5f2cc425e4237a5e4b3eb
2016-01-04 11:11:48 -08:00
Nick Lockwood d7ad393f22 Fix unused argument warnings
Reviewed By: milend

Differential Revision: D2795407

fb-gh-sync-id: 83f5cc10b115eef3becb4ebab56b366f1a12a3ad
2015-12-30 14:16:29 -08:00
Tadeu Zagallo 809627379b Rename RCTContextExecutor to RCTJSCExecutor
Summary:
public

Rename the executor to so it actually says something about the implementation.

Reviewed By: jspahrsummers, nicklockwood

Differential Revision: D2759688

fb-gh-sync-id: 5b1ac447e75109fbbc2ee71c804710d9926785aa
2015-12-16 02:51:28 -08:00
Nick Lockwood f7edcda5d7 Deprecated RCTDidCreateNativeModules notification
Summary:
public

Thanks to the new lazy initialization system for modules, `RCTDidCreateNativeModules` no longer does what the name implies.

Previously, `RCTDidCreateNativeModules` was fired after all native modules had been initialized. Now, it simply fires each time the bridge is reloaded. Modules are created on demand when they are needed, so most of the assumptions about when `RCTDidCreateNativeModules` will fire are now incorrect.

This diff deprecates `RCTDidCreateNativeModules`, and adds a new notification, `RCTDidInitializeModuleNotification`, which fires each time a module a new module is instantiated.

If you need to access a module at any time you can just call `-[bridge moduleForClass:]` and the module will be instantiated on demand. If you want to access a module *only* after it has already been instantiated, you can use the `RCTDidInitializeModuleNotification` notification.

Reviewed By: tadeuzagallo

Differential Revision: D2755036

fb-gh-sync-id: 25bab6d5eb6fcd35d43125ac45908035eea01487
2015-12-15 05:43:33 -08:00
Tadeu Zagallo 2d61dfd9c1 Replace private bridge categories with private header
Summary:
public

A lot of the core modules have to use private methods in the bridge, specially
since the `RCTBatchedBridge` interface is never exposed. That was leading to a
lot of different private bridge categories spread across different modules,
which makes harder to identify which modules are affected by private API changes.

Replace all the categories with a single private header.

Reviewed By: nicklockwood

Differential Revision: D2757564

fb-gh-sync-id: 793158b9082d542b74a6094ed0db4d5dc3a88f78
2015-12-15 05:40:27 -08:00
Milen Dzhumerov 2ac0157a24 Improve error message when profiler data cannot be uploaded
Summary:
Improve error message when profiling data cannot be sent to the packager

public

Reviewed By: tadeuzagallo

Differential Revision: D2749489

fb-gh-sync-id: 26bd56d05be5f3579e45c2407974dd2b885460fc
2015-12-15 03:58:28 -08:00
Milen Dzhumerov 0fe50055c4 Introduce JSC profiler API
Summary:
Extract JSC profiler API which can now be used even if profiler is unavailable.

public

Reviewed By: tadeuzagallo

Differential Revision: D2749217

fb-gh-sync-id: 1ffa6f37323ea0ddbda3fdacfdf8a9b360185b2e
2015-12-15 03:12:32 -08:00
Tadeu Zagallo 230c180a12 Add profiler hooks to views
Summary:
public

The profiler currently only hooks into bridge modules, extend it so we also
log method calls on views.

Reviewed By: jspahrsummers

Differential Revision: D2755213

fb-gh-sync-id: e8ff224eec08898340d05e104772ff1626538bd5
2015-12-14 13:08:29 -08:00
Tadeu Zagallo b6fce4ad52 Prevent the profiler from hooking into stret methods
Summary:
public

In order to handle methods that returns struct in i386 and x86_64 we'd need to implement special methods (like objc_msgSend_stret),
but we'll just bail out for now, since there's very few usages.

Reviewed By: jspahrsummers

Differential Revision: D2754732

fb-gh-sync-id: d3585d244633d918770ef79a52dee9cdf87a53da
2015-12-14 07:12:32 -08:00
Dave Sibiski b78b8f6cab Fixes grammar in comment
Summary: Closes https://github.com/facebook/react-native/pull/4726

Reviewed By: svcscm

Differential Revision: D2748499

Pulled By: androidtrunkagent

fb-gh-sync-id: cbc6bc7b6692191bc68b8e1782897d17bc01bfa3
2015-12-10 22:52:32 -08:00
Tadeu Zagallo cd4574498d Use actual CADisplayLink timestamp for VSYNC
Summary:
public

Use the actual timestamp provided through `CADisplayLink` instead of the time
the handler is called.

Reviewed By: jspahrsummers

Differential Revision: D2739121

fb-gh-sync-id: 1da28190bb25351dc3dd94efaff21d49279a570f
2015-12-09 09:56:27 -08:00
Tadeu Zagallo 02ded6d0bb Preserve all return registers on x86_64 trampoline
Summary:
public

Only the first quad-word and floating point return registers were being preserved,
make sure to preserve the 2nd ones as well (`%rdx` and `%xmm1`)

Reviewed By: jspahrsummers

Differential Revision: D2727523

fb-gh-sync-id: d8176512d2dfb5f664f634ecaaf34510515506ea
2015-12-07 06:43:28 -08:00
Tadeu Zagallo a7e2059c15 Fix class pair register on reload
Summary: public

It was possible after reload to detach from the new instance, removing the markers.

Reviewed By: jspahrsummers

Differential Revision: D2696208

fb-gh-sync-id: ad8f5d449f51c7c74a20ae7c0cafc4fc786ea390
2015-11-26 07:27:27 -08:00
Tadeu Zagallo ea96a7edb8 Avoid dispatch_async on RCTProfile when not profiling
Summary: public

Fixes #3953

Bail out soon when the profiler is not running + move string formating into the macro so that it happens in a background queue.

Reviewed By: jspahrsummers

Differential Revision: D2696167

fb-gh-sync-id: a1b91ee4459078ab9a4c0be62bd23362ec05e208
2015-11-26 04:11:28 -08:00
Nick Lockwood 060664fd3d Refactored module access to allow for lazy loading
Summary: public

The `bridge.modules` dictionary provides access to all native modules, but this API requires that every module is initialized in advance so that any module can be accessed.

This diff introduces a better API that will allow modules to be initialized lazily as they are needed, and deprecates `bridge.modules` (modules that use it will still work, but should be rewritten to use `bridge.moduleClasses` or `-[bridge moduleForName/Class:` instead.

The rules are now as follows:

* Any module that overrides `init` or `setBridge:` will be initialized on the main thread when the bridge is created
* Any module that implements `constantsToExport:` will be initialized later when the config is exported (the module itself will be initialized on a background queue, but  `constantsToExport:` will still be called on the main thread.
* All other modules will be initialized lazily when a method is first called on them.

These rules may seem slightly arcane, but they have the advantage of not violating any assumptions that may have been made by existing code - any module written under the original assumption that it would be initialized synchronously on the main thread when the bridge is created should still function exactly the same, but modules that avoid overriding `init` or `setBridge:` will now be loaded lazily.

I've rewritten most of the standard modules to take advantage of this new lazy loading, with the following results:

Out of the 65 modules included in UIExplorer:

* 16 are initialized on the main thread when the bridge is created
* A further 8 are initialized when the config is exported to JS
* The remaining 41 will be initialized lazily on-demand

Reviewed By: jspahrsummers

Differential Revision: D2677695

fb-gh-sync-id: 507ae7e9fd6b563e89292c7371767c978e928f33
2015-11-25 04:49:45 -08:00
Tadeu Zagallo 789b5708ec Fix arch macro on profiler
Summary: public

Bad typo in `RCTProfile.m`, was using `__x86__` instead of the right one `__i386__`.

Reviewed By: jspahrsummers

Differential Revision: D2690557

fb-gh-sync-id: 537eb0502f5df22cd93665cabfddeead12cad9db
2015-11-24 06:50:10 -08:00
Tadeu Zagallo 659cc005ad Restore VSYNC markers on RCTProfile
Summary: public

The VSYNC markers got lost at some point when refactoring RCTBatchedBridge, restore it, but keep it in RCTProfile.

Reviewed By: jspahrsummers

Differential Revision: D2685805

fb-gh-sync-id: 1acad330de7baf004a83b41f90ba4b6532605de6
2015-11-23 09:50:30 -08:00
Nick Lockwood fa0b45c58b Replaced RCTSparseArray with NSDictionary
Reviewed By: jspahrsummers

Differential Revision: D2651920

fb-gh-sync-id: 953e2ea33abfc7a3a553da95b13e9ab2bccc5a1c
2015-11-14 10:28:28 -08:00
Tadeu Zagallo 0b5b0f9016 Move string transform from Tramponline to Profiler Queue
Summary: public

`RCTProfileTrampoline` (and consequently `RCTProfileTrampoline(Start|End)`) should be as lightweight
as possible, since it's called for every BridgeModule's method invocation, so
avoid doing any string processing there by dispatching it to Profiler queue.

Reviewed By: jspahrsummers

Differential Revision: D2625918

fb-gh-sync-id: 86a98d4cf727c3be20eebee0bf8437c502c6a42a
2015-11-09 08:43:35 -08:00
Tadeu Zagallo e5b843834d Rename RCTProfile(Begin|End)Event
Summary: public

Rename it to `RCT_PROFILE_(BEGIN|END)_EVENT` to make it clearer that it's a macro,
since it has special behaviours.

Reviewed By: jspahrsummers

Differential Revision: D2631542

fb-gh-sync-id: 629c139462c4aa3582f719b14482017d13676e33
2015-11-09 08:43:29 -08:00
Tadeu Zagallo fdbc1e03de Use barrier to write flag
Summary: public

Use OSAtomicBarrier to write the flags rather than using OSAtomic to read *and* write.

Reviewed By: jspahrsummers

Differential Revision: D2625915

fb-gh-sync-id: 2ed357ae408b2afe5ef2689582585bf4f9edd8a7
2015-11-09 08:03:26 -08:00
Tadeu Zagallo e1fa325569 Change async events' cookie to NSUInteger
Summary: public

As jspahrsumemrs pointed out, `int` could overflow pretty easy, since it was static,
change it to an NSUInteger and downcast it when need to interop.

Reviewed By: jspahrsummers

Differential Revision: D2625902

fb-gh-sync-id: 2052be47a7b0ed81484da004fa18d6ef5baf26f7
2015-11-08 10:20:29 -08:00
Tadeu Zagallo 1f0d48a0e4 Guard from hooking modules twice
Summary: public

The dev menu is a little bit flaky right now, and sometimes it emits messages twice,
so guard it not to hook into the modules twice.

Reviewed By: jspahrsummers

Differential Revision: D2625911

fb-gh-sync-id: 18fd6bc00e473ed226291e7aca4a02cec84bfc8f
2015-11-07 13:47:27 -08:00
Tadeu Zagallo 0c74804427 Use dispatch_async instead of lock
Summary: public

The initial implementation used a lock to manage the stored profile information,
blocking the caller thread for longer than it should. Replace it with a private
queue, since the only thing we need to from the caller is to record the immediate
call time and the caller thread/queue, all the rest has absolutely no priority.

Use macros to also defer work done when generate the name of the events.

Reviewed By: nicklockwood

Differential Revision: D2603120

fb-gh-sync-id: e3e36160c893e7ae9ed3558f07c854ea76396661
2015-11-04 09:03:01 -08:00
Nick Lockwood c5b990f65f Added lightweight generic annotations
Summary: public

Added lightweight genarics annotations to make the code more readable and help the compiler catch bugs.

Fixed some type bugs and improved bridge validation in a few places.

Reviewed By: javache

Differential Revision: D2600189

fb-gh-sync-id: f81e22f2cdc107bf8d0b15deec6d5b83aacc5b56
2015-11-03 14:49:30 -08:00
Tadeu Zagallo 6532290397 Guard against dev menu calling twice
Summary: public

The Dev Menu is for some reason eventually calling twice the callbacks, guard
against it while we don't fix it.

Reviewed By: nicklockwood

Differential Revision: D2600470

fb-gh-sync-id: 50c622d2ab64ce50d51572dbfcc076c2765ce582
2015-11-03 07:24:28 -08:00
Tadeu Zagallo 63015b911c Explicitly cast the trampoline prototype to IMP
Summary: public

Add explicitly cast to the trampoline prototype to silence warnings.

Reviewed By: javache

Differential Revision: D2605779

fb-gh-sync-id: e208b69236c1b87bb1374ee493840ea5f47b371c
2015-11-02 10:51:48 -08:00
Tadeu Zagallo ccd90e25c1 Convert remaining uses of alloc] init] to new]
Summary: public

We moved to using `new` instead of `alloc] init` but there was still some calls
left.

Reviewed By: javache

Differential Revision: D2604679

fb-gh-sync-id: ff7300ecbedb55dd5e93873592598810c9b87808
2015-11-02 08:03:17 -08:00
Tadeu Zagallo 287e0e3c49 Add RCTPerformanceLogger data to PerfMonitor
Summary: public

Add information the times recorded by RCTPerformanceLogger to RCTPerfMonitor,
tap the monitor to show a table view with the data.

Reviewed By: jspahrsummers

Differential Revision: D2595372

fb-gh-sync-id: dc3b73af71b6d7f258e4e5991116bbc6cedc21fb
2015-10-30 16:57:30 -07:00
Tadeu Zagallo 010380cca6 Fix CPU profiler upload
Summary: public

Changes were made on the packager that broke the CPU profile upload route,
fix it.

Reviewed By: martinbigio

Differential Revision: D2585184

fb-gh-sync-id: 206744f92d403d6851a69891dfac0c4c11bf1b7e
2015-10-30 14:46:00 -07:00
Tadeu Zagallo 8185b203be Preserve xmm registers on x86_64
Summary: public

`%xmm` registers weren't being preserved what would cause eventual weird issues
for methods using floats / doubles / etc.

Reviewed By: jspahrsummers

Differential Revision: D2581358

fb-gh-sync-id: 701498def0f05716c665f4749e5154b828bf41ec
2015-10-28 05:35:25 -07:00
Tadeu Zagallo 0f92639a96 Prevent RCTProfileTrampoline from getting stripped
Summary: public

I was using `dlsym` as a more elegant way of checking if the function was defined
to prevent crashes if running on an unsupported architecture, but Xcode might
strip the symbol, even with `.no_dead_strip`, if there's no references to the
compilation unit at all.

Replace it with an ugly `#if` that checks if it's any of the supported targets
and extern the function prototype.

Reviewed By: jspahrsummers

Differential Revision: D2581143

fb-gh-sync-id: b004ed351de97f96c04b4a6c914ce55cfcbbbcbb
2015-10-27 13:03:28 -07:00
Tadeu Zagallo a044ade333 Update button and add comments to Perf Monitor
Summary: public

Rename the dev menu button and add comments to the private method
used.

Reviewed By: ndfred

Differential Revision: D2576599

fb-gh-sync-id: cd5cde7562dcbc243663ac68d2b9cac5c0a984ab
2015-10-24 14:03:27 -07:00
Tadeu Zagallo 9069bdf1c2 Introduce Perf Monitor
Summary: public

Kill `RCTPerfStats` and introduce the new `RCTPerfMonitor`, including memory
usage, JSC heap size, number of RN views in screen, FPS (both on UI and JS threads)
and more to come.

It removes all the previous traces that were previous spread across the bridge
and the dev menu and moves everything to be more contained, so the whole thing
can be safely striped in production.

Reviewed By: nicklockwood

Differential Revision: D2575158

fb-gh-sync-id: 6a6d0c4422adbddeeefddd32ec3409a7095ff2a9
2015-10-23 10:56:56 -07:00
Tadeu Zagallo 89c1747c33 Implement asm trampoline rather forwardInvocation
Summary: public

The profiler overrides all the methods of all the BridgeModules, and in order to
`start` and `end` the profiler at the function invocation time it used `NSInvocation`,
which is slow.

Replace it with a simple assembly method based on `objc_msgSend`.

Reviewed By: jspahrsummers

Differential Revision: D2550807

fb-gh-sync-id: 88ca08f9d6bfcd3035bda9304c93566c8818b46f
2015-10-20 04:14:09 -07:00