Create performance_counters

This commit is contained in:
twinaphex 2016-05-10 08:53:14 +02:00
parent 4a49c197c9
commit b79b2dca13
39 changed files with 262 additions and 183 deletions

View File

@ -205,6 +205,7 @@ OBJ += frontend/frontend.o \
record/record_driver.o \
record/drivers/record_null.o \
performance.o \
performance_counters.o \
verbosity.o
ifneq ($(HAVE_GETOPT_LONG), 1)

View File

@ -30,7 +30,7 @@
#include "../configuration.h"
#include "../retroarch.h"
#include "../runloop.h"
#include "../performance.h"
#include "../performance_counters.h"
#include "../verbosity.h"
#include "../list_special.h"

View File

@ -30,6 +30,7 @@
#include "../config_file_userdata.h"
#include "../frontend/frontend_driver.h"
#include "../performance.h"
#include "../performance_counters.h"
#include "../dynamic.h"
struct rarch_dsp_plug

View File

@ -22,6 +22,7 @@
#include "../config_file_userdata.h"
#ifdef RARCH_INTERNAL
#include "../performance.h"
#include "../performance_counters.h"
#endif
#ifndef DONT_HAVE_STRING_LIST
#include "../list_special.h"

View File

@ -21,7 +21,7 @@
#include <rthreads/rthreads.h>
#include "audio_thread_wrapper.h"
#include "../performance.h"
#include "../performance_counters.h"
#include "../verbosity.h"
typedef struct audio_thread

View File

@ -25,6 +25,7 @@
#ifdef RARCH_INTERNAL
#include "../performance.h"
#include "../performance_counters.h"
#endif
/**

View File

@ -18,7 +18,7 @@
#include "../audio_driver.h"
#include "../../configuration.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../../runloop.h"
typedef struct

View File

@ -18,7 +18,7 @@
#include "../audio_driver.h"
#include "../../configuration.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../../runloop.h"
#include "../../ctr/ctr_debug.h"

View File

@ -41,7 +41,7 @@
#include <compat/strl.h>
#include "../camera_driver.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../../verbosity.h"
struct buffer

View File

@ -26,7 +26,7 @@
#include "libretro.h"
#include "network/net_http_special.h"
#include "configuration.h"
#include "performance.h"
#include "performance_counters.h"
#include "msg_hash.h"
#include "runloop.h"
#include "core.h"

View File

@ -44,7 +44,7 @@
#include "autosave.h"
#include "core_info.h"
#include "core_type.h"
#include "performance.h"
#include "performance_counters.h"
#include "dynamic.h"
#include "content.h"
#include "movie.h"

View File

@ -37,6 +37,7 @@
#include "location/location_driver.h"
#include "record/record_driver.h"
#include "core.h"
#include "performance_counters.h"
#include "performance.h"
#include "system.h"
#include "gfx/video_context_driver.h"

View File

@ -39,7 +39,6 @@
#include <formats/image.h>
#include "../../driver.h"
#include "../../performance.h"
#include "../../libretro.h"
#include "../../general.h"
#include "../../retroarch.h"

View File

@ -47,7 +47,7 @@
#endif
#include "../../core.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../../defines/d3d_defines.h"
#include "../../verbosity.h"

View File

@ -30,7 +30,7 @@
#include "render_chain_driver.h"
#include "../video_driver.h"
#include "../../general.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../../verbosity.h"
#include "d3d.h"

View File

@ -28,7 +28,7 @@
#include "../../driver.h"
#include "../../retroarch.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#define CTR_TOP_FRAMEBUFFER_WIDTH 400
#define CTR_TOP_FRAMEBUFFER_HEIGHT 240

View File

@ -34,7 +34,7 @@
#include "../../driver.h"
#include "../../record/record_driver.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../../libretro.h"
#include "../../general.h"

View File

@ -25,7 +25,7 @@
#include "../../driver.h"
#include "../../general.h"
#include "../../retroarch.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../../verbosity.h"
#include "../video_context_driver.h"
#include "../font_driver.h"

View File

@ -25,7 +25,7 @@
#include "../../driver.h"
#include "../../general.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../video_frame.h"
#include "../video_context_driver.h"

View File

@ -30,7 +30,7 @@
#include "../../general.h"
#include "../../retroarch.h"
#include "../../driver.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../font_driver.h"
#include "../../content.h"
#include "../../runloop.h"

View File

@ -36,7 +36,7 @@
#include "../../driver.h"
#include "../../record/record_driver.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../../libretro.h"
#include "../../general.h"

View File

@ -34,6 +34,7 @@
#include "../retroarch.h"
#include "../runloop.h"
#include "../performance.h"
#include "../performance_counters.h"
#include "../list_special.h"
#include "../core.h"
#include "../system.h"

View File

@ -25,6 +25,7 @@
#include "../dynamic.h"
#include "../general.h"
#include "../performance.h"
#include "../performance_counters.h"
#include "../verbosity.h"
#include "video_filter.h"
#include "video_filters/softfilter.h"

View File

@ -24,6 +24,7 @@
#include "font_driver.h"
#include "video_shader_driver.h"
#include "../performance.h"
#include "../performance_counters.h"
#include "../runloop.h"
#include "../verbosity.h"

View File

@ -63,6 +63,7 @@ ENCODINGS
PERFORMANCE
============================================================ */
#include "../performance.c"
#include "../performance_counters.c"
/*============================================================
COMPATIBILITY

View File

@ -30,7 +30,7 @@
#include "../input_config.h"
#include "../input_joypad_driver.h"
#include "../drivers_keyboard/keyboard_event_android.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../../general.h"
#include "../../driver.h"

View File

@ -31,7 +31,7 @@
#include "../movie.h"
#include "../core.h"
#include "../runloop.h"
#include "../performance.h"
#include "../performance_counters.h"
#include "../verbosity.h"
#include "../audio/audio_driver.h"

View File

@ -30,7 +30,7 @@
#include "../../managers/core_option_manager.h"
#include "../../managers/cheat_manager.h"
#include "../../general.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../../system.h"
#include "../../intl/intl.h"

View File

@ -30,7 +30,7 @@
#include "../../general.h"
#include "../../retroarch.h"
#include "../../system.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../../gfx/video_shader_driver.h"

View File

@ -29,6 +29,7 @@
#include "../../configuration.h"
#include "../../performance.h"
#include "../../performance_counters.h"
#include "../../input/input_autodetect.h"
#include "../../input/input_config.h"
#include "../../cheevos.h"

View File

@ -23,6 +23,7 @@
#include "menu_animation.h"
#include "../configuration.h"
#include "../performance.h"
#include "../performance_counters.h"
#define IDEAL_DELTA_TIME (1.0 / 60.0 * 1000000.0)

View File

@ -44,7 +44,7 @@
#include "../git_version.h"
#include "../input/input_config.h"
#include "../list_special.h"
#include "../performance.h"
#include "../performance_counters.h"
#include "../core_info.h"
#ifdef HAVE_CHEEVOS

View File

@ -40,6 +40,7 @@
#include "../general.h"
#include "../managers/cheat_manager.h"
#include "../performance.h"
#include "../performance_counters.h"
#include "../core.h"
#include "../input/input_joypad_driver.h"
#include "../input/input_remapping.h"

View File

@ -59,7 +59,7 @@
#include "../input/input_config.h"
#include "../input/input_autodetect.h"
#include "../config.def.h"
#include "../performance.h"
#include "../performance_counters.h"
#include "../lakka.h"
#include "../tasks/tasks_internal.h"

View File

@ -19,6 +19,7 @@
#include <net/net_http.h>
#include "../performance.h"
#include "../performance_counters.h"
#include "net_http_special.h"
int net_http_get(const char **result, size_t *size, const char *url, retro_time_t *timeout)

View File

@ -109,90 +109,6 @@ static int clock_gettime(int clk_ik, struct timespec *t)
#include "frontend/drivers/platform_linux.h"
#endif
static struct retro_perf_counter *perf_counters_rarch[MAX_COUNTERS];
static struct retro_perf_counter *perf_counters_libretro[MAX_COUNTERS];
static unsigned perf_ptr_rarch;
static unsigned perf_ptr_libretro;
struct retro_perf_counter **retro_get_perf_counter_rarch(void)
{
return perf_counters_rarch;
}
struct retro_perf_counter **retro_get_perf_counter_libretro(void)
{
return perf_counters_libretro;
}
unsigned retro_get_perf_count_rarch(void)
{
return perf_ptr_rarch;
}
unsigned retro_get_perf_count_libretro(void)
{
return perf_ptr_libretro;
}
void rarch_perf_register(struct retro_perf_counter *perf)
{
if (
!runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL)
|| perf->registered
|| perf_ptr_rarch >= MAX_COUNTERS
)
return;
perf_counters_rarch[perf_ptr_rarch++] = perf;
perf->registered = true;
}
void retro_perf_register(struct retro_perf_counter *perf)
{
if (perf->registered || perf_ptr_libretro >= MAX_COUNTERS)
return;
perf_counters_libretro[perf_ptr_libretro++] = perf;
perf->registered = true;
}
void retro_perf_clear(void)
{
perf_ptr_libretro = 0;
memset(perf_counters_libretro, 0, sizeof(perf_counters_libretro));
}
static void log_counters(struct retro_perf_counter **counters, unsigned num)
{
unsigned i;
for (i = 0; i < num; i++)
{
if (counters[i]->call_cnt)
{
RARCH_LOG(PERF_LOG_FMT,
counters[i]->ident,
(unsigned long long)counters[i]->total /
(unsigned long long)counters[i]->call_cnt,
(unsigned long long)counters[i]->call_cnt);
}
}
}
void rarch_perf_log(void)
{
if (!runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL))
return;
RARCH_LOG("[PERF]: Performance counters (RetroArch):\n");
log_counters(perf_counters_rarch, perf_ptr_rarch);
}
void retro_perf_log(void)
{
RARCH_LOG("[PERF]: Performance counters (libretro):\n");
log_counters(perf_counters_libretro, perf_ptr_libretro);
}
/**
* retro_get_perf_counter:
*
@ -652,30 +568,3 @@ uint64_t retro_get_cpu_features(void)
return cpu;
}
int rarch_perf_init(struct retro_perf_counter *perf, const char *name)
{
perf->ident = name;
if (!perf->registered)
rarch_perf_register(perf);
return 0;
}
void retro_perf_start(struct retro_perf_counter *perf)
{
if (!runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL) || !perf)
return;
perf->call_cnt++;
perf->start = retro_get_perf_counter();
}
void retro_perf_stop(struct retro_perf_counter *perf)
{
if (!runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL) || !perf)
return;
perf->total += retro_get_perf_counter() - perf->start;
}

View File

@ -25,27 +25,6 @@
extern "C" {
#endif
#ifndef MAX_COUNTERS
#define MAX_COUNTERS 64
#endif
struct retro_perf_counter **retro_get_perf_counter_rarch(void);
struct retro_perf_counter **retro_get_perf_counter_libretro(void);
unsigned retro_get_perf_count_rarch(void);
unsigned retro_get_perf_count_libretro(void);
/*
* retro_get_perf_counter:
*
* Gets performance counter.
*
* Returns: performance counter.
**/
retro_perf_tick_t retro_get_perf_counter(void);
/**
* retro_get_time_usec:
*
@ -54,35 +33,6 @@ retro_perf_tick_t retro_get_perf_counter(void);
**/
retro_time_t retro_get_time_usec(void);
void retro_perf_register(struct retro_perf_counter *perf);
/* Same as retro_perf_register, just for libretro cores. */
void retro_perf_register(struct retro_perf_counter *perf);
void retro_perf_clear(void);
void retro_perf_log(void);
void rarch_perf_log(void);
int rarch_perf_init(struct retro_perf_counter *perf, const char *name);
/**
* retro_perf_start:
* @perf : pointer to performance counter
*
* Start performance counter.
**/
void retro_perf_start(struct retro_perf_counter *perf);
/**
* retro_perf_stop:
* @perf : pointer to performance counter
*
* Stop performance counter.
**/
void retro_perf_stop(struct retro_perf_counter *perf);
/**
* retro_get_cpu_features:
*

145
performance_counters.c Normal file
View File

@ -0,0 +1,145 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2016 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include "performance_counters.h"
#include "general.h"
#include "compat/strl.h"
#include "verbosity.h"
#ifdef _WIN32
#define PERF_LOG_FMT "[PERF]: Avg (%s): %I64u ticks, %I64u runs.\n"
#else
#define PERF_LOG_FMT "[PERF]: Avg (%s): %llu ticks, %llu runs.\n"
#endif
#if !defined(_WIN32) && !defined(RARCH_CONSOLE)
#include <unistd.h>
#endif
static struct retro_perf_counter *perf_counters_rarch[MAX_COUNTERS];
static struct retro_perf_counter *perf_counters_libretro[MAX_COUNTERS];
static unsigned perf_ptr_rarch;
static unsigned perf_ptr_libretro;
struct retro_perf_counter **retro_get_perf_counter_rarch(void)
{
return perf_counters_rarch;
}
struct retro_perf_counter **retro_get_perf_counter_libretro(void)
{
return perf_counters_libretro;
}
unsigned retro_get_perf_count_rarch(void)
{
return perf_ptr_rarch;
}
unsigned retro_get_perf_count_libretro(void)
{
return perf_ptr_libretro;
}
void rarch_perf_register(struct retro_perf_counter *perf)
{
if (
!runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL)
|| perf->registered
|| perf_ptr_rarch >= MAX_COUNTERS
)
return;
perf_counters_rarch[perf_ptr_rarch++] = perf;
perf->registered = true;
}
void retro_perf_register(struct retro_perf_counter *perf)
{
if (perf->registered || perf_ptr_libretro >= MAX_COUNTERS)
return;
perf_counters_libretro[perf_ptr_libretro++] = perf;
perf->registered = true;
}
void retro_perf_clear(void)
{
perf_ptr_libretro = 0;
memset(perf_counters_libretro, 0, sizeof(perf_counters_libretro));
}
static void log_counters(struct retro_perf_counter **counters, unsigned num)
{
unsigned i;
for (i = 0; i < num; i++)
{
if (counters[i]->call_cnt)
{
RARCH_LOG(PERF_LOG_FMT,
counters[i]->ident,
(unsigned long long)counters[i]->total /
(unsigned long long)counters[i]->call_cnt,
(unsigned long long)counters[i]->call_cnt);
}
}
}
void rarch_perf_log(void)
{
if (!runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL))
return;
RARCH_LOG("[PERF]: Performance counters (RetroArch):\n");
log_counters(perf_counters_rarch, perf_ptr_rarch);
}
void retro_perf_log(void)
{
RARCH_LOG("[PERF]: Performance counters (libretro):\n");
log_counters(perf_counters_libretro, perf_ptr_libretro);
}
int rarch_perf_init(struct retro_perf_counter *perf, const char *name)
{
perf->ident = name;
if (!perf->registered)
rarch_perf_register(perf);
return 0;
}
void retro_perf_start(struct retro_perf_counter *perf)
{
if (!runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL) || !perf)
return;
perf->call_cnt++;
perf->start = retro_get_perf_counter();
}
void retro_perf_stop(struct retro_perf_counter *perf)
{
if (!runloop_ctl(RUNLOOP_CTL_IS_PERFCNT_ENABLE, NULL) || !perf)
return;
perf->total += retro_get_perf_counter() - perf->start;
}

83
performance_counters.h Normal file
View File

@ -0,0 +1,83 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2016 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _PERFORMANCE_COUNTERS_H
#define _PERFORMANCE_COUNTERS_H
#include <stdint.h>
#include "libretro.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MAX_COUNTERS
#define MAX_COUNTERS 64
#endif
struct retro_perf_counter **retro_get_perf_counter_rarch(void);
struct retro_perf_counter **retro_get_perf_counter_libretro(void);
unsigned retro_get_perf_count_rarch(void);
unsigned retro_get_perf_count_libretro(void);
/*
* retro_get_perf_counter:
*
* Gets performance counter.
*
* Returns: performance counter.
**/
retro_perf_tick_t retro_get_perf_counter(void);
void retro_perf_register(struct retro_perf_counter *perf);
/* Same as retro_perf_register, just for libretro cores. */
void retro_perf_register(struct retro_perf_counter *perf);
void retro_perf_clear(void);
void retro_perf_log(void);
void rarch_perf_log(void);
int rarch_perf_init(struct retro_perf_counter *perf, const char *name);
/**
* retro_perf_start:
* @perf : pointer to performance counter
*
* Start performance counter.
**/
void retro_perf_start(struct retro_perf_counter *perf);
/**
* retro_perf_stop:
* @perf : pointer to performance counter
*
* Stop performance counter.
**/
void retro_perf_stop(struct retro_perf_counter *perf);
#ifdef __cplusplus
}
#endif
#endif