mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Move files from packager/ to local-cli
Summary: public This is not only to put the files on a place where it makes more sense but also to allow to use ES6 features on them as `/packager` is not whitelisted on `babel`. Reviewed By: mkonicek Differential Revision: D2577267 fb-gh-sync-id: b69a17c0aad349a3eda987e33d1778d97a8e1549
This commit is contained in:
committed by
facebook-github-bot-3
parent
f87d2e15bd
commit
bcf762af60
47
local-cli/server/middleware/cpuProfilerMiddleware.js
Normal file
47
local-cli/server/middleware/cpuProfilerMiddleware.js
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const execFile = require('child_process').execFile;
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = function(req, res, next) {
|
||||
if (req.url !== '/cpu-profile') {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Dumping CPU profile information...');
|
||||
var dumpName = '/tmp/cpu-profile_' + Date.now();
|
||||
fs.writeFileSync(dumpName + '.json', req.rawBody);
|
||||
|
||||
var cmdPath = path.join(
|
||||
__dirname,
|
||||
'../react-native-github/JSCLegacyProfiler/json2trace'
|
||||
);
|
||||
execFile(
|
||||
cmdPath,
|
||||
[
|
||||
'-cpuprofiler',
|
||||
dumpName + '.cpuprofile ' + dumpName + '.json'
|
||||
],
|
||||
function(error) {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
res.end('Unknown error: ' + error.message);
|
||||
} else {
|
||||
var response = 'Your profile was generated at\n\n' + dumpName + '.cpuprofile\n\n' +
|
||||
'Open `Chrome Dev Tools > Profiles > Load` and select the profile to visualize it.';
|
||||
console.log(response);
|
||||
res.end(response);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user