This patch adds Tracer class for priting debug information.
Change-Id: Ia1439e7d86b94e9a03f377f3d372eeb7b8eec565
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
namespace rpc_port {
namespace internal {
-AcceptedPort::AcceptedPort(int read_fd, int write_fd, std::string id,
+AcceptedPort::AcceptedPort(int read_fd, int write_fd, pid_t pid, std::string id,
std::string inst, IEvent* listener, bool is_delegate)
- : Port(read_fd, write_fd, std::move(id), std::move(inst)),
+ : Port(read_fd, write_fd, pid, std::move(id), std::move(inst)),
listener_(listener),
is_delegate_(is_delegate) {}
-AcceptedPort::AcceptedPort(int read_fd, int write_fd, std::string id,
+AcceptedPort::AcceptedPort(int read_fd, int write_fd, pid_t pid, std::string id,
IEvent* listener, bool is_delegate)
- : Port(read_fd, write_fd, std::move(id)),
+ : Port(read_fd, write_fd, pid, std::move(id)),
listener_(listener),
is_delegate_(is_delegate) {}
virtual void OnSocketDisconnected(int fd) = 0;
};
- AcceptedPort(int read_fd, int write_fd, std::string id, std::string inst,
+ AcceptedPort(int read_fd, int write_fd, pid_t pid, std::string id,
+ std::string inst, IEvent* listener, bool is_delegate);
+ AcceptedPort(int read_fd, int write_fd, pid_t pid, std::string id,
IEvent* listener, bool is_delegate);
- AcceptedPort(int read_fd, int write_fd, std::string id, IEvent* listener,
- bool is_delegate);
virtual ~AcceptedPort();
bool IsDelegate() const;
int fd = Connect();
if (fd < 0) break;
- port_.reset(new Port(-1, fd, "Debug"));
+ port_.reset(new Port(-1, fd, -1, "Debug"));
if (Watch(fd) < 0) break;
SetConnectionStatus(true);
if (fd < 0) return -1;
std::lock_guard<std::recursive_mutex> lock(handle->GetMutex());
- handle->port_.reset(new Port(-1, fd, "Debug"));
+ handle->port_.reset(new Port(-1, fd, -1, "Debug"));
int ret = handle->Watch(fd);
if (ret < 0) return -1;
} // namespace
-Port::Port(int read_fd, int write_fd, std::string id)
+Port::Port(int read_fd, int write_fd, pid_t pid, std::string id)
: read_fd_(read_fd),
write_fd_(write_fd),
+ pid_(pid),
id_(std::move(id)),
instance_(""),
seq_(0) {
if (read_fd > -1) SetReceiveTimeout(-1);
}
-Port::Port(int read_fd, int write_fd, std::string id, std::string instance)
+Port::Port(int read_fd, int write_fd, pid_t pid, std::string id,
+ std::string instance)
: read_fd_(read_fd),
write_fd_(write_fd),
+ pid_(pid),
id_(std::move(id)),
instance_(std::move(instance)),
seq_(0) {
uint32_t Port::GetSeq() { return ++seq_; }
+pid_t Port::GetPid() const { return pid_; }
+
// LCOV_EXCL_START
gboolean Port::UnixFdSourceFunc(gint fd, GIOCondition condition,
gpointer data) {
class Port : public std::enable_shared_from_this<Port> {
public:
- Port(int read_fd, int write_fd, std::string id, std::string instance);
- Port(int read_fd, int write_fd, std::string id);
+ Port(int read_fd, int write_fd, pid_t pid, std::string id,
+ std::string instance);
+ Port(int read_fd, int write_fd, pid_t pid, std::string id);
virtual ~Port();
virtual void Disconnect();
std::recursive_mutex& GetWriteMutex() const;
const std::string& GetInstance() const;
uint32_t GetSeq();
+ pid_t GetPid() const;
private:
// LCOV_EXCL_START
private:
int read_fd_;
int write_fd_;
+ pid_t pid_;
std::string id_;
std::string instance_;
std::atomic<uint32_t> seq_;
#include "rpc-port/exception-internal.hh"
#include "rpc-port/glib-internal.hh"
#include "rpc-port/log-private.hh"
+#include "rpc-port/peer-cred-internal.hh"
#include "rpc-port/request-internal.hh"
#include "rpc-port/response-internal.hh"
&delegate_client_[1]);
if (ret != RPC_PORT_ERROR_NONE) return ret;
+ auto peer_cred =
+ std::unique_ptr<PeerCred>(PeerCred::Get(main_client_[0]->GetFd()));
+ pid_ = peer_cred->GetPid();
+ _D("pid=%d", pid_);
if (sync) {
main_port_.reset(new ProxyPort(main_client_[0]->RemoveFd(),
- main_client_[1]->RemoveFd(), target_appid_,
- this, false));
+ main_client_[1]->RemoveFd(), pid_,
+ target_appid_, this, false));
delegate_port_.reset(new ProxyPort(delegate_client_[0]->RemoveFd(),
- delegate_client_[1]->RemoveFd(),
+ delegate_client_[1]->RemoveFd(), pid_,
target_appid_, this));
DebugPort::AddSession(port_name_, main_port_, delegate_port_);
listener_->OnConnected(target_appid_, main_port_.get());
void Proxy::SetPort(int fd, bool is_read, bool is_delegate) {
if (is_delegate) {
if (!delegate_port_)
- delegate_port_.reset(new ProxyPort(-1, -1, target_appid_, this));
+ delegate_port_.reset(new ProxyPort(-1, -1, pid_, target_appid_, this));
if (is_read) {
_W("[DELEGATE] read_fd=%d", fd);
}
} else {
if (!main_port_)
- main_port_.reset(new ProxyPort(-1, -1, target_appid_, this, false));
+ main_port_.reset(new ProxyPort(-1, -1, pid_, target_appid_, this, false));
if (is_read) {
_W("[MAIN] read_fd=%d", fd);
if (main_port_ && main_port_->GetReadFd() > 0 &&
main_port_->GetWriteFd() > 0 && delegate_port_ &&
delegate_port_->GetReadFd() > 0 && delegate_port_->GetWriteFd() > 0) {
- _W("[CONNECTED] target_appid=%s, port_name=%s, main_fd=%d:%d, "
+ _W("[CONNECTED] target=%s(%d), port_name=%s, main_fd=%d:%d, "
"delegate_fd=%d:%d",
- target_appid_.c_str(), port_name_.c_str(), main_port_->GetReadFd(),
+ target_appid_.c_str(), pid_, port_name_.c_str(), main_port_->GetReadFd(),
main_port_->GetWriteFd(), delegate_port_->GetReadFd(),
delegate_port_->GetWriteFd());
DebugPort::AddSession(port_name_, main_port_, delegate_port_);
private:
std::string port_name_;
std::string port_path_;
+ pid_t pid_ = -1;
std::shared_ptr<ProxyPort> main_port_;
std::shared_ptr<ProxyPort> delegate_port_;
IEventListener* listener_ = nullptr;
namespace rpc_port {
namespace internal {
-ProxyPort::ProxyPort(int read_fd, int write_fd, std::string id,
+ProxyPort::ProxyPort(int read_fd, int write_fd, pid_t pid, std::string id,
IEvent* listener, bool is_delegate)
- : Port(read_fd, write_fd, std::move(id)),
+ : Port(read_fd, write_fd, pid, std::move(id)),
listener_(listener),
is_delegate_(is_delegate) {
if (read_fd > -1)
#define PROXY_PORT_INTERNAL_HH_
#include <glib.h>
+#include <sys/types.h>
+#include <unistd.h>
#include <string>
virtual void OnSocketDisconnected(int fd) = 0;
};
- ProxyPort(int read_fd, int write_fd, std::string id, IEvent* listener,
- bool is_delegate = true);
+ ProxyPort(int read_fd, int write_fd, pid_t pid, std::string id,
+ IEvent* listener, bool is_delegate = true);
virtual ~ProxyPort();
bool IsDelegate() const;
#include "log-private.hh"
#include "parcel-internal.hh"
#include "port-internal.hh"
+#include "tracer-internal.hh"
#define MAX_PARCEL_SIZE (1024 * 1024 * 10)
internal::Port* pt = static_cast<internal::Port*>(port);
{
+ internal::Tracer tracer(pt->GetPid(), pt->GetId(), __FUNCTION__);
std::lock_guard<std::recursive_mutex> lock(pt->GetReadMutex());
int ret = rpc_port_read(port, &len, 4);
if (ret != 0) return ret;
internal::Port* pt = static_cast<internal::Port*>(port);
{
+ internal::Tracer tracer(pt->GetPid(), pt->GetId(), __FUNCTION__);
std::lock_guard<std::recursive_mutex> lock(pt->GetWriteMutex());
int ret = rpc_port_write(port, &len, sizeof(len));
if (ret != 0) return ret;
#include "port-internal.hh"
#include "proxy-internal.hh"
#include "stub-internal.hh"
+#include "tracer-internal.hh"
#undef RPC_API
#define RPC_API extern "C" __attribute__((visibility("default")))
if (h == nullptr || appid == nullptr || port == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
+ rpc_port::internal::Tracer tracer(-1, appid, __FUNCTION__);
auto p = static_cast<std::shared_ptr<::ProxyExt>*>(h);
auto* proxy = p->get();
_W("rpc_port_proxy_connect(%p, %s, %s)", proxy, appid, port);
if (h == nullptr || appid == nullptr || port == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
+ rpc_port::internal::Tracer tracer(-1, appid, __FUNCTION__);
auto p = static_cast<std::shared_ptr<::ProxyExt>*>(h);
auto* proxy = p->get();
_W("rpc_port_proxy_connect(%p, %s, %s)", proxy, appid, port);
return RPC_PORT_ERROR_INVALID_PARAMETER;
_W("rpc_port_stub_listen(%p)", h);
+ rpc_port::internal::Tracer tracer(-1, "amd", __FUNCTION__);
auto p = static_cast<::StubExt*>(h);
std::lock_guard<std::recursive_mutex> lock(p->GetMutex());
}
void Stub::AddAcceptedPort(const std::string& sender_appid,
- const std::string& instance, const std::string& port_type, int fd) {
+ const std::string& instance,
+ const std::string& port_type, int fd, pid_t pid) {
std::lock_guard<std::recursive_mutex> lock(GetMutex());
if (port_type == kPortTypeMainWrite) {
ports_.emplace_back(
- new AcceptedPort(-1, fd, sender_appid, instance, this, false));
+ new AcceptedPort(-1, fd, pid, sender_appid, instance, this, false));
} else if (port_type == kPortTypeMainRead) {
auto port = FindPort(instance);
if (port) port->SetReadFd(fd);
} else if (port_type == kPortTypeDelegateWrite) {
ports_.emplace_back(
- new AcceptedPort(-1, fd, sender_appid, instance, this, true));
+ new AcceptedPort(-1, fd, pid, sender_appid, instance, this, true));
} else if (port_type == kPortTypeDelegateRead) {
auto port = FindDelegatePort(instance);
if (port) port->SetReadFd(fd);
client->SetNonblock();
int client_fd = client->RemoveFd();
AddAcceptedPort(app_id, request->GetInstance(), request->GetPortType(),
- client_fd);
+ client_fd, cred->GetPid());
};
int res;
private:
void AddAcceptedPort(const std::string& sender_appid,
- const std::string& instance, const std::string& port_type, int fd);
+ const std::string& instance,
+ const std::string& port_type, int fd, pid_t pid);
void RemoveAcceptedPorts(std::string instance);
std::recursive_mutex& GetMutex() const;
int GetFdFromSystemd();
--- /dev/null
+/*
+ * Copyright (c) 2017 - 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "rpc-port/tracer-internal.hh"
+
+#include <dlog.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <utility>
+
+namespace rpc_port {
+namespace internal {
+
+Tracer::Tracer(pid_t dest_pid, std::string dest, std::string func)
+ : dest_pid_(dest_pid),
+ dest_(std::move(dest)),
+ func_(std::move(func)),
+ start_(std::chrono::steady_clock::now()) {}
+
+Tracer::~Tracer() {
+ auto end = std::chrono::steady_clock::now();
+ std::chrono::duration<double> elapsed_time = end - start_;
+ if (elapsed_time.count() > 0.1f) {
+ auto start_time = std::chrono::duration_cast<std::chrono::duration<double>>(
+ start_.time_since_epoch())
+ .count();
+ auto end_time = std::chrono::duration_cast<std::chrono::duration<double>>(
+ end.time_since_epoch())
+ .count();
+ dlog_print(DLOG_INFO, "VTRACE",
+ "[%s]:Took:%.3f s:[%.3f~%.3f]:S[%d]:D[%d:%s]", func_.c_str(),
+ elapsed_time.count(), start_time, end_time, gettid(), dest_pid_,
+ dest_.c_str());
+ }
+}
+
+} // namespace internal
+} // namespace rpc_port
--- /dev/null
+/*
+ * Copyright (c) 2017 - 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TRACER_INTERNAL_HH_
+#define TRACER_INTERNAL_HH_
+
+#include <unistd.h>
+
+#include <chrono>
+#include <string>
+
+namespace rpc_port {
+namespace internal {
+
+class Tracer {
+ public:
+ explicit Tracer(pid_t dest_pid, std::string dest, std::string func);
+ ~Tracer();
+
+ private:
+ pid_t dest_pid_;
+ std::string dest_;
+ std::string func_;
+ std::chrono::time_point<std::chrono::steady_clock> start_;
+};
+
+} // namespace internal
+} // namespace rpc_port
+
+#endif // TRACER_INTERNAL_HH_