summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Dickow <jjdickow@gmail.com>2014-07-17 14:48:42 -0400
committerJustin Dickow <jjdickow@gmail.com>2014-07-17 14:48:42 -0400
commit63384f97c6a78280f8f3b6fb69dc73bbb6e76fd2 (patch)
treeebb4d04d905933ca987925da4721ed6e623a13a1
parent6c7e4535d802b49ded9f3430dcaa44453328a160 (diff)
downloadsmartdevicelink-63384f97c6a78280f8f3b6fb69dc73bbb6e76fd2.tar.gz
3.5 - Time Tester
Author: Alex Kutsan Signed-off-by: Justin Dickow <jjdickow@gmail.com>
-rw-r--r--src/components/time_tester/CMakeLists.txt1
-rw-r--r--src/components/time_tester/include/time_tester/application_manager_metric.h14
-rw-r--r--src/components/time_tester/include/time_tester/json_keys.h5
-rw-r--r--src/components/time_tester/include/time_tester/metric_wrapper.h59
-rw-r--r--src/components/time_tester/include/time_tester/protocol_handler_metric.h7
-rw-r--r--src/components/time_tester/include/time_tester/time_manager.h24
-rw-r--r--src/components/time_tester/include/time_tester/transport_manager_metric.h7
-rw-r--r--src/components/time_tester/src/application_manager_metric.cc6
-rw-r--r--src/components/time_tester/src/application_manager_observer.cc3
-rw-r--r--src/components/time_tester/src/metric_wrapper.cc46
-rw-r--r--src/components/time_tester/src/protocol_handler_metric.cc7
-rw-r--r--src/components/time_tester/src/protocol_handler_observer.cc3
-rw-r--r--src/components/time_tester/src/time_manager.cc16
-rw-r--r--src/components/time_tester/src/transport_manager_metric.cc7
-rw-r--r--src/components/time_tester/src/transport_manager_observer.cc3
15 files changed, 166 insertions, 42 deletions
diff --git a/src/components/time_tester/CMakeLists.txt b/src/components/time_tester/CMakeLists.txt
index fea874340..38841996a 100644
--- a/src/components/time_tester/CMakeLists.txt
+++ b/src/components/time_tester/CMakeLists.txt
@@ -16,6 +16,7 @@ include_directories (
)
set (SOURCES
+ ./src/metric_wrapper.cc
./src/time_manager.cc
./src/application_manager_observer.cc
./src/transport_manager_observer.cc
diff --git a/src/components/time_tester/include/time_tester/application_manager_metric.h b/src/components/time_tester/include/time_tester/application_manager_metric.h
index a0c8bf618..1c21c0f72 100644
--- a/src/components/time_tester/include/time_tester/application_manager_metric.h
+++ b/src/components/time_tester/include/time_tester/application_manager_metric.h
@@ -30,12 +30,12 @@
* 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"
@@ -43,12 +43,14 @@ namespace time_tester {
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_
diff --git a/src/components/time_tester/include/time_tester/json_keys.h b/src/components/time_tester/include/time_tester/json_keys.h
index 75409912e..d1ace3f9d 100644
--- a/src/components/time_tester/include/time_tester/json_keys.h
+++ b/src/components/time_tester/include/time_tester/json_keys.h
@@ -44,8 +44,9 @@ namespace time_tester {
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_
diff --git a/src/components/time_tester/include/time_tester/metric_wrapper.h b/src/components/time_tester/include/time_tester/metric_wrapper.h
new file mode 100644
index 000000000..705316a4a
--- /dev/null
+++ b/src/components/time_tester/include/time_tester/metric_wrapper.h
@@ -0,0 +1,59 @@
+/*
+ * 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_
diff --git a/src/components/time_tester/include/time_tester/protocol_handler_metric.h b/src/components/time_tester/include/time_tester/protocol_handler_metric.h
index 507f0543b..47db117a3 100644
--- a/src/components/time_tester/include/time_tester/protocol_handler_metric.h
+++ b/src/components/time_tester/include/time_tester/protocol_handler_metric.h
@@ -35,16 +35,17 @@
#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_
diff --git a/src/components/time_tester/include/time_tester/time_manager.h b/src/components/time_tester/include/time_tester/time_manager.h
index a4f26dc88..cd8bc4f07 100644
--- a/src/components/time_tester/include/time_tester/time_manager.h
+++ b/src/components/time_tester/include/time_tester/time_manager.h
@@ -40,7 +40,7 @@
#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"
@@ -56,19 +56,12 @@ class TimeManager {
~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);
@@ -79,13 +72,22 @@ class TimeManager {
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
diff --git a/src/components/time_tester/include/time_tester/transport_manager_metric.h b/src/components/time_tester/include/time_tester/transport_manager_metric.h
index c2c9c4a7b..25261b007 100644
--- a/src/components/time_tester/include/time_tester/transport_manager_metric.h
+++ b/src/components/time_tester/include/time_tester/transport_manager_metric.h
@@ -34,15 +34,16 @@
#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_
diff --git a/src/components/time_tester/src/application_manager_metric.cc b/src/components/time_tester/src/application_manager_metric.cc
index 6978e72b0..251323dc4 100644
--- a/src/components/time_tester/src/application_manager_metric.cc
+++ b/src/components/time_tester/src/application_manager_metric.cc
@@ -36,8 +36,8 @@
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));
@@ -49,6 +49,6 @@ std::string ApplicationManagerMetric::GetStyledString() {
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
diff --git a/src/components/time_tester/src/application_manager_observer.cc b/src/components/time_tester/src/application_manager_observer.cc
index fa768e2bf..67d7268da 100644
--- a/src/components/time_tester/src/application_manager_observer.cc
+++ b/src/components/time_tester/src/application_manager_observer.cc
@@ -41,8 +41,9 @@ ApplicationManagerObserver::ApplicationManagerObserver(TimeManager* time_manager
}
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
diff --git a/src/components/time_tester/src/metric_wrapper.cc b/src/components/time_tester/src/metric_wrapper.cc
new file mode 100644
index 000000000..2922bf35c
--- /dev/null
+++ b/src/components/time_tester/src/metric_wrapper.cc
@@ -0,0 +1,46 @@
+#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();
+}
+
+}
diff --git a/src/components/time_tester/src/protocol_handler_metric.cc b/src/components/time_tester/src/protocol_handler_metric.cc
index 278cab292..93e08642f 100644
--- a/src/components/time_tester/src/protocol_handler_metric.cc
+++ b/src/components/time_tester/src/protocol_handler_metric.cc
@@ -36,8 +36,8 @@
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));
@@ -45,6 +45,7 @@ std::string ProtocolHandlerMectic::GetStyledString() {
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
diff --git a/src/components/time_tester/src/protocol_handler_observer.cc b/src/components/time_tester/src/protocol_handler_observer.cc
index 1ddf08476..a5ca678e9 100644
--- a/src/components/time_tester/src/protocol_handler_observer.cc
+++ b/src/components/time_tester/src/protocol_handler_observer.cc
@@ -63,8 +63,9 @@ void ProtocolHandlerObserver::EndMessageProcess(utils::SharedPtr<MessageMetric>
}
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
diff --git a/src/components/time_tester/src/time_manager.cc b/src/components/time_tester/src/time_manager.cc
index d7c458954..c68dd9d37 100644
--- a/src/components/time_tester/src/time_manager.cc
+++ b/src/components/time_tester/src/time_manager.cc
@@ -43,6 +43,7 @@
#include "transport_manager/transport_manager_default.h"
#include "config_profile/profile.h"
+#include "utils/resource_usage.h"
namespace time_tester {
@@ -54,7 +55,8 @@ TimeManager::TimeManager():
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();
}
@@ -67,7 +69,8 @@ TimeManager::~TimeManager() {
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);
@@ -85,11 +88,14 @@ void TimeManager::Stop() {
::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(
@@ -120,7 +126,7 @@ void TimeManager::Streamer::threadMain() {
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());
}
diff --git a/src/components/time_tester/src/transport_manager_metric.cc b/src/components/time_tester/src/transport_manager_metric.cc
index cb2567f4d..a7c9ecb5a 100644
--- a/src/components/time_tester/src/transport_manager_metric.cc
+++ b/src/components/time_tester/src/transport_manager_metric.cc
@@ -37,14 +37,15 @@
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
diff --git a/src/components/time_tester/src/transport_manager_observer.cc b/src/components/time_tester/src/transport_manager_observer.cc
index ad8628125..41cb30126 100644
--- a/src/components/time_tester/src/transport_manager_observer.cc
+++ b/src/components/time_tester/src/transport_manager_observer.cc
@@ -50,11 +50,12 @@ void TransportManagerObserver::StopRawMsg(const protocol_handler::RawMessage* pt
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);
}
}