@@ -288,14 +288,6 @@ static void handle_sigint(int) { graceful_exit = true; }
288288
289289static void handle_sigchld (int ) { sigchld_requested = true ; }
290290
291- bool startsWith (std::string mainStr, std::string toMatch)
292- {
293- if (mainStr.find (toMatch) == 0 ) {
294- return true ;
295- } else {
296- return false ;
297- }
298- }
299291
300292// / This will start a new device by forking and executing a
301293// / new child
@@ -354,7 +346,7 @@ void spawnDevice(DeviceSpec const& spec, std::map<int, size_t>& socket2DeviceInf
354346 info.historySize = 1000 ;
355347 info.historyPos = 0 ;
356348 info.maxLogLevel = LogParsingHelpers::LogLevel::Debug;
357- info.dataRelayerViewIndex = DataRelayerViewIndex{ 0 , 0 , {} };
349+ info.dataRelayerViewIndex = Metric2DViewIndex{ " data_relayer " , 0 , 0 , {} };
358350
359351 socket2DeviceInfo.insert (std::make_pair (childstdout[0 ], deviceInfos.size ()));
360352 socket2DeviceInfo.insert (std::make_pair (childstderr[0 ], deviceInfos.size ()));
@@ -371,8 +363,6 @@ void spawnDevice(DeviceSpec const& spec, std::map<int, size_t>& socket2DeviceInf
371363void processChildrenOutput (DriverInfo& driverInfo, DeviceInfos& infos, DeviceSpecs const & specs,
372364 DeviceControls& controls, std::vector<DeviceMetricsInfo>& metricsInfos)
373365{
374- static const char * DATA_RELAYER_METRIC_PREFIX = " data_relayer" ;
375- static const size_t DATA_RELAYER_METRIC_PREFIX_SIZE = std::strlen (DATA_RELAYER_METRIC_PREFIX);
376366 // Wait for children to say something. When they do
377367 // print it.
378368 fd_set fdset;
@@ -426,39 +416,7 @@ void processChildrenOutput(DriverInfo& driverInfo, DeviceInfos& infos, DeviceSpe
426416 info.history .resize (info.historySize );
427417 info.historyLevel .resize (info.historySize );
428418
429- auto & view = info.dataRelayerViewIndex ;
430- auto updateDataRelayerViewIndex = [&view](std::string const & name, MetricInfo const & metric, int value) {
431- if (startsWith (name, DATA_RELAYER_METRIC_PREFIX) == false ) {
432- return ;
433- }
434- auto extra = name;
435-
436- // +1 is to remove the /
437- extra.erase (0 , DATA_RELAYER_METRIC_PREFIX_SIZE + 1 );
438- if (extra == " w" ) {
439- view.w = value;
440- view.indexes .resize (view.w * view.h );
441- return ;
442- } else if (extra == " h" ) {
443- view.h = value;
444- view.indexes .resize (view.w * view.h );
445- return ;
446- }
447- int idx = -1 ;
448- try {
449- idx = std::stoi (extra, nullptr , 10 );
450- } catch (...) {
451- LOG (ERROR) << " Badly formatted metric" << std::endl;
452- }
453- if (idx < 0 ) {
454- LOG (ERROR) << " Negative metric" << std::endl;
455- return ;
456- }
457- if (view.indexes .size () <= idx) {
458- view.indexes .resize (std::max (idx + 1 , view.w * view.h ));
459- }
460- view.indexes [idx] = metric.storeIdx ;
461- };
419+ auto updateDataRelayerViewIndex = Metric2DViewIndex::getUpdater (info.dataRelayerViewIndex );
462420
463421 while ((pos = s.find (delimiter)) != std::string::npos) {
464422 token = s.substr (0 , pos);
0 commit comments