ext/nyara.c in nyara-0.0.1.pre.9 vs ext/nyara.c in nyara-0.1.pre.0
- old
+ new
@@ -3,10 +3,11 @@
#include "nyara.h"
#include <ruby/io.h>
#include <sys/socket.h>
#include <sys/resource.h>
#include <sys/fcntl.h>
+#include "inc/rdtsc.h"
rb_encoding* u8_encoding;
static VALUE nyara;
void nyara_set_nonblock(int fd) {
@@ -29,21 +30,20 @@
rlim.rlim_max = nofiles;
setrlimit (RLIMIT_NOFILE, &rlim);
}
}
-static bool summary_request = false;
-void nyara_summary_request(int method, VALUE path, VALUE controller) {
- if (summary_request) {
- rb_funcall(nyara, rb_intern("summary_request"), 3, INT2NUM(method), path, controller);
- }
+static unsigned long long last_rdtsc = 0;
+
+static VALUE ext_rdtsc_start(VALUE _) {
+ last_rdtsc = rdtsc();
+ return Qnil;
}
-// set whether should log summary of request
-static VALUE ext_summary_request(VALUE _, VALUE toggle) {
- summary_request = RTEST(toggle);
- return toggle;
+static VALUE ext_rdtsc(VALUE _) {
+ unsigned long long diff = rdtsc() - last_rdtsc;
+ return ULL2NUM(diff);
}
void Init_nyara() {
u8_encoding = rb_utf8_encoding();
set_fd_limit(20000);
@@ -78,10 +78,12 @@
HTTP_STATUS_CODES(STATUS_DESC);
# undef STATUS_DESC
OBJ_FREEZE(status_map);
VALUE ext = rb_define_module_under(nyara, "Ext");
- rb_define_singleton_method(ext, "summary_request", ext_summary_request, 1);
+ rb_define_singleton_method(ext, "rdtsc_start", ext_rdtsc_start, 0);
+ rb_define_singleton_method(ext, "rdtsc", ext_rdtsc, 0);
+
Init_accept(ext);
Init_mime(ext);
Init_request(nyara, ext);
Init_request_parse(nyara, ext);
Init_test_response(nyara);