Aded profiler efkdlgm
This commit is contained in:
parent
70caa1a9e0
commit
c532aecc21
|
|
@ -30,7 +30,7 @@ else()
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
add_compile_options(/O2 /fp:fast /GL /GF /GA)
|
add_compile_options(/O2 /fp:fast /GL /GF /GA)
|
||||||
else()
|
else()
|
||||||
add_compile_options(-Ofast -funroll-loops -fipa-pta -ftree-vectorize -fstdarg-opt -fomit-frame-pointer -frename-registers)
|
add_compile_options(-O2 -ffast-math -fipa-pta -ftree-vectorize -fstdarg-opt -fomit-frame-pointer -frename-registers)
|
||||||
if(!WIN32)
|
if(!WIN32)
|
||||||
add_compile_options(-flto)
|
add_compile_options(-flto)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,67 @@
|
||||||
#include "meow.h"
|
#include "meow.h"
|
||||||
|
|
||||||
#include <ruby.h>
|
#include <ruby.h>
|
||||||
|
#include <ruby/debug.h>
|
||||||
#include <ruby/encoding.h>
|
#include <ruby/encoding.h>
|
||||||
#undef inline
|
#undef inline
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <time.h>
|
||||||
#include <SDL3/SDL_filesystem.h>
|
#include <SDL3/SDL_filesystem.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint64_t start_ns;
|
||||||
|
} ud_t;
|
||||||
|
|
||||||
|
//TODO rewrtire profiler bcz ChatGPT bcz WHERE IS DOCS ABOUT RUBY C API TRACEPOINT
|
||||||
|
static uint64_t now_ns(void) {
|
||||||
|
struct timespec ts;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *val_to_cstr(VALUE v, const char *fallback) {
|
||||||
|
if (NIL_P(v)) return fallback;
|
||||||
|
VALUE s = rb_funcall(v, rb_intern("to_s"), 0);
|
||||||
|
if (!RB_TYPE_P(s, T_STRING)) return fallback;
|
||||||
|
return RSTRING_PTR(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tp_cb(VALUE tpval, void *data) {
|
||||||
|
ud_t *ud = (ud_t *)data;
|
||||||
|
|
||||||
|
rb_trace_arg_t *trace_arg = rb_tracearg_from_tracepoint(tpval);
|
||||||
|
if (!trace_arg) return;
|
||||||
|
|
||||||
|
VALUE path = rb_tracearg_path(trace_arg);
|
||||||
|
VALUE lineno = rb_tracearg_lineno(trace_arg);
|
||||||
|
VALUE defined_class = rb_tracearg_defined_class(trace_arg);
|
||||||
|
VALUE method_id = rb_tracearg_method_id(trace_arg);
|
||||||
|
rb_event_flag_t ev = rb_tracearg_event_flag(trace_arg);
|
||||||
|
|
||||||
|
const char *path_s = val_to_cstr(path, "<nil>");
|
||||||
|
const char *class_s = val_to_cstr(defined_class, "<nil>");
|
||||||
|
|
||||||
|
const char *meth_s = "<nil>";
|
||||||
|
if (!NIL_P(method_id)) {
|
||||||
|
const char *mn = rb_id2name(SYM2ID(method_id));
|
||||||
|
if (mn) meth_s = mn;
|
||||||
|
}
|
||||||
|
|
||||||
|
long line = NIL_P(lineno) ? 0 : FIX2LONG(lineno);
|
||||||
|
|
||||||
|
if (ev == RUBY_EVENT_CALL) {
|
||||||
|
ud->start_ns = now_ns();
|
||||||
|
} else if (ev == RUBY_EVENT_RETURN) {
|
||||||
|
uint64_t end_ns = now_ns();
|
||||||
|
uint64_t dur_ns = end_ns - ud->start_ns;
|
||||||
|
printf("[PROFILER] %s %s:%ld class=%s dur_ns=%" PRIu64 "\n", meth_s, path_s, line, class_s, dur_ns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extern const char binding_mri_module_rpg1_rb[];
|
extern const char binding_mri_module_rpg1_rb[];
|
||||||
|
|
||||||
static void mriBindingExecute();
|
static void mriBindingExecute();
|
||||||
|
|
@ -356,11 +409,7 @@ static void runRMXPScripts(BacktraceData &btData){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the debug flag */
|
|
||||||
rb_gv_set("$debug", conf.debugMode ? Qtrue : Qfalse);
|
|
||||||
|
|
||||||
rb_gv_set("$RGSS_SCRIPTS", scriptArray);
|
rb_gv_set("$RGSS_SCRIPTS", scriptArray);
|
||||||
|
|
||||||
long scriptCount = RARRAY_LEN(scriptArray);
|
long scriptCount = RARRAY_LEN(scriptArray);
|
||||||
std::string decodeBuffer;
|
std::string decodeBuffer;
|
||||||
decodeBuffer.resize(0x1000);
|
decodeBuffer.resize(0x1000);
|
||||||
|
|
@ -507,8 +556,17 @@ static void mriBindingExecute(){
|
||||||
ruby_init();
|
ruby_init();
|
||||||
ruby_init_loadpath();
|
ruby_init_loadpath();
|
||||||
rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));
|
rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));
|
||||||
|
|
||||||
Config &conf = shState->rtData().config;
|
Config &conf = shState->rtData().config;
|
||||||
|
if(conf.debugMode){
|
||||||
|
setvbuf(stdout, NULL, _IOFBF, 1<<20);
|
||||||
|
ud_t ud;
|
||||||
|
rb_event_flag_t flags = 0;
|
||||||
|
flags |= RUBY_EVENT_CALL;
|
||||||
|
flags |= RUBY_EVENT_RETURN;
|
||||||
|
flags |= RUBY_EVENT_RAISE;
|
||||||
|
VALUE tp = rb_tracepoint_new(Qnil, flags, tp_cb, &ud);
|
||||||
|
rb_tracepoint_enable(tp);
|
||||||
|
}
|
||||||
|
|
||||||
if (!conf.rubyLoadpaths.empty()){
|
if (!conf.rubyLoadpaths.empty()){
|
||||||
/* Setup custom load paths */
|
/* Setup custom load paths */
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#include <SDL3/SDL_version.h>
|
#include <SDL3/SDL_version.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "security.h"
|
#include "security.h"
|
||||||
|
#include "config.h"
|
||||||
//Просто на C реализуем методы мне в падлу ебаться со статической линковкой и прочим дерьмом.
|
//Просто на C реализуем методы мне в падлу ебаться со статической линковкой и прочим дерьмом.
|
||||||
//Аминь.
|
//Аминь.
|
||||||
|
|
||||||
|
|
@ -40,7 +40,6 @@ void SunshineBindingInit(){
|
||||||
rb_const_set(module, rb_intern("SDLVersion_minor"), INT2NUM(SDL_MINOR_VERSION));
|
rb_const_set(module, rb_intern("SDLVersion_minor"), INT2NUM(SDL_MINOR_VERSION));
|
||||||
rb_const_set(module, rb_intern("SDLVersion_micro"), INT2NUM(SDL_MICRO_VERSION));
|
rb_const_set(module, rb_intern("SDLVersion_micro"), INT2NUM(SDL_MICRO_VERSION));
|
||||||
rb_const_set(module, rb_intern("SECURITYSTATE"), rb_str_new_cstr(securitystate));
|
rb_const_set(module, rb_intern("SECURITYSTATE"), rb_str_new_cstr(securitystate));
|
||||||
|
|
||||||
//если методы доступны то просто не перезаписываем их
|
//если методы доступны то просто не перезаписываем их
|
||||||
if (!rb_respond_to(rb_cObject, rb_intern("class"))) {
|
if (!rb_respond_to(rb_cObject, rb_intern("class"))) {
|
||||||
rb_define_method(rb_cObject, "class", rb_obj_class, 0);
|
rb_define_method(rb_cObject, "class", rb_obj_class, 0);
|
||||||
|
|
@ -53,7 +52,4 @@ void SunshineBindingInit(){
|
||||||
if (!rb_respond_to(rb_cInteger, rb_intern("times"))) {
|
if (!rb_respond_to(rb_cInteger, rb_intern("times"))) {
|
||||||
rb_define_method(rb_cInteger, "times", RUBY_METHOD_FUNC(int_times), 0);
|
rb_define_method(rb_cInteger, "times", RUBY_METHOD_FUNC(int_times), 0);
|
||||||
}
|
}
|
||||||
if (!rb_respond_to(rb_cArray, rb_intern("last"))) {
|
|
||||||
rb_define_method(rb_cArray, "last", RUBY_METHOD_FUNC(a_last), 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
tp = TracePoint.new(:call) do |t|
|
||||||
|
# Для Ruby-методов:
|
||||||
|
next unless t.defined_class.is_a?(Module) # обычно всегда
|
||||||
|
puts "CALL #{t.defined_class}##{t.method_id} (line #{t.lineno})"
|
||||||
|
end
|
||||||
|
|
||||||
|
tp.enable
|
||||||
|
p "idi naxui"
|
||||||
|
tp.disable
|
||||||
|
|
@ -114,9 +114,9 @@ class Game_Party
|
||||||
if $game_followers.empty?
|
if $game_followers.empty?
|
||||||
$game_followers.push(Game_Follower.new($game_player, actor))
|
$game_followers.push(Game_Follower.new($game_player, actor))
|
||||||
else
|
else
|
||||||
$game_followers.push(Game_Follower.new($game_followers.last, actor))
|
$game_followers.push(Game_Follower.new($game_followers[-1], actor))
|
||||||
end
|
end
|
||||||
$scene.add_follower($game_followers.last)
|
$scene.add_follower($game_followers[-1])
|
||||||
end
|
end
|
||||||
# Add actor
|
# Add actor
|
||||||
@actors.push(actor)
|
@actors.push(actor)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,26 @@ at_exit do
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
p RUBY_VERSION
|
||||||
|
if $debug
|
||||||
|
trace = TracePoint.new(:raise) do |tp|
|
||||||
|
p [tp.lineno, tp.event, tp.raised_exception]
|
||||||
|
end
|
||||||
|
trace.enable
|
||||||
|
|
||||||
|
0 / 0
|
||||||
|
#tp = TracePoint.new(:call, :return) do |t|
|
||||||
|
# case t.event
|
||||||
|
# when :call
|
||||||
|
# puts "WRAP START (#{start_code}) -> #{t.defined_class}##{t.method_id}"
|
||||||
|
# when :return
|
||||||
|
# puts "WRAP END -> #{t.defined_class}##{t.method_id}"
|
||||||
|
# end
|
||||||
|
#end
|
||||||
|
#tp.enable
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
RPG::Mod.exec_hooks("hooks/Main/start", binding)
|
RPG::Mod.exec_hooks("hooks/Main/start", binding)
|
||||||
$console = Graphics.fullscreen
|
$console = Graphics.fullscreen
|
||||||
Graphics.frame_rate = 60
|
Graphics.frame_rate = 60
|
||||||
|
|
@ -52,8 +72,15 @@ begin
|
||||||
Journal.set ''
|
Journal.set ''
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if $debug
|
||||||
|
tp.disable
|
||||||
|
end
|
||||||
|
|
||||||
Oneshot.allow_exit true
|
Oneshot.allow_exit true
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
|
if $debug
|
||||||
|
tp.disable
|
||||||
|
end
|
||||||
# Supplement Errno::ENOENT exception
|
# Supplement Errno::ENOENT exception
|
||||||
# If unable to open file, display message and end
|
# If unable to open file, display message and end
|
||||||
filename = $!.message.sub("No such file or directory - ", "")
|
filename = $!.message.sub("No such file or directory - ", "")
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
#include <SDL3/SDL_stdinc.h>
|
#include <SDL3/SDL_stdinc.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <ruby.h>
|
|
||||||
#include <ruby/version.h>
|
#include <ruby/version.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <AL/al.h>
|
#include <AL/al.h>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue