19std::shared_ptr<ROOT::RWebWindow> window;
22bool window_terminated =
false;
24bool batch_mode =
false;
25int current_counter = 0;
27auto start_tm = std::chrono::high_resolution_clock::now();
28auto firstmsg_tm = start_tm;
29auto stop_tm = start_tm;
30std::string round_trip =
"<not defined>";
32void ProcessData(
unsigned connid,
const std::string &arg)
34 if (arg.find(
"PING:") == 0) {
35 window->Send(connid, arg);
36 }
else if (arg ==
"first") {
38 firstmsg_tm = std::chrono::high_resolution_clock::now();
39 std::vector<std::string> clients;
42 for(
int n = 1;
n < num_clients; ++
n)
43 clients.emplace_back(
".." + window->GetUrl(
false));
45 }
else if (arg.find(
"SHOW:") == 0) {
46 std::string msg = arg.substr(5);
48 std::cout << msg << std::endl;
49 if (msg.find(
"Cnt:") == 0) {
50 int counter = std::stoi(msg.substr(4));
52 current_counter = counter;
55 auto p = msg.find(
"round-trip:");
56 if (
p > 0) round_trip = msg.substr(
p);
58 }
else if (arg ==
"halt") {
60 window_terminated =
true;
61 window->TerminateROOT();
79 modeHttpWindowThread = 3,
88void ping(
int nclients = 1,
int test_mode = 0)
90 num_clients = nclients;
92 batch_mode =
gROOT->IsBatch();
95 if (test_mode < 0) test_mode = 0;
96 int major_mode = test_mode / 10;
97 test_mode = test_mode % 10;
98 if (test_mode > modeCivetThread)
99 test_mode = modeDefault;
103 else if (num_clients > 1000)
107 if (major_mode == majorLongpoll)
114 if ((test_mode == modeHttpThread) || (test_mode == modeHttpWindowThread))
118 if (test_mode == modeMinimalTimer)
130 window->SetConnLimit(num_clients);
135 std::string fname = __FILE__;
136 auto pos = fname.find(
"ping.cxx");
140 fname =
gROOT->GetTutorialsDir() + std::string(
"/webgui/ping/");
141 fname.append(
"ping.html");
142 window->SetDefaultPage(
"file:" + fname);
145 window->SetGeometry(300, 500);
149 window->SetDataCallBack(ProcessData);
152 if (test_mode == modeCivetThread)
153 window->UseServerThreads();
155 if (test_mode == modeHttpWindowThread)
156 window->StartThread();
160 window->Show(batch_mode ?
"headless" :
"");
162 std::cout <<
"Window url is: " << window->GetUrl(
true) << std::endl;
166 const int run_limit = 200;
167 const double fullrun_time = 100., startup_time = 70.;
168 start_tm = firstmsg_tm = std::chrono::high_resolution_clock::now();
169 window->WaitFor([=](
double tm) {
return (current_counter >= run_limit) || (tm > fullrun_time) || ((current_counter == 0) && (tm > startup_time)) ? 1 : 0; });
170 stop_tm = std::chrono::high_resolution_clock::now();
171 auto startuptime_int = std::chrono::duration_cast<std::chrono::milliseconds>(firstmsg_tm - start_tm);
172 auto runttime_int = std::chrono::duration_cast<std::chrono::milliseconds>(stop_tm - firstmsg_tm);
174 if (current_counter >= run_limit)
175 std::cout <<
"PING-PONG TEST COMPLETED " << round_trip;
177 std::cout <<
"PING-PONG TEST FAIL cnt:" << current_counter;
179 std::cout <<
" startup: " << startuptime_int.count() <<
"ms" <<
" run: " << runttime_int.count() <<
"ms" << std::endl;
winID h TVirtualViewer3D TVirtualGLPainter p
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static void SetSingleConnMode(bool on=true)
Enable or disable single connection mode (default on) If enabled, one connection only with any web wi...
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
Set the value of a resource or create a new resource.