public function toClientMetrics()
 {
     $client_metrics = new ClientMetrics();
     foreach ($this->metrics as $key => $value) {
         $metric_data = new MetricData();
         if ($key == self::EXECUTION_TIME) {
             $metric_data->setMetricName($this->action . "." . $key);
             $metric_data->setMetricType(MetricData::LATENCY);
             $metric_data->setValue($value->getEndTimeMilli() - $value->getStartTimeMilli());
             $metric_data->setTimeStamp(round($value->getEndTimeMilli() / 1000));
         }
         $client_metrics->add($metric_data);
     }
     return $client_metrics;
 }
 public function run()
 {
     require __DIR__ . "/../../../bootstrap.php";
     while (true) {
         try {
             $start_time = time();
             $client_metrics = new ClientMetrics();
             $metrics = $this->metrics_queue->popAllMetrics();
             $client_metrics->addAll($metrics);
             $this->fds_client->putClientMetrics($client_metrics);
             $this->fds_client->printResponse("Pushed " . count($metrics) . " metrics.\n");
             $end_time = time();
             $used_time = $end_time - $start_time;
             $left_time = self::UPLOAD_INTERVAL - $used_time;
             if ($left_time > 0) {
                 sleep($left_time);
             } else {
                 $this->fds_client->printResponse("Push metrics timeout, costs " . $used_time . " seconds\n");
             }
         } catch (Exception $e) {
             $this->fds_client->printResponse("Failed to push metrics, " . $e->getMessage());
         }
     }
 }