mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-20 13:59:57 +00:00
Aded profiler efkdlgm
This commit is contained in:
parent
70caa1a9e0
commit
c532aecc21
7 changed files with 106 additions and 17 deletions
|
|
@ -30,7 +30,7 @@ else()
|
|||
if (MSVC)
|
||||
add_compile_options(/O2 /fp:fast /GL /GF /GA)
|
||||
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)
|
||||
add_compile_options(-flto)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -33,14 +33,67 @@
|
|||
#include "meow.h"
|
||||
|
||||
#include <ruby.h>
|
||||
#include <ruby/debug.h>
|
||||
#include <ruby/encoding.h>
|
||||
#undef inline
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <zlib.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <time.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[];
|
||||
|
||||
static void mriBindingExecute();
|
||||
|
|
@ -355,12 +408,8 @@ static void runRMXPScripts(BacktraceData &btData){
|
|||
crash(Exception::MEOW, "Failed to read script data");
|
||||
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);
|
||||
std::string decodeBuffer;
|
||||
decodeBuffer.resize(0x1000);
|
||||
|
|
@ -507,8 +556,17 @@ static void mriBindingExecute(){
|
|||
ruby_init();
|
||||
ruby_init_loadpath();
|
||||
rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));
|
||||
|
||||
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()){
|
||||
/* Setup custom load paths */
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include <SDL3/SDL_version.h>
|
||||
#include <limits.h>
|
||||
#include "security.h"
|
||||
|
||||
#include "config.h"
|
||||
//Просто на 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_micro"), INT2NUM(SDL_MICRO_VERSION));
|
||||
rb_const_set(module, rb_intern("SECURITYSTATE"), rb_str_new_cstr(securitystate));
|
||||
|
||||
//если методы доступны то просто не перезаписываем их
|
||||
if (!rb_respond_to(rb_cObject, rb_intern("class"))) {
|
||||
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"))) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
9
niga.rb
Normal file
9
niga.rb
Normal file
|
|
@ -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?
|
||||
$game_followers.push(Game_Follower.new($game_player, actor))
|
||||
else
|
||||
$game_followers.push(Game_Follower.new($game_followers.last, actor))
|
||||
$game_followers.push(Game_Follower.new($game_followers[-1], actor))
|
||||
end
|
||||
$scene.add_follower($game_followers.last)
|
||||
$scene.add_follower($game_followers[-1])
|
||||
end
|
||||
# Add actor
|
||||
@actors.push(actor)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,26 @@ at_exit do
|
|||
end
|
||||
|
||||
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)
|
||||
$console = Graphics.fullscreen
|
||||
Graphics.frame_rate = 60
|
||||
|
|
@ -51,9 +71,16 @@ begin
|
|||
if Journal.active?
|
||||
Journal.set ''
|
||||
end
|
||||
|
||||
if $debug
|
||||
tp.disable
|
||||
end
|
||||
|
||||
Oneshot.allow_exit true
|
||||
rescue Errno::ENOENT
|
||||
if $debug
|
||||
tp.disable
|
||||
end
|
||||
# Supplement Errno::ENOENT exception
|
||||
# If unable to open file, display message and end
|
||||
filename = $!.message.sub("No such file or directory - ", "")
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
#include <SDL3/SDL_stdinc.h>
|
||||
#include <time.h>
|
||||
#include <fstream>
|
||||
#include <ruby.h>
|
||||
#include <ruby/version.h>
|
||||
#include <zlib.h>
|
||||
#include <AL/al.h>
|
||||
|
|
|
|||
Loading…
Reference in a new issue