Path: blob/master/libmupen64plus/mupen64plus-core/src/r4300/profile.c
2 views
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *1* Mupen64plus - profile.c *2* Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *3* Copyright (C) 2012 CasualJames *4* Copyright (C) 2002 Hacktarux *5* *6* This program is free software; you can redistribute it and/or modify *7* it under the terms of the GNU General Public License as published by *8* the Free Software Foundation; either version 2 of the License, or *9* (at your option) any later version. *10* *11* This program is distributed in the hope that it will be useful, *12* but WITHOUT ANY WARRANTY; without even the implied warranty of *13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *14* GNU General Public License for more details. *15* *16* You should have received a copy of the GNU General Public License *17* along with this program; if not, write to the *18* Free Software Foundation, Inc., *19* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *20* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */2122#ifdef PROFILE23#include "r4300.h"2425#include "api/m64p_types.h"26#include "api/callbacks.h"2728static long long int time_in_section[5];29static long long int last_start[5];3031#if defined(WIN32) && !defined(__MINGW32__)32// timing33#include <windows.h>34static long long int get_time(void)35{36LARGE_INTEGER counter;37QueryPerformanceCounter(&counter);38return counter.QuadPart;39}40static long long int time_to_nsec(long long int time)41{42static LARGE_INTEGER freq = { 0 };43if (freq.QuadPart == 0)44QueryPerformanceFrequency(&freq);45return time * 1000000000 / freq.QuadPart;46}4748#else /* Not WIN32 */49// timing50#include <time.h>51static long long int get_time(void)52{53struct timespec ts;54clock_gettime(CLOCK_MONOTONIC, &ts);55return (long long int)ts.tv_sec * 1000000000 + ts.tv_nsec;56}57static long long int time_to_nsec(long long int time)58{59return time;60}61#endif6263void start_section(int section_type)64{65last_start[section_type] = get_time();66}6768void end_section(int section_type)69{70long long int end = get_time();71time_in_section[section_type] += end - last_start[section_type];72}7374void refresh_stat()75{76long long int curr_time = get_time();77if(time_to_nsec(curr_time - last_start[ALL_SECTION]) >= 2000000000)78{79time_in_section[ALL_SECTION] = curr_time - last_start[ALL_SECTION];80DebugMessage(M64MSG_INFO, "gfx=%f%% - audio=%f%% - compiler=%f%%, idle=%f%%",81100.0 * (double)time_in_section[GFX_SECTION] / time_in_section[ALL_SECTION],82100.0 * (double)time_in_section[AUDIO_SECTION] / time_in_section[ALL_SECTION],83100.0 * (double)time_in_section[COMPILER_SECTION] / time_in_section[ALL_SECTION],84100.0 * (double)time_in_section[IDLE_SECTION] / time_in_section[ALL_SECTION]);85DebugMessage(M64MSG_INFO, "gfx=%llins - audio=%llins - compiler %llins - idle=%llins",86time_to_nsec(time_in_section[GFX_SECTION]),87time_to_nsec(time_in_section[AUDIO_SECTION]),88time_to_nsec(time_in_section[COMPILER_SECTION]),89time_to_nsec(time_in_section[IDLE_SECTION]));90time_in_section[GFX_SECTION] = 0;91time_in_section[AUDIO_SECTION] = 0;92time_in_section[COMPILER_SECTION] = 0;93time_in_section[IDLE_SECTION] = 0;94last_start[ALL_SECTION] = curr_time;95}96}9798#endif99100101102