1ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo/* Copyright (c) 2013, The Linux Foundation. All rights reserved. 2ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * 3ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * Redistribution and use in source and binary forms, with or without 4ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * modification, are permitted provided that the following conditions are 5ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * met: 6ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * * Redistributions of source code must retain the above copyright 7ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * notice, this list of conditions and the following disclaimer. 8ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * * Redistributions in binary form must reproduce the above 9ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * copyright notice, this list of conditions and the following 10ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * disclaimer in the documentation and/or other materials provided 11ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * with the distribution. 12ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * * Neither the name of The Linux Foundation nor the names of its 13ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * contributors may be used to endorse or promote products derived 14ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * from this software without specific prior written permission. 15ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * 16ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo */ 28ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 29ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#ifndef __PLATFORM_LIB_MACROS_H__ 30ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define __PLATFORM_LIB_MACROS_H__ 31ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 32ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#include <sys/time.h> 33ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 34ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define TS_PRINTF(format, x...) \ 35ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo{ \ 36ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo struct timeval tv; \ 37ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo struct timezone tz; \ 38ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo int hh, mm, ss; \ 39ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo gettimeofday(&tv, &tz); \ 40ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo hh = tv.tv_sec/3600%24; \ 41ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo mm = (tv.tv_sec%3600)/60; \ 42ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo ss = tv.tv_sec%60; \ 43ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo fprintf(stdout,"%02d:%02d:%02d.%06ld]" format "\n", hh, mm, ss, tv.tv_usec,##x); \ 44ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo} 45ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 46ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 47ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#ifdef USE_GLIB 48ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 49ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define strlcat g_strlcat 50ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define strlcpy g_strlcpy 51ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 52ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define ALOGE(format, x...) TS_PRINTF("E/%s (%d): " format , LOG_TAG, getpid(), ##x) 53ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define ALOGW(format, x...) TS_PRINTF("W/%s (%d): " format , LOG_TAG, getpid(), ##x) 54ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define ALOGI(format, x...) TS_PRINTF("I/%s (%d): " format , LOG_TAG, getpid(), ##x) 55ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define ALOGD(format, x...) TS_PRINTF("D/%s (%d): " format , LOG_TAG, getpid(), ##x) 56ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define ALOGV(format, x...) TS_PRINTF("V/%s (%d): " format , LOG_TAG, getpid(), ##x) 57ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 58ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define GETTID_PLATFORM_LIB_ABSTRACTION (syscall(SYS_gettid)) 59ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 60ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define LOC_EXT_CREATE_THREAD_CB_PLATFORM_LIB_ABSTRACTION createPthread 61ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define ELAPSED_MILLIS_SINCE_BOOT_PLATFORM_LIB_ABSTRACTION (elapsedMillisSinceBoot()) 62ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 63ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 64ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#else 65ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 66ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#ifdef __cplusplus 67ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russoextern "C" { 68ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#endif 69ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russopid_t gettid(void); 70ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 71ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#ifdef __cplusplus 72ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo} 73ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#endif 74ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 75ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define GETTID_PLATFORM_LIB_ABSTRACTION (gettid()) 76ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define LOC_EXT_CREATE_THREAD_CB_PLATFORM_LIB_ABSTRACTION android::AndroidRuntime::createJavaThread 77ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#define ELAPSED_MILLIS_SINCE_BOOT_PLATFORM_LIB_ABSTRACTION (android::elapsedRealtime()) 78ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 79ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#endif 80ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo 81ec6e5d3a2597d37d5b1d98911cb06218cdf19bf1Dante Russo#endif 82