env.AppendUnique(LIBS = ['dl', 'pthread'])
env.AppendUnique(CCFLAGS = ['-D__TIZEN__', '-D_GNU_SOURCE', '-DTIZEN_DEBUG_ENABLE'])
-env.ParseConfig("pkg-config dlog --cflags --libs")
+env.ParseConfig("pkg-config dlog ttrace --cflags --libs")
# Set arch flags : It will be handled by Tizen build system.
# TODO : Currently Hardcoded WIFI_ADAPTER. Change it to generic
CFLAGS.debug = -DWITH_POSIX -D__TIZEN__ -Wall -std=c99 -DSLP_SDK_LOG -g -D_GNU_SOURCE -DTIZEN_DEBUG_ENABLE -DTB_LOG $(ADAPTER_MACRO)
CFLAGS.release = -DWITH_POSIX -D__TIZEN__ -Wall -std=c99 -DSLP_SDK_LOG -D_GNU_SOURCE -DTIZEN_DEBUG_ENABLE -DTB_LOG $(ADAPTER_MACRO)
-COMPILEFLAG = `pkg-config --cflags --libs capi-network-wifi dlog capi-network-bluetooth glib-2.0`
+COMPILEFLAG = `pkg-config --cflags --libs capi-network-wifi dlog ttrace capi-network-bluetooth glib-2.0`
# Include files will be copied into a single folder on gbsbuild.
# NO NEED to mention the path explicitly.
%{!?WITH_TCP: %define WITH_TCP 0}
BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(ttrace)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(capi-network-connection)
BuildRequires: pkgconfig(capi-network-wifi)
if env.get('LOGGING'):
env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-env.ParseConfig("pkg-config --cflags --libs capi-network-wifi capi-network-connection dlog glib-2.0")
+env.ParseConfig("pkg-config --cflags --libs capi-network-wifi capi-network-connection dlog ttrace glib-2.0")
if 'ALL' in transport:
env.AppendUnique(CPPDEFINES = ['WIFI_ADAPTER', 'NO_ETHERNET_ADAPTER','EDR_ADAPTER','LE_ADAPTER'])
print "CA Transport is ALL"
#include "caremotehandler.h"
#include "caprotocolmessage.h"
#include "logger.h"
+#include "trace.h"
#ifndef WITH_UPSTREAM_LIBCOAP
#include "coap/config.h"
#endif
VERIFY_NON_NULL(data, TAG, "data");
VERIFY_NON_NULL(data->remoteEndpoint, TAG, "remoteEndpoint");
+ OIC_TRACE_BEGIN(%s:CAProcessSendData, TAG);
+
CAResult_t res = CA_STATUS_FAILED;
CASendDataType_t type = data->type;
else
{
OIC_LOG(DEBUG, TAG, "request info, response info is empty");
+ OIC_TRACE_END();
return CA_STATUS_INVALID_PARAM;
}
CAErrorHandler(data->remoteEndpoint, pdu->transport_hdr, pdu->length, res);
coap_delete_list(options);
coap_delete_pdu(pdu);
+ OIC_TRACE_END();
return res;
}
}
CAErrorHandler(data->remoteEndpoint, pdu->transport_hdr, pdu->length, res);
coap_delete_list(options);
coap_delete_pdu(pdu);
+ OIC_TRACE_END();
return res;
}
OIC_LOG_V(INFO, TAG, "retransmission is not enabled due to error, res : %d", res);
coap_delete_list(options);
coap_delete_pdu(pdu);
+ OIC_TRACE_END();
return res;
}
}
{
OIC_LOG(ERROR,TAG,"Failed to generate unicast PDU");
CASendErrorInfo(data->remoteEndpoint, info, CA_SEND_FAILED);
+ OIC_TRACE_END();
return CA_SEND_FAILED;
}
}
CAProcessMulticastData(data);
#endif
}
-
+ OIC_TRACE_END();
return CA_STATUS_OK;
}
VERIFY_NON_NULL_VOID(sep, TAG, "remoteEndpoint");
VERIFY_NON_NULL_VOID(data, TAG, "data");
+ OIC_TRACE_BEGIN(%s:CAReceivedPacketCallback, TAG);
+
if (0 == dataLen)
{
OIC_LOG(ERROR, TAG, "dataLen is zero");
+ OIC_TRACE_END();
return;
}
exit:
OIC_LOG(DEBUG, TAG, "received pdu data :");
OIC_LOG_BUFFER(DEBUG, TAG, data, dataLen);
+
+ OIC_TRACE_END();
}
void CAHandleRequestResponseCallbacks()
Command("./src/logger.cpp", "./src/logger.c", Copy("$TARGET", "$SOURCE"))
logger_src = ['./src/logger.cpp']
else:
- logger_src = ['./src/logger.c']
+ logger_src = ['./src/logger.c', './src/trace.c']
loggerlib = local_env.StaticLibrary('logger', logger_src)
local_env.InstallTarget(loggerlib, 'logger')
--- /dev/null
+//******************************************************************
+//
+// Copyright 2017 Samsung Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// 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 TRACE_H_
+#define TRACE_H_
+
+#ifdef __ANDROID__
+#include "logger.h"
+#elif defined(__TIZEN__)
+#include <ttrace.h>
+#elif defined(ARDUINO)
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+#ifdef __ANDROID__
+
+#define OIC_TRACE_BEGIN(MSG, ...) \
+ oic_trace_begin("OIC:"#MSG, ##__VA_ARGS__)
+#define OIC_TRACE_END() \
+ oic_trace_end()
+
+#elif defined(__TIZEN__)
+/* trace macro for Tizen. this will call ttrace api internally*/
+#define OIC_TRACE_BEGIN(MSG, ...) \
+ traceBegin(TTRACE_TAG_APP, "IOTIVITY:"#MSG, ##__VA_ARGS__)
+#define OIC_TRACE_END() \
+ traceEnd(TTRACE_TAG_APP)
+
+#elif defined(ARDUINO)
+/* trace macro for Arduino. currently this will call nothing*/
+#define OIC_TRACE_BEGIN(MSG, ...)
+#define OIC_TRACE_END()
+
+#else
+#define OIC_TRACE_BEGIN(MSG, ...)
+#define OIC_TRACE_END()
+
+#endif //endif
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#endif /* TRACE_H_ */
--- /dev/null
+//******************************************************************
+//
+// Copyright 2017 Samsung Mobile Communications GmbH All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// 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.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+// Defining _POSIX_C_SOURCE macro with 199309L (or greater) as value
+// causes header files to expose definitions
+// corresponding to the POSIX.1b, Real-time extensions
+// (IEEE Std 1003.1b-1993) specification
+//
+// For this specific file, see use of clock_gettime,
+// Refer to http://pubs.opengroup.org/stage7tc1/functions/clock_gettime.html
+// and to http://man7.org/linux/man-pages/man2/clock_gettime.2.html
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 200809L
+#endif
+
+#include "iotivity_config.h"
+
+// Pull in _POSIX_TIMERS feature test macro to check for
+// clock_gettime() support.
+#ifndef __TIZEN__
+
+#include "trace.h"
+#include "logger.h"
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#elif defined(HAVE_STRINGS_H)
+#include <strings.h>
+#endif
+
+#define FD_INITIAL_VALUE -1
+#define FD_NOT_EXIST -2
+#define MAX_BUF_SIZE 4096
+#define MAX_TRACE_LEN 524
+#define MAX_HEAD_LEN 8
+#define MAX_TAIL_LEN 13
+#define POS_LABEL_ST ((MAX_TRACE_LEN - MAX_HEAD_LEN))
+#define POS_LABEL_ED ((MAX_TRACE_LEN - MAX_TAIL_LEN))
+
+#define TAG "OIC_TRACER"
+
+#ifdef __ANDROID__
+/*
+* Currently android api level 21 is used for building iotivity project.
+* Since Atrace (aka. android trace) API has been provided by NDK above android api level 23,
+* we use ftrace directly as workaround to Atrace API until android build level is upgraded
+*/
+int g_trace_marker_hd=FD_INITIAL_VALUE;
+
+int oic_trace_init()
+{
+ OIC_LOG(INFO, TAG, "entering oic_trace_init");
+ int mounts;
+ char buf[MAX_BUF_SIZE] = {0};
+ ssize_t buflen;
+ char *line, *tmp1, *path = NULL;
+
+ if(g_trace_marker_hd == FD_INITIAL_VALUE)
+ {
+ mounts = open("/proc/mounts", O_RDONLY);
+ if (mounts < 0)
+ {
+ OIC_LOG(INFO, TAG, "no /proc/mounts");
+ return -1;
+ }
+
+ buflen = read(mounts, buf, sizeof(buf) - 1);
+ close(mounts);
+
+ if (buflen < 0)
+ {
+ OIC_LOG(INFO, TAG, "failed to read /proc/mounts");
+ return -1;
+ }
+
+ line = strtok_r(buf, "\n", &tmp1);
+ while (line)
+ {
+ char *tmp2, *tmp_path, *fstype;
+ /* "<dev> <mountpoint> <fs type> ..." */
+ strtok_r(line, " ", &tmp2);
+ tmp_path = strtok_r(NULL, " ", &tmp2);
+ fstype = strtok_r(NULL, " ", &tmp2);
+
+ if (strcmp(fstype, "debugfs") == 0)
+ {
+ path = tmp_path;
+ break;
+ }
+ line = strtok_r(NULL, "\n", &tmp1);
+ }
+
+ if (NULL == path)
+ {
+ OIC_LOG(INFO, TAG, "debugfs mountpoint not found");
+ return -1;
+ }
+
+ snprintf(buf, sizeof(buf) - 1, "%s/tracing/trace_marker", path);
+ g_trace_marker_hd = open(buf, O_WRONLY);
+ if (g_trace_marker_hd < 0)
+ {
+ OIC_LOG_V(INFO, TAG, "failed to open trace_marker file: %s (%d)", strerror(errno), errno);
+ return -1;
+ }
+ }
+ OIC_LOG_V(INFO, TAG, "exit oic_trace_init with: %d", g_trace_marker_hd);
+ return 0;
+}
+
+void oic_trace_begin(const char *name, ...)
+{
+ if (g_trace_marker_hd == FD_INITIAL_VALUE)
+ {
+ oic_trace_init();
+ }
+
+ if (g_trace_marker_hd > 0)
+ {
+ char buf[MAX_TRACE_LEN]={0};
+ int len = MAX_HEAD_LEN, ret = 0;
+ va_list ap;
+
+ va_start(ap, name);
+ snprintf(buf, MAX_TRACE_LEN, "B|%5d|", getpid());
+ len += vsnprintf(buf + MAX_HEAD_LEN, POS_LABEL_ST, name, ap);
+ va_end(ap);
+
+ if (len > MAX_TRACE_LEN)
+ {
+ len = MAX_TRACE_LEN - 1;
+ }
+
+ ret = write(g_trace_marker_hd, buf, len);
+
+ if (ret < 0)
+ {
+ OIC_LOG_V(INFO, TAG, "error writing, len: %d, ret: %d, errno: %d at oic_trace_begin",
+ len, ret, errno);
+ }
+ }
+ else
+ {
+ OIC_LOG_V(INFO, TAG, "oic_trace_begin: invalid fd: %d", g_trace_marker_hd);
+ }
+}
+
+void oic_trace_end()
+{
+ if (FD_INITIAL_VALUE == g_trace_marker_hd)
+ {
+ oic_trace_init();
+ }
+
+ if (g_trace_marker_hd > 0)
+ {
+ int ret = 0, len = 1;
+ char end = 'E';
+
+ ret = write(g_trace_marker_hd, &end, len);
+ if (ret < 0)
+ {
+ OIC_LOG_V(INFO, TAG, "error writing, len: %d, ret: %d, errno: %d at oic_trace_end",
+ len, ret, errno);
+ }
+ }
+ else
+ {
+ OIC_LOG_V(INFO, TAG, "oic_trace_end: invalid fd: %d", g_trace_marker_hd);
+ }
+}
+
+#elif defined ARDUINO
+/* TODO: Trace api for ARDUINO and others will be implemented */
+#endif //ARDUINO
+
+#endif // #ifndef __TIZEN__
%{!?WITH_TCP: %define WITH_TCP 0}
BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(ttrace)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(capi-network-connection)
BuildRequires: pkgconfig(capi-network-wifi)
if env.get('LOGGING'):
env.AppendUnique(CPPDEFINES = ['TB_LOG'])
-env.ParseConfig("pkg-config --cflags --libs capi-network-wifi capi-network-connection dlog glib-2.0")
+env.ParseConfig("pkg-config --cflags --libs capi-network-wifi capi-network-connection dlog ttrace glib-2.0")
if 'ALL' in transport:
env.AppendUnique(CPPDEFINES = ['WIFI_ADAPTER', 'NO_ETHERNET_ADAPTER','EDR_ADAPTER','LE_ADAPTER'])
print "CA Transport is ALL"
#include "oic_malloc.h"
#include "oic_string.h"
#include "logger.h"
+#include "trace.h"
#include "ocserverrequest.h"
#include "secureresourcemanager.h"
#include "psinterface.h"
VERIFY_NON_NULL_NR(responseInfo, FATAL);
OIC_LOG(INFO, TAG, "Enter HandleCAResponses");
-
+ OIC_TRACE_BEGIN(%s:HandleCAResponses, TAG);
#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
#ifdef ROUTING_GATEWAY
bool needRIHandling = false;
if(ret != OC_STACK_OK || !needRIHandling)
{
OIC_LOG_V(INFO, TAG, "Routing status![%d]. Not forwarding to RI", ret);
+ OIC_TRACE_END();
return;
}
#endif
OCHandleResponse(endPoint, responseInfo);
OIC_LOG(INFO, TAG, "Exit HandleCAResponses");
+ OIC_TRACE_END();
}
/*
VERIFY_NON_NULL_NR(errorInfo, FATAL);
OIC_LOG(INFO, TAG, "Enter HandleCAErrorResponse");
+ OIC_TRACE_BEGIN(%s:HandleCAErrorResponse, TAG);
ClientCB *cbNode = GetClientCB(errorInfo->info.token,
errorInfo->info.tokenLength, NULL, NULL);
}
OIC_LOG(INFO, TAG, "Exit HandleCAErrorResponse");
+ OIC_TRACE_END();
}
/*
void HandleCARequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* requestInfo)
{
OIC_LOG(INFO, TAG, "Enter HandleCARequests");
+ OIC_TRACE_BEGIN(%s:HandleCARequests, TAG);
if (!endPoint)
{
OIC_LOG(ERROR, TAG, "endPoint is NULL");
+ OIC_TRACE_END();
return;
}
if (!requestInfo)
{
OIC_LOG(ERROR, TAG, "requestInfo is NULL");
+ OIC_TRACE_END();
return;
}
if (OC_STACK_OK != ret || !needRIHandling)
{
OIC_LOG_V(INFO, TAG, "Routing status![%d]. Not forwarding to RI", ret);
+ OIC_TRACE_END();
return;
}
#endif
OCHandleRequests(endPoint, requestInfo);
}
OIC_LOG(INFO, TAG, "Exit HandleCARequests");
+ OIC_TRACE_END();
}
//-----------------------------------------------------------------------------
%if "%{TARGET_OS}" == "tizen"
BuildRequires: gettext-tools
BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(ttrace)
BuildRequires: pkgconfig(capi-network-connection)
BuildRequires: pkgconfig(capi-network-wifi)
BuildRequires: pkgconfig(capi-network-bluetooth) >= 0.1.52