@@ -107,6 +107,7 @@ static const char USAGE_STRING[] =
107107 " " APP_BINARY " stop -o flat jps\n "
108108 " " APP_BINARY " -d 5 -e alloc MyAppName\n " ;
109109
110+ static const unsigned int DEFAULT_FDTRANSFER_TIMEOUT = 30 ;
110111
111112extern " C" int jattach (int pid, int argc, const char ** argv);
112113
@@ -227,6 +228,7 @@ static bool use_tmp_file = false;
227228static int duration = 60 ;
228229static int pid = 0 ;
229230static volatile unsigned long long end_time;
231+ static unsigned int timeout = DEFAULT_FDTRANSFER_TIMEOUT;
230232
231233static void sigint_handler (int sig) {
232234 end_time = 0 ;
@@ -331,7 +333,7 @@ static int jps(const char* cmd, const char* app_name = NULL) {
331333 return pid;
332334}
333335
334- static void run_fdtransfer (int pid, String& fdtransfer) {
336+ static void run_fdtransfer (int pid, String& fdtransfer, unsigned int timeout ) {
335337 if (!FdTransferServer::supported () || fdtransfer == " " ) return ;
336338
337339 pid_t child = fork ();
@@ -340,7 +342,7 @@ static void run_fdtransfer(int pid, String& fdtransfer) {
340342 }
341343
342344 if (child == 0 ) {
343- exit (FdTransferServer::runOnce (pid, fdtransfer.str ()) ? 0 : 1 );
345+ exit (FdTransferServer::runOnce (pid, fdtransfer.str (), timeout ) ? 0 : 1 );
344346 } else {
345347 int ret = wait_for_exit (child);
346348 if (ret != 0 ) {
@@ -483,7 +485,9 @@ int main(int argc, const char** argv) {
483485 output = " jfr" ;
484486
485487 } else if (arg == " --timeout" || arg == " --loop" ) {
486- params << " ," << (arg.str () + 2 ) << " =" << args.next ();
488+ const char * value = args.next ();
489+ params << " ," << (arg.str () + 2 ) << " =" << value;
490+ timeout = atoi (value);
487491 if (action == " collect" ) action = " start" ;
488492
489493 } else if (arg == " --fd-path" ) {
@@ -537,7 +541,7 @@ int main(int argc, const char** argv) {
537541 }
538542
539543 if (action == " collect" ) {
540- run_fdtransfer (pid, fdtransfer);
544+ run_fdtransfer (pid, fdtransfer, timeout );
541545 run_jattach (pid, kJattachLoad , String (" start,file=" ) << file << " ," << output << format << params << " ,log=" << logfile);
542546
543547 fprintf (stderr, " Profiling for %d seconds\n " , duration);
@@ -561,7 +565,7 @@ int main(int argc, const char** argv) {
561565 if (params != kEmpty ) {
562566 fprintf (stderr, " Warning: action fdtransfer was given, these parameters will be ignored: %s\n " , params.str ());
563567 }
564- run_fdtransfer (pid, fdtransfer);
568+ run_fdtransfer (pid, fdtransfer, timeout );
565569
566570 } else if (action == " jattach" ) {
567571 if (jattach_cmd == kEmpty ) {
@@ -578,7 +582,7 @@ int main(int argc, const char** argv) {
578582 run_jattach (pid, kJattachJcmd , jattach_cmd);
579583
580584 } else {
581- if (action == " start" || action == " resume" ) run_fdtransfer (pid, fdtransfer);
585+ if (action == " start" || action == " resume" ) run_fdtransfer (pid, fdtransfer, timeout );
582586 run_jattach (pid, kJattachLoad , String (action) << " ,file=" << file << " ," << output << format << params << " ,log=" << logfile);
583587 }
584588
0 commit comments