#include <stdlib.h> #include "clientapi.h" #include "strops.h" #include "strtable.h" #include "globals.h" #include "clientgremlin.h" #include "clientgremlinclient.h" #include "clientgremlindesc.h" #include "clientgremlinuser.h" void run_meta_job( ClientApi* client ); void run_meta_lsync( ClientApi* client ); void run_meta_client( ClientApi* client ); void run_meta_label( ClientApi* client ); void run_meta_user( ClientApi* client ); void task_meta( ClientApi* client ) { int rnd = rand() % 100; if ( rnd < 5 ) run_meta_job( client ); else if ( rnd < 31 ) run_meta_lsync( client ); else if ( rnd < 45 ) run_meta_client( client ); else if ( rnd < 65 ) run_meta_label( client ); else run_meta_user( client ); } void run_meta_client( ClientApi* client ) { StrBuf views, cliname, depot, view, dir, cdir; depot.Set( "depot" ); cliname = client->GetClient(); int c = dirs1.GetCount(); if ( !c || rand() % 5 < 2 ) { views.Append( " \"//depot/...\" \"//" ); views.Append( &cliname ); views.Append( "/...\"\n" ); } if ( c ) { for ( int a = 0 ; a < rand() % c ; a++ ) { dir.Set( dirs1.GetVar( StrNum( rand() % c ) ) ); if ( !dir.Length() ) break; views.Append( " \"" ); if ( rand() % 20 < 5 ) views.Append( "-" ); views.Append( &dir ); views.Append( "/...\" \"" ); cdir.Clear(); StrOps::Replace( cdir, dir, depot, cliname ); views.Append( &cdir ); views.Append( "/...\"\n" ); } c = dirs2.GetCount(); } if ( c ) { for ( int a = 0 ; a < rand() % c ; a++ ) { dir.Set( dirs2.GetVar( StrNum( rand() % c ) ) ); if ( !dir.Length() ) break; views.Append( " \"" ); if ( rand() % 20 < 15 ) views.Append( "-" ); views.Append( &dir ); views.Append( "/...\" \"" ); cdir.Clear(); StrOps::Replace( cdir, dir, depot, cliname ); views.Append( &cdir ); views.Append( "/...\"\n" ); } c = dirs3.GetCount(); } if ( c ) { for ( int a = 0 ; a < rand() % c ; a++ ) { dir.Set( dirs3.GetVar( StrNum( rand() % c ) ) ); if ( !dir.Length() ) break; views.Append( " \"" ); if ( rand() % 20 < 5 ) views.Append( "-" ); views.Append( &dir ); views.Append( "/...\" \"" ); cdir.Clear(); StrOps::Replace( cdir, dir, depot, cliname ); views.Append( &cdir ); views.Append( "/...\"\n" ); } c = dirs4.GetCount(); } if ( c ) { for ( int a = 0 ; a < rand() % c ; a++ ) { dir.Set( dirs4.GetVar( StrNum( rand() % c ) ) ); if ( !dir.Length() ) break; views.Append( " \"" ); if ( rand() % 20 < 15 ) views.Append( "-" ); views.Append( &dir ); views.Append( "/...\" \"" ); cdir.Clear(); StrOps::Replace( cdir, dir, depot, cliname ); views.Append( &cdir ); views.Append( "/...\"\n" ); } c = dirs5.GetCount(); } if ( c ) { for ( int a = 0 ; a < rand() % c ; a++ ) { dir.Set( dirs5.GetVar( StrNum( rand() % c ) ) ); if ( !dir.Length() ) break; views.Append( " \"" ); if ( rand() % 20 < 5 ) views.Append( "-" ); views.Append( &dir ); views.Append( "/...\" \"" ); cdir.Clear(); StrOps::Replace( cdir, dir, depot, cliname ); views.Append( &cdir ); views.Append( "/...\"\n" ); } } ClientGremlinClient grem = ClientGremlinClient( client ); grem.view.Set( views ); grem.arg1 = StrRef( "-o" ); grem.arg2 = cliname; grem.Run(); grem.arg1 = StrRef( "-i" ); grem.arg2 = StrBuf(); grem.Run(); } void run_meta_job( ClientApi* client ) { ClientGremlinDesc grem = ClientGremlinDesc( client ); grem.cmd = "job"; grem.arg1.Set( "-o" ); grem.Run(); grem.arg1.Set( "-i" ); grem.Run(); } void run_meta_lsync( ClientApi* client ) { ClientGremlin grem = ClientGremlin( client, "labelsync" ); grem.arg1.Set( "-l" ); grem.arg2.Set( filewords.GetVar( StrNum( rand() % 4 ) ) ); grem.arg2.Append( filewords.GetVar( StrNum( rand() % 4 ) ) ); grem.Run(); } void run_meta_label( ClientApi* client ) { ClientGremlin grem = ClientGremlinDesc( client ); grem.cmd = "label"; grem.arg1.Set( "-o" ); grem.arg2.Set( filewords.GetVar( StrNum( rand() % 4 ) ) ); grem.arg2.Append( filewords.GetVar( StrNum( rand() % 4 ) ) ); grem.Run(); grem.arg2.Clear(); grem.arg1.Set( "-i" ); grem.Run(); } void run_meta_user( ClientApi* client ) { ClientGremlinUser grem = ClientGremlinUser( client ); grem.arg1.Set( "-o" ); grem.Run(); grem.arg1.Set( "-i" ); grem.Run(); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 2041 | Sam Stafford |
P4GREMLIN, a stress testing utility. Requires the P4 Client API to build. |