@@ -30,7 +30,7 @@ Profiling.exposeProfiling = function(pmx, profiler_path) {
30
30
* Heap snapshot
31
31
*/
32
32
pmx . action ( 'km:heapdump' , function ( reply ) {
33
- var dump_file = path . join ( os . tmpDir ( ) , Date . now ( ) + '.heapsnapshot' ) ;
33
+ var dump_file = path . join ( os . tmpdir ( ) , Date . now ( ) + '.heapsnapshot' ) ;
34
34
35
35
var snapshot = profiler . takeSnapshot ( 'km-heap-snapshot' ) ;
36
36
var buffer = '' ;
@@ -64,7 +64,7 @@ Profiling.exposeProfiling = function(pmx, profiler_path) {
64
64
* CPU profiling snapshot
65
65
*/
66
66
var ns_cpu_profiling = 'km-cpu-profiling' ;
67
- var cpu_dump_file = path . join ( os . tmpDir ( ) , Date . now ( ) + '.cpuprofile' ) ;
67
+ var cpu_dump_file = path . join ( os . tmpdir ( ) , Date . now ( ) + '.cpuprofile' ) ;
68
68
69
69
pmx . action ( 'km:cpu:profiling:start' , function ( reply ) {
70
70
profiler . startProfiling ( ns_cpu_profiling ) ;
@@ -94,19 +94,24 @@ Profiling.exposeProfiling = function(pmx, profiler_path) {
94
94
/**
95
95
* Discover v8-profiler
96
96
*/
97
- Profiling . detectV8Profiler = function ( cb ) {
97
+ Profiling . detectV8Profiler = function ( module_name , cb ) {
98
98
var require_paths = require . main . paths . slice ( ) ;
99
99
100
100
( function look_for_profiler ( require_paths ) {
101
- if ( ! require_paths [ 0 ] )
102
- return cb ( new Error ( 'Module not found' ) ) ;
103
-
104
- var profiler_path = path . join ( require_paths [ 0 ] , 'v8-profiler' ) ;
105
-
106
- fs . exists ( profiler_path , function ( exist ) {
107
- if ( exist )
101
+ if ( ! require_paths [ 0 ] ) {
102
+ debug ( '[x] %s NOT FOUND' , module_name ) ;
103
+ return cb ( new Error ( 'v8-profiler not found' ) ) ;
104
+ }
105
+ var profiler_path = path . join ( require_paths [ 0 ] , module_name ) ;
106
+
107
+ debug ( 'Checking %s in path %s' , module_name , profiler_path ) ;
108
+ fs . access ( profiler_path , fs . R_OK || fs . constants . R_OK , function ( err ) {
109
+ if ( ! err ) {
110
+ debug ( '[+] %s detected in path %s' , module_name , profiler_path ) ;
108
111
return cb ( null , profiler_path ) ;
112
+ }
109
113
114
+ debug ( '[-] %s not found in path %s' , module_name , profiler_path ) ;
110
115
require_paths . shift ( ) ;
111
116
return look_for_profiler ( require_paths ) ;
112
117
} ) ;
@@ -115,9 +120,14 @@ Profiling.detectV8Profiler = function(cb) {
115
120
} ;
116
121
117
122
Profiling . v8Profiling = function ( pmx ) {
118
- Profiling . detectV8Profiler ( function ( err , profiler_path ) {
119
- if ( err )
120
- return false ;
123
+ Profiling . detectV8Profiler ( 'v8-profiler' , function ( err , profiler_path ) {
124
+ if ( err ) {
125
+ return Profiling . detectV8Profiler ( 'v8-profiler-node8' , function ( err , profiler_path ) {
126
+ if ( err )
127
+ return false ;
128
+ return Profiling . exposeProfiling ( pmx , profiler_path ) ;
129
+ } ) ;
130
+ }
121
131
return Profiling . exposeProfiling ( pmx , profiler_path ) ;
122
132
} ) ;
123
133
} ;
0 commit comments