Monday 13 March 2017

Why I can't do cpu-profiling when the process blocking by String(str).replace(some_regexp, '') in Node.js?

For Example,blow function testReplace will blocking the Node.js process:

function testReplace() {
    let str = '<br/>                                                        早餐后自由活动,于指定时间集合自行办理退房手续。';
    str += '<br/>                                      <br/>                                        <br/>                                    <br/>';
    str += '                                    <br/>                                                                                                                        <br/>';
    str += '                                                <br/>                                                                                                            <br/>';
    str += '                                                                                                                    根据船班时间,自行前往暹粒机场,返回中国。<br/>';
    str += '如需送机服务,需增加280/每单。<br/>';

    let r = String(str).replace(/(^(\s*?<br[\s\/]*?>\*?)+|(\s*?<br[\s\/]*?>\s*?)+?$)/igm, '');
    console.log(str)
}

And I want to know where is the blocking function, so I use v8-profiler to do cpu-profiling when the process blocking, such as:

v8Profiler.startProfiling('easy_monitor', true);
setTimeout(() => {
    let profile = v8Profiler.stopProfiling('easy_monitor');
    profile.delete();
}, 5000);

but this always throw error:

Bus error: 10

How can I resolve this problem? If you can help me I'll really appreciate to you :)



via hyj1991

No comments:

Post a Comment