/* * Copyright (c) 2016-present Samsung Electronics Co., Ltd * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA */ /* * Copyright (c) 2010 Mike Lovell * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "Escargot.h" #include "Vector.h" #include "Util.h" #if defined(__ANDROID__) #include #elif defined(_WIN32) // https : // gist.github.com/ugovaretto/5875385 #include < time.h > #include < windows.h > #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 #else #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL #endif struct timezone { int tz_minuteswest; /* minutes W of Greenwich */ int tz_dsttime; /* type of dst correction */ }; int gettimeofday(struct timeval *tv, struct timezone *tz) { FILETIME ft; unsigned __int64 tmpres = 0; static int tzflag = 0; if (NULL != tv) { GetSystemTimeAsFileTime(&ft); tmpres |= ft.dwHighDateTime; tmpres <<= 32; tmpres |= ft.dwLowDateTime; tmpres /= 10; /*convert into microseconds*/ /*converting file time to unix epoch*/ tmpres -= DELTA_EPOCH_IN_MICROSECS; tv->tv_sec = (long)(tmpres / 1000000UL); tv->tv_usec = (long)(tmpres % 1000000UL); } if (NULL != tz) { if (!tzflag) { _tzset(); tzflag++; } tz->tz_minuteswest = _timezone / 60; tz->tz_dsttime = _daylight; } return 0; } #else #include #include #include #endif namespace Escargot { uint64_t fastTickCount() { #if defined(CLOCK_MONOTONIC_COARSE) timespec ts; clock_gettime(CLOCK_MONOTONIC_COARSE, &ts); return ts.tv_sec * 1000UL + ts.tv_nsec / 1000000UL; #else return tickCount(); #endif } uint64_t tickCount() { struct timeval gettick; gettimeofday(&gettick, NULL); return (uint64_t)gettick.tv_sec * 1000UL + gettick.tv_usec / 1000UL; } uint64_t longTickCount() { struct timeval gettick; gettimeofday(&gettick, NULL); return (uint64_t)gettick.tv_sec * 1000000UL + gettick.tv_usec; } uint64_t timestamp() { struct timeval tv; gettimeofday(&tv, NULL); return (uint64_t)tv.tv_sec * 1000UL + tv.tv_usec / 1000UL; } ProfilerTimer::~ProfilerTimer() { uint64_t end = longTickCount(); float time = (float)((end - m_start) / 1000.f); ESCARGOT_LOG_INFO("did %s in %f ms\n", m_msg, time); } LongTaskFinder::~LongTaskFinder() { uint64_t end = longTickCount(); float time = (float)((end - m_start) / 1000.f); if (time >= m_loggingTime) { ESCARGOT_LOG_INFO("found long task %s in %f ms\n", m_msg, time); } } } // namespace Escargot