testframework: systrace c interface support

support for c interface for systrace

Change-Id: I854741ae05dbb26c6b80a6f7dc3d2c75482eae37
diff --git a/Android.mk b/Android.mk
index abab3ad..b47ec26 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,31 +1,36 @@
 LOCAL_PATH:= $(call my-dir)
 include $(CLEAR_VARS)
 
+#copy include file to /system/include
 LOCAL_COPY_HEADERS_TO := testframework
 LOCAL_COPY_HEADERS := inc/testframework.h
+LOCAL_COPY_HEADERS += inc/systracer.h
 include $(BUILD_COPY_HEADERS)
 
-ifdef TARGET_USES_TESTFRAMEWORK
 #testframework lib
+include $(CLEAR_VARS)
 LOCAL_PRELINK_MODULE := false
 LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)
-LOCAL_SRC_FILES := \
+LOCAL_SRC_FILES := src/Systracer.cpp
+
+LOCAL_SHARED_LIBRARIES := libutils libcutils
+
+ifdef TARGET_USES_TESTFRAMEWORK
+LOCAL_CFLAGS := -DCUSTOM_EVENTS_TESTFRAMEWORK
+LOCAL_C_INCLUDES := $(TOP)/vendor/qcom/opensource/testframework
+LOCAL_C_INCLUDES += $(TOP)/frameworks/native/include
+LOCAL_SRC_FILES += \
         src/TestFrameworkApi.cpp \
         src/TestFrameworkCommon.cpp \
         src/TestFrameworkHash.cpp \
         src/TestFrameworkService.cpp
 
-LOCAL_CFLAGS := -DCUSTOM_EVENTS_TESTFRAMEWORK
-
-LOCAL_C_INCLUDES := $(TOP)/vendor/qcom/opensource/testframework
-
-LOCAL_SHARED_LIBRARIES += libutils libcutils
-
 ifeq ($(TF_FEATURE_USES_BINDER),true)
 LOCAL_CFLAGS += -DTF_FEATURE_USE_BINDER
 LOCAL_SRC_FILES += src/TestFramework.cpp
 LOCAL_SHARED_LIBRARIES += libbinder
 endif
+endif
 
 ifeq ($(call is-android-codename,JELLY_BEAN),true)
 LOCAL_CFLAGS += -DJB
@@ -37,6 +42,7 @@
 include $(BUILD_SHARED_LIBRARY)
 
 #testframework servcice
+ifdef TARGET_USES_TESTFRAMEWORK
 include $(CLEAR_VARS)
 
 LOCAL_PRELINK_MODULE := false
diff --git a/inc/systracer.h b/inc/systracer.h
new file mode 100644
index 0000000..1072d1c
--- /dev/null
+++ b/inc/systracer.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. 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 Linux Foundation 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 "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER 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 ANDROID_SYS_TRACER_H
+#define ANDROID_SYS_TRACER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// These tags must be kept in sync with frameworks/native/include/utils/Trace.h.
+#define ATRACE_TAG_NEVER            0       // The "never" tag is never enabled.
+#define ATRACE_TAG_ALWAYS           (1<<0)  // The "always" tag is always enabled.
+#define ATRACE_TAG_GRAPHICS         (1<<1)
+#define ATRACE_TAG_INPUT            (1<<2)
+#define ATRACE_TAG_VIEW             (1<<3)
+#define ATRACE_TAG_WEBVIEW          (1<<4)
+#define ATRACE_TAG_WINDOW_MANAGER   (1<<5)
+#define ATRACE_TAG_ACTIVITY_MANAGER (1<<6)
+#define ATRACE_TAG_SYNC_MANAGER     (1<<7)
+#define ATRACE_TAG_AUDIO            (1<<8)
+#define ATRACE_TAG_VIDEO            (1<<9)
+#define ATRACE_TAG_CAMERA           (1<<10)
+#define ATRACE_TAG_LAST             ATRACE_TAG_CAMERA
+
+//not implemented
+#ifdef ATRACE_CALL
+#undef ATRACE_CALL
+#undef ATRACE_NAME
+#endif
+#define ATRACE_CALL()
+#define ATRACE_NAME(name)
+
+// ATRACE_INT traces a named integer value.  This can be used to track how the
+// value changes over time in a trace.
+#ifdef ATRACE_INT
+#undef ATRACE_INT
+#endif
+#define ATRACE_INT(name, value) traceCounter(ATRACE_TAG, name, value)
+
+// ATRACE_ENABLED returns true if the trace tag is enabled.  It can be used as a
+// guard condition around more expensive trace calculations.
+#ifdef ATRACE_ENABLED
+#undef ATRACE_ENABLED
+#endif
+#define ATRACE_ENABLED() isTagEnabled(ATRACE_TAG)
+
+
+void traceBegin(uint64_t tag, const char* name);
+void traceEnd(uint64_t tag);
+void traceCounter(uint64_t tag, const char* name, int32_t value);
+int isTagEnabled(uint64_t tag);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // ANDROID_TEST_FRAMEWORK_H
diff --git a/inc/testframework.h b/inc/testframework.h
index 407162c..dd83dd1 100644
--- a/inc/testframework.h
+++ b/inc/testframework.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -31,7 +31,6 @@
 #define ANDROID_TEST_FRAMEWORK_H
 
 #include <stdarg.h>
-
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/src/Systracer.cpp b/src/Systracer.cpp
new file mode 100644
index 0000000..c741039
--- /dev/null
+++ b/src/Systracer.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013, The Linux Foundation. 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 Linux Foundation 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 "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER 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.
+ */
+
+#include <utils/Trace.h>
+#include "../inc/systracer.h"
+
+void traceBegin(uint64_t tag, const char* name) {
+  android::Tracer::traceBegin(tag, name);
+  return;
+}
+
+void traceEnd(uint64_t tag) {
+  android::Tracer::traceEnd(tag);
+  return;
+}
+
+void traceCounter(uint64_t tag, const char* name, int32_t value) {
+  android::Tracer::traceCounter(tag, name, value);
+  return;
+}
+
+int isTagEnabled(uint64_t tag) {
+  return android::Tracer::isTagEnabled(tag);
+}
+
+