mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Add -s <seconds> parameter to capture.cpp
This commit is contained in:
+15
-2
@@ -34,7 +34,7 @@ void SigInt( int )
|
||||
|
||||
[[noreturn]] void Usage()
|
||||
{
|
||||
printf( "Usage: capture -o output.tracy [-a address] [-p port] [-f]\n" );
|
||||
printf( "Usage: capture -o output.tracy [-a address] [-p port] [-f] [-s seconds]\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
@@ -52,9 +52,10 @@ int main( int argc, char** argv )
|
||||
const char* address = "127.0.0.1";
|
||||
const char* output = nullptr;
|
||||
int port = 8086;
|
||||
int seconds = -1;
|
||||
|
||||
int c;
|
||||
while( ( c = getopt( argc, argv, "a:o:p:f" ) ) != -1 )
|
||||
while( ( c = getopt( argc, argv, "a:o:p:fs:" ) ) != -1 )
|
||||
{
|
||||
switch( c )
|
||||
{
|
||||
@@ -70,6 +71,9 @@ int main( int argc, char** argv )
|
||||
case 'f':
|
||||
overwrite = true;
|
||||
break;
|
||||
case 's':
|
||||
seconds = atoi (optarg);
|
||||
break;
|
||||
default:
|
||||
Usage();
|
||||
break;
|
||||
@@ -137,6 +141,7 @@ int main( int argc, char** argv )
|
||||
{
|
||||
worker.Disconnect();
|
||||
disconnect = false;
|
||||
break;
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
@@ -162,6 +167,14 @@ int main( int argc, char** argv )
|
||||
fflush( stdout );
|
||||
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
|
||||
if( seconds != -1 )
|
||||
{
|
||||
const auto dur = std::chrono::high_resolution_clock::now() - t0;
|
||||
if( std::chrono::duration_cast<std::chrono::seconds>(dur).count() >= seconds )
|
||||
{
|
||||
disconnect = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto t1 = std::chrono::high_resolution_clock::now();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user