From b8c641afc475fd8bd3839bcf0b079e839ea89114 Mon Sep 17 00:00:00 2001 From: Jinwoo Nam Date: Tue, 21 Aug 2012 20:52:12 +0900 Subject: [PATCH] tizen 2.0 beta --- CMakeLists.txt | 7 ++- debian/changelog | 7 --- debian/compat | 1 - debian/control | 24 --------- debian/dirs | 2 - debian/docs | 1 - debian/librua-0.install.in | 2 - debian/librua-0.postinst.in | 16 ------ debian/librua-dev.install.in | 3 -- debian/rules | 117 ------------------------------------------- include/perf-measure.h | 66 ++++++++++++++++++++++++ include/rua.h | 0 src/perf-measure.c | 63 +++++++++++++++++++++++ rua.c => src/rua.c | 16 +++++- test/CMakeLists.txt | 22 ++++++++ test/rua-test.c | 65 ++++++++++++++++++++++++ 16 files changed, 237 insertions(+), 175 deletions(-) delete mode 100644 debian/changelog delete mode 100644 debian/compat delete mode 100644 debian/control delete mode 100644 debian/dirs delete mode 100644 debian/docs delete mode 100644 debian/librua-0.install.in delete mode 100644 debian/librua-0.postinst.in delete mode 100644 debian/librua-dev.install.in delete mode 100755 debian/rules create mode 100644 include/perf-measure.h mode change 100644 => 100755 include/rua.h create mode 100644 src/perf-measure.c rename rua.c => src/rua.c (94%) create mode 100644 test/CMakeLists.txt create mode 100644 test/rua-test.c diff --git a/CMakeLists.txt b/CMakeLists.txt index fa96a14..01055ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,10 @@ SET(LIBDIR "\${prefix}/lib") SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}") SET(VERSION 0.1.0) -SET(SRCS rua.c) +SET(SRCS + src/perf-measure.c + src/rua.c +) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) @@ -39,3 +42,5 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkg INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/rua.h DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/rua_db.sql DESTINATION /opt/share/) + +#ADD_SUBDIRECTORY(test) diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index 3c7bc9e..0000000 --- a/debian/changelog +++ /dev/null @@ -1,7 +0,0 @@ -librua (0.1.0-33) unstable; urgency=low - - * Initial Release. - * Git: pkgs/l/librua - * Tag: librua_0.1.0-33 - - -- Jinwoo Nam Sat, 17 Mar 2012 16:52:46 +0900 diff --git a/debian/compat b/debian/compat deleted file mode 100644 index 7ed6ff8..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -5 diff --git a/debian/control b/debian/control deleted file mode 100644 index dcde5e6..0000000 --- a/debian/control +++ /dev/null @@ -1,24 +0,0 @@ -Source: librua -Section: libs -Priority: optional -Maintainer: Jinwoo Nam -Build-Depends: debhelper (>= 5), libsqlite3-dev, libslp-db-util-dev, sqlite3 -Standards-Version: 3.7.2 - -Package: librua-dev -Section: libs -Architecture: any -Depends: librua-0 (= ${Source-Version}), libsqlite3-dev, libslp-db-util-dev, sqlite3 -Description: recently used applcation library (development) - -Package: librua-0 -Section: libs -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, sqlite3 -Description: recently used application library (shared object) - -Package: librua-dbg -Section: debug -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, librua-0 (= ${Source-Version}) -Description: recently used application library (unstripped) diff --git a/debian/dirs b/debian/dirs deleted file mode 100644 index ca882bb..0000000 --- a/debian/dirs +++ /dev/null @@ -1,2 +0,0 @@ -usr/bin -usr/sbin diff --git a/debian/docs b/debian/docs deleted file mode 100644 index a0f0008..0000000 --- a/debian/docs +++ /dev/null @@ -1 +0,0 @@ -CMakeLists.txt diff --git a/debian/librua-0.install.in b/debian/librua-0.install.in deleted file mode 100644 index 3199eb6..0000000 --- a/debian/librua-0.install.in +++ /dev/null @@ -1,2 +0,0 @@ -@PREFIX@/lib/*.so.* -/opt/share/* diff --git a/debian/librua-0.postinst.in b/debian/librua-0.postinst.in deleted file mode 100644 index b658109..0000000 --- a/debian/librua-0.postinst.in +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -mkdir -p /opt/dbspace/ -sqlite3 /opt/dbspace/.rua.db < /opt/share/rua_db.sql -rm -rf /opt/share/rua_db.sql - -if [ ${USER} = "root" ] -then - chown root:5000 /opt/dbspace/.rua.db - chown root:5000 /opt/dbspace/.rua.db-journal -fi - -chmod 660 @DATADIR@/dbspace/.rua.db -chmod 660 @DATADIR@/dbspace/.rua.db-journal - - diff --git a/debian/librua-dev.install.in b/debian/librua-dev.install.in deleted file mode 100644 index 6975317..0000000 --- a/debian/librua-dev.install.in +++ /dev/null @@ -1,3 +0,0 @@ -@PREFIX@/include/* -@PREFIX@/lib/pkgconfig/*.pc -@PREFIX@/lib/*.so diff --git a/debian/rules b/debian/rules deleted file mode 100755 index 92570a1..0000000 --- a/debian/rules +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/make -f -# -*- makefile -*- -# Sample debian/rules that uses debhelper. -# This file was originally written by Joey Hess and Craig Small. -# As a special exception, when this file is copied by dh-make into a -# dh-make output file, you may use that output file without restriction. -# This special exception was added by Craig Small in version 0.37 of dh-make. - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - -CFLAGS ?= -Wall -g -LDFLAGS ?= -PREFIX ?= /usr -DATADIR ?= /opt - -ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) - CFLAGS += -O0 -else - CFLAGS += -O2 -endif - -LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed - -configure: configure-stamp -configure-stamp: - dh_testdir - # Add here commands to configure the package. - CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" cmake . -DCMAKE_INSTALL_PREFIX=$(PREFIX) - - touch configure-stamp - -build: build-stamp - -build-stamp: configure-stamp - dh_testdir - - # Add here commands to compile the package. - $(MAKE) - #docbook-to-man debian/wavplayer.sgml > wavplayer.1 - - for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ - cat $$f > $${f%.in}; \ - sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ - sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \ - done - - - touch $@ - -clean: - dh_testdir - dh_testroot - rm -f build-stamp configure-stamp - - # Add here commands to clean up after the build process. - -$(MAKE) clean - rm -rf CMakeCache.txt - rm -rf CMakeFiles - rm -rf cmake_install.cmake - rm -rf Makefile - rm -rf install_manifest.txt - - for f in `find $(CURDIR)/ -name "*.in"`; do \ - rm -f $${f%.in}; \ - done - - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - - # Add here commands to install the package into debian/wavplayer. - $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install - - mkdir -p $(CURDIR)/debian/tmp/opt/dbspace - -# Build architecture-independent files here. -binary-indep: build install -# We have nothing to do by default. - -# Build architecture-dependent files here. -binary-arch: build install - dh_testdir - dh_testroot - dh_installchangelogs - dh_installdocs - dh_installexamples - dh_install --sourcedir=debian/tmp -# dh_installmenu -# dh_installdebconf -# dh_installlogrotate -# dh_installemacsen -# dh_installpam -# dh_installmime -# dh_python -# dh_installinit -# dh_installcron -# dh_installinfo - dh_installman - dh_link - dh_strip --dbg-package=librua-dbg - dh_compress - dh_fixperms -# dh_perl - dh_makeshlibs - dh_installdeb - dh_shlibdeps - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/include/perf-measure.h b/include/perf-measure.h new file mode 100644 index 0000000..49dcc68 --- /dev/null +++ b/include/perf-measure.h @@ -0,0 +1,66 @@ +/* + * RUA + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee + * + * 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 __PERF_MEASURE__ +#define __PERF_MEASURE__ + +#include + + +//#define PERF_MEASURE_ENABLE + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef PERF_MEASURE_ENABLE + +unsigned int _perf_measure_start(const char *tag, char *func_name, int line); +unsigned int _perf_measure_end(const char *tag, unsigned int ts_start, + char *func_name, int line); + +#define PERF_MEASURE_START(tag) _perf_measure_start(tag, __func__,__LINE__) +#define PERF_MEASURE_END(tag, ts_start) \ + _perf_measure_end(tag, ts_start,__func__, __LINE__) + +#else + +#define PERF_MEASURE_START(tag) (0) +#define PERF_MEASURE_END(tag, ts_start) (0) + +#endif + + + + + + + + + + + + + +#ifdef __cplusplus +} +#endif +#endif /*__PERF_MEASURE__*/ diff --git a/include/rua.h b/include/rua.h old mode 100644 new mode 100755 diff --git a/src/perf-measure.c b/src/perf-measure.c new file mode 100644 index 0000000..5168852 --- /dev/null +++ b/src/perf-measure.c @@ -0,0 +1,63 @@ +/* + * RUA + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee + * + * 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 +#include + +unsigned int _perf_measure_start(const char *tag, char *func_name, int line) +{ + struct timeval t; + unsigned int ts_start; + + if (!tag) + return 0; + + gettimeofday(&t, NULL); + ts_start = t.tv_sec * 1000000UL + t.tv_usec; + + printf("### START [%s:%d] timestamp(%u)\n", func_name, line, ts_start); + + return ts_start; +} + +unsigned int _perf_measure_end(const char *tag, unsigned int ts_start, + char *func_name, int line) +{ + struct timeval t; + unsigned int ts_end; + unsigned int elapsed_time = 0; + + gettimeofday(&t, NULL); + ts_end = t.tv_sec * 1000000UL + t.tv_usec; + + if (ts_start) + elapsed_time = ts_end - ts_start; + + printf("### END [%s:%d] timestamp(%u)\n", func_name, line, ts_end); + + if (elapsed_time) + printf("### ELAPSED [%s:%d] timestamp(%u)\n", func_name, line, + elapsed_time); + + return ts_end; +} + diff --git a/rua.c b/src/rua.c similarity index 94% rename from rua.c rename to src/rua.c index 67a9245..9b5ef8b 100644 --- a/rua.c +++ b/src/rua.c @@ -21,7 +21,6 @@ /* * @file rua.c - * @author Noha Park (noha.park@samsung.com) * @version 0.1 */ @@ -33,6 +32,7 @@ #include "rua.h" #include "db-schema.h" +#include "perf-measure.h" #define RUA_DB_PATH "/opt/dbspace" #define RUA_DB_NAME ".rua.db" @@ -108,6 +108,9 @@ int rua_add_history(struct rua_rec *rec) char query[QUERY_MAXLEN]; sqlite3_stmt *stmt; + unsigned int timestamp; + timestamp = PERF_MEASURE_START("RUA"); + if (_db == NULL) return -1; @@ -151,6 +154,8 @@ int rua_add_history(struct rua_rec *rec) return -1; } + PERF_MEASURE_END("RUA", timestamp); + return r; } @@ -268,6 +273,9 @@ int rua_is_latest_app(const char *pkg_name) int rua_init(void) { + unsigned int timestamp; + timestamp = PERF_MEASURE_START("RUA"); + if (_db) { return 0; } @@ -279,16 +287,22 @@ int rua_init(void) if (_db == NULL) return -1; + PERF_MEASURE_END("RUA", timestamp); + return 0; } int rua_fini(void) { + unsigned int timestamp; + timestamp = PERF_MEASURE_START("RUA"); + if (_db) { db_util_close(_db); _db = NULL; } + PERF_MEASURE_END("RUA", timestamp); return 0; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..3f7d5c8 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,22 @@ +SET(RUATEST rua-test) +SET(RUATEST_SRCS rua-test.c) +SET(RUATEST_VENDOR samsung) +SET(RUATEST_DIR /usr/bin) +SET(RUATEST_LOCALEDIR /usr/share/locale) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +PKG_CHECK_MODULES(RUATEST_PKGS REQUIRED + ) + +FOREACH(flag ${RUATEST_PKGS_CFLAGS}) + SET(RUATEST_CFLAGS "${RUATEST_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(RUATEST_CFLAGS, "${RUATEST_CFLAGS} -DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") + +ADD_EXECUTABLE(${RUATEST} ${RUATEST_SRCS}) +SET_TARGET_PROPERTIES(${RUATEST} PROPERTIES COMPILE_FLAGS "${RUATEST_CFLAGS}") +TARGET_LINK_LIBRARIES(${RUATEST} ${PROJECT_NAME} ${RUATEST_PKGS_LDFLAGS}) + +INSTALL(TARGETS ${RUATEST} DESTINATION bin) + diff --git a/test/rua-test.c b/test/rua-test.c new file mode 100644 index 0000000..6fdd2e0 --- /dev/null +++ b/test/rua-test.c @@ -0,0 +1,65 @@ +/* + * RUA + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jayoun Lee + * + * 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 +#include +#include +#include +#include + +#include "rua.h" + +int __add_history(char *pkgname) +{ + int ret = 0; + struct rua_rec rec; + char apppath[FILENAME_MAX] = ""; + + snprintf(apppath, "/opt/apps/%s", pkgname, FILENAME_MAX); + memset(&rec, 0, sizeof(rec)); + rec.pkg_name = pkgname; + rec.app_path = apppath; + + ret = rua_init(); + if (ret) { + fprintf(stderr, "error rua_init()\n"); + return -1; + } + + ret = rua_add_history(&rec); + + rua_fini(); + + return ret; + +} + +int main(int argc, char* argv[]) +{ + int ret = 0; + + if (argc != 2) + return 0; + ret = __add_history(argv[1]); + return 0; +} + + -- 2.7.4