SOme fixes for new profielr

This commit is contained in:
DepressedTWM 2026-08-06 15:02:22 +04:00
parent bfc418e9e6
commit 6cc79f616f
2 changed files with 23 additions and 22 deletions

View file

@ -1320,10 +1320,10 @@ module RPG
class Mod class Mod
def self.exec_hooks(path, b) def self.exec_hooks(path, b)
if ModLoader::IS_ENABLED return unless ModLoader::IS_ENABLED
ModLoader.hooks(path).each do |item| return unless path.is_a?(String)
eval(File.read(item), b) ModLoader.hooks(path).each do |item|
end eval(File.read(item), b)
end end
end end
end end

View file

@ -1,20 +1,17 @@
// someone plz help me fix it 3: //SOMEONE PLZ HELP ME FIX TIHIS SHITTTTTTTTTTT
#include "binding.h" #include "binding.h"
#include "binding-util.h" #include "binding-util.h"
#include "debugwriter.h" #include "debugwriter.h"
#include <ruby.h> #include <ruby.h>
#include <ruby/debug.h> #include <ruby/debug.h>
#include <inttypes.h> #include <inttypes.h>
#include <time.h> #include <time.h>
#include <iostream>
#include <string> #include <string>
#include <vector> #include <vector>
static VALUE tp = Qnil; VALUE tp = Qnil;
static uint64_t now_ns(void) { static uint64_t now_ns(void) {
timespec ts; timespec ts;
@ -27,7 +24,7 @@ static std::string value_to_string(VALUE v, const char *fallback) {
return std::string(StringValuePtr(v)); return std::string(StringValuePtr(v));
} }
static void tp_cb(VALUE tpval, void * /*data*/) { static void tp_cb(VALUE tpval, void *) {
rb_trace_arg_t *trace_arg = rb_tracearg_from_tracepoint(tpval); rb_trace_arg_t *trace_arg = rb_tracearg_from_tracepoint(tpval);
if (!trace_arg) return; if (!trace_arg) return;
@ -42,7 +39,7 @@ static void tp_cb(VALUE tpval, void * /*data*/) {
return; return;
} }
if (ev == RUBY_EVENT_RETURN || ev == RUBY_EVENT_RAISE) { if (ev == RUBY_EVENT_RETURN) {
if (stack.starts.empty()) return; if (stack.starts.empty()) return;
uint64_t end_ns = now_ns(); uint64_t end_ns = now_ns();
@ -67,19 +64,21 @@ static void tp_cb(VALUE tpval, void * /*data*/) {
long line = NIL_P(lineno) ? 0 : FIX2LONG(lineno); long line = NIL_P(lineno) ? 0 : FIX2LONG(lineno);
std::cout << "[PROFILER] " Debug() << "[PROFILER] "
<< meth_s << ' ' << meth_s << ' '
<< path_s << ':' << line << path_s << ':' << line
<< " class=" << class_s << " class=" << class_s
<< " dur_ns=" << dur_ns << " dur_ns=" << dur_ns << "\n";
<< (ev == RUBY_EVENT_RAISE ? " event=RAISE" : " event=RETURN")
<< '\n';
return; return;
} }
} }
static VALUE profiler(VALUE /*self*/, VALUE v) { static VALUE profiler(VALUE, VALUE v) {
if (tp == Qnil) return Qnil; if (tp == Qnil || NIL_P(tp)) {
rb_raise(rb_eRuntimeError, "Profiler not initialized");
return Qnil;
}
if (v == Qtrue) { if (v == Qtrue) {
rb_tracepoint_enable(tp); rb_tracepoint_enable(tp);
} else { } else {
@ -93,9 +92,11 @@ void ProfilerInit() {
VALUE module = rb_define_module("Profiler"); VALUE module = rb_define_module("Profiler");
tp = rb_tracepoint_new( tp = rb_tracepoint_new(
Qnil, Qnil,
RUBY_EVENT_CALL | RUBY_EVENT_RETURN | RUBY_EVENT_RAISE, RUBY_EVENT_CALL | RUBY_EVENT_RETURN,
tp_cb, tp_cb,
nullptr nullptr
); );
rb_gc_register_address(&tp);
rb_define_singleton_method(module, "set", RUBY_METHOD_FUNC(profiler), 1); rb_define_singleton_method(module, "set", RUBY_METHOD_FUNC(profiler), 1);
} }