)
set (SOURCES
+ ./src/metric_wrapper.cc
./src/time_manager.cc
./src/application_manager_observer.cc
./src/transport_manager_observer.cc
* POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_MECTRIC_H_
-#define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_MECTRIC_H_
+#ifndef SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_
+#define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_
#include <string>
-#include "metric.h"
+#include "metric_wrapper.h"
#include "application_manager_observer.h"
class ApplicationManagerObserver;
-class ApplicationManagerMetric: public Metric {
+class ApplicationManagerMetricWrapper: public MetricWrapper {
public:
utils::SharedPtr<application_manager::AMMetricObserver::MessageMetric> message_metric;
- std::string GetStyledString();
+
+ protected:
+ virtual Json::Value GetJsonMetric();
};
}
-#endif // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_MECTRIC_H_
+#endif // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_APPLICATION_MANAGER_MECTRIC_WRAPPER_H_
const char session_id[] = "session_id";
const char correlation_id[] = "correlation_id";
const char connection_key[] = "connection_key";
-
-
+ const char stime[] = "stime";
+ const char utime[] = "utime";
+ const char memory[] = "RAM";
}
}
#endif // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_JSON_KEYS_H_
--- /dev/null
+/*
+ * Copyright (c) 2014, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_MECTRIC_H_
+#define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_MECTRIC_H_
+
+#include <string>
+#include "utils/resource_usage.h"
+#include "json/json.h"
+
+namespace time_tester {
+
+class MetricWrapper {
+ utils::ResourseUsage* resources;
+ public:
+ MetricWrapper();
+ /*
+ * @brief get current cpu and memory info and store it as member
+ */
+ bool grabResources();
+ virtual std::string GetStyledString();
+ ~MetricWrapper();
+ protected:
+ virtual Json::Value GetJsonMetric();
+ void Clear();
+};
+
+
+} // namespace time_tester
+#endif // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_MECTRIC_H_
#include <string>
#include "utils/shared_ptr.h"
-#include "metric.h"
+#include "metric_wrapper.h"
#include "protocol_handler_observer.h"
namespace time_tester {
-class ProtocolHandlerMectic: public Metric {
+class ProtocolHandlerMecticWrapper: public MetricWrapper {
public:
utils::SharedPtr<protocol_handler::PHMetricObserver::MessageMetric> message_metric;
- std::string GetStyledString();
+ protected:
+ virtual Json::Value GetJsonMetric();
};
} // namespace time_tester
#endif // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_PROTOCOL_HANDLER_MECTRIC_H_
#include "utils/threads/thread.h"
#include "utils/singleton.h"
#include "utils/threads/thread_delegate.h"
-#include "metric.h"
+#include "metric_wrapper.h"
#include "application_manager_observer.h"
#include "application_manager/application_manager_impl.h"
#include "transport_manager_observer.h"
~TimeManager();
void Init(protocol_handler::ProtocolHandlerImpl* ph);
void Stop();
- void SendMetric(utils::SharedPtr<Metric> metric);
+ void SendMetric(utils::SharedPtr<MetricWrapper> metric);
private:
ApplicationManagerObserver app_observer;
TransportManagerObserver tm_observer;
ProtocolHandlerObserver ph_observer;
- int16_t port_;
- std::string ip_;
- int32_t socket_fd_;
- bool is_ready_;
- threads::Thread* thread_;
- MessageQueue<utils::SharedPtr<Metric> > messages_;
-
class Streamer : public threads::ThreadDelegate {
public:
explicit Streamer(TimeManager* const server);
void Start();
void Stop();
bool Send(const std::string &msg);
+ volatile bool is_client_connected_;
private:
TimeManager* const server_;
- int32_t new_socket_fd_;
- volatile bool is_client_connected_;
+ int32_t new_socket_fd_;
volatile bool stop_flag_;
DISALLOW_COPY_AND_ASSIGN(Streamer);
};
+
+ int16_t port_;
+ std::string ip_;
+ int32_t socket_fd_;
+ bool is_ready_;
+ threads::Thread* thread_;
+ MessageQueue<utils::SharedPtr<MetricWrapper> > messages_;
+ Streamer* streamer_;
+
DISALLOW_COPY_AND_ASSIGN(TimeManager);
};
} // namespace time_manager
#define SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_TRANSPORT_MANAGER_MECTRIC_H_
#include <string>
-#include "metric.h"
+#include "metric_wrapper.h"
#include "transport_manager_observer.h"
namespace time_tester {
-class TransportManagerMectic: public Metric {
+class TransportManagerMecticWrapper: public MetricWrapper {
public:
utils::SharedPtr<transport_manager::TMMetricObserver::MessageMetric> message_metric;
- std::string GetStyledString();
+ protected:
+ virtual Json::Value GetJsonMetric();
};
} // namespace time_tester
#endif // SRC_COMPONENTS_TIME_TESTER_INCLUDE_TIME_TESTER_TRANSPORT_MANAGER_MECTRIC_H_
namespace time_tester {
-std::string ApplicationManagerMetric::GetStyledString() {
- Json::Value result;
+Json::Value ApplicationManagerMetricWrapper::GetJsonMetric() {
+ Json::Value result = MetricWrapper::GetJsonMetric();
result[strings::logger] = "ApplicationManager";
result[strings::begin] =
Json::Int64(date_time::DateTime::getuSecs(message_metric->begin));
params[application_manager::strings::correlation_id].asInt();
result[strings::connection_key] =
params[application_manager::strings::connection_key].asInt();
- return result.toStyledString();
+ return result;
}
} // namespace time_tester
}
void ApplicationManagerObserver::OnMessage(utils::SharedPtr<MessageMetric> metric) {
- ApplicationManagerMetric* m = new ApplicationManagerMetric();
+ ApplicationManagerMetricWrapper* m = new ApplicationManagerMetricWrapper();
m->message_metric = metric;
+ m->grabResources();
time_manager_->SendMetric(m);
}
} // namespace time_tester
--- /dev/null
+#include "metric_wrapper.h"
+#include "json_keys.h"
+
+namespace time_tester {
+
+ MetricWrapper::MetricWrapper():
+ resources(NULL) {
+ }
+
+bool MetricWrapper::grabResources() {
+ Clear();
+ resources = utils::Resources::getCurrentResourseUsage();
+ if (NULL != resources) {
+ return true;
+ } else {
+ return false;
+ }
+ flush(std::cout);
+}
+
+std::string MetricWrapper::GetStyledString() {
+ return GetJsonMetric().toStyledString();
+}
+
+Json::Value MetricWrapper::GetJsonMetric() {
+ Json::Value result;
+ if (resources) {
+ result[strings::stime] = resources->stime;
+ result[strings::utime] = resources->utime;
+ result[strings::memory] = resources->memory;
+ }
+ return result;
+}
+
+void MetricWrapper::Clear() {
+ if (NULL != resources) {
+ delete resources;
+ resources = NULL;
+ }
+}
+
+MetricWrapper::~MetricWrapper() {
+ Clear();
+}
+
+}
namespace time_tester {
-std::string ProtocolHandlerMectic::GetStyledString() {
- Json::Value result;
+Json::Value ProtocolHandlerMecticWrapper::GetJsonMetric() {
+ Json::Value result = MetricWrapper::GetJsonMetric();
result[strings::logger] = "ProtocolHandler";
result[strings::begin] =
Json::Int64(date_time::DateTime::getuSecs(message_metric->begin));
Json::Int64(date_time::DateTime::getuSecs(message_metric->end));
result[strings::message_id] = message_metric->message_id;
result[strings::connection_key] = message_metric->connection_key;
- return result.toStyledString();
+ return result;
}
+
} // namespace time_tester
}
m->begin= time_starts[message_id];
m->end = date_time::DateTime::getCurrentTime();
- ProtocolHandlerMectic* metric = new ProtocolHandlerMectic();
+ ProtocolHandlerMecticWrapper* metric = new ProtocolHandlerMecticWrapper();
metric->message_metric = m;
+ metric->grabResources();
time_manager_->SendMetric(metric);
}
} //namespace time_tester
#include "transport_manager/transport_manager_default.h"
#include "config_profile/profile.h"
+#include "utils/resource_usage.h"
namespace time_tester {
thread_(NULL),
app_observer(this),
tm_observer(this),
- ph_observer(this) {
+ ph_observer(this),
+ streamer_(NULL) {
ip_ = profile::Profile::instance()->server_address();
port_ = profile::Profile::instance()->time_testing_port();
}
void TimeManager::Init(protocol_handler::ProtocolHandlerImpl* ph) {
DCHECK(ph);
if (!thread_) {
- thread_ = new threads::Thread("SocketAdapter", new Streamer(this));
+ streamer_ = new Streamer(this);
+ thread_ = new threads::Thread("SocketAdapter", streamer_ );
application_manager::ApplicationManagerImpl::instance()->SetTimeMetricObserver(&app_observer);
transport_manager::TransportManagerDefault::instance()->SetTimeMetricObserver(&tm_observer);
ph->SetTimeMetricObserver(&ph_observer);
::close(socket_fd_);
}
}
+ messages_.Reset();
LOG4CXX_INFO(logger_, "TimeManager stopped");
}
-void TimeManager::SendMetric(utils::SharedPtr<Metric> metric) {
- messages_.push(metric);
+void TimeManager::SendMetric(utils::SharedPtr<MetricWrapper> metric) {
+ if ((NULL != streamer_ )&& streamer_->is_client_connected_) {
+ messages_.push(metric);
+ }
}
TimeManager::Streamer::Streamer(
is_client_connected_ = true;
while (is_client_connected_) {
while (!server_->messages_.empty()) {
- utils::SharedPtr<Metric> metric = server_->messages_.pop();
+ utils::SharedPtr<MetricWrapper> metric = server_->messages_.pop();
is_client_connected_ = Send(metric->GetStyledString());
}
namespace time_tester {
-std::string TransportManagerMectic::GetStyledString() {
- Json::Value result;
+Json::Value TransportManagerMecticWrapper::GetJsonMetric() {
+ Json::Value result = MetricWrapper::GetJsonMetric();
result[strings::logger] = "TransportManager";
result[strings::begin] =
Json::Int64(date_time::DateTime::getuSecs(message_metric->begin));
result[strings::end] =
Json::Int64(date_time::DateTime::getuSecs(message_metric->end));
result[strings::data_size] = static_cast<uint32_t>(message_metric->data_size);
- return result.toStyledString();
+ return result;
}
+
} // namespace time_tester
std::map<const protocol_handler::RawMessage*, TimevalStruct>::const_iterator it;
it = time_starts.find(ptr);
if (it != time_starts.end()) {
- TransportManagerMectic* m = new TransportManagerMectic();
+ TransportManagerMecticWrapper* m = new TransportManagerMecticWrapper();
m->message_metric = new transport_manager::TMMetricObserver::MessageMetric();
m->message_metric->begin = it->second;
m->message_metric->end = date_time::DateTime::getCurrentTime();
m->message_metric->data_size = ptr->data_size();
+ m->grabResources();
time_manager_->SendMetric(m);
}
}