Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Noordhuis bnoordhuis

View GitHub Profile
View strace.out
This file has been truncated, but you can view the full file.
[root@server ~]# strace -fp 5497
Process 5497 attached with 2 threads - interrupt to quit
[pid 5498] futex(0x7fa1b80008c8, FUTEX_WAIT_PRIVATE, 0, NULL <unfinished ...>
[pid 5497] epoll_wait(5, {{EPOLLIN, {u32=10, u64=10}}}, 1024, 4294967295) = 1
[pid 5497] accept4(10, 0, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK) = 11
[pid 5497] futex(0x7fa1b80008c8, FUTEX_WAKE_PRIVATE, 1) = 1
[pid 5498] <... futex resumed> ) = 0
[pid 5498] nanosleep({0, 900000}, NULL) = 0
[pid 5498] futex(0x7fa1b80008c8, FUTEX_WAIT_PRIVATE, 0, NULL <unfinished ...>
@bnoordhuis
bnoordhuis / stacktrace.cc
Last active Jul 23, 2018
Decode C/C++ and V8 JS stack frames.
View stacktrace.cc
#include "v8.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <cxxabi.h>
#include <dlfcn.h>
using namespace v8;
@bnoordhuis
bnoordhuis / http-and-https-proxy.js
Created Feb 8, 2013
A node.js proxy that accepts HTTP and HTTPS traffic on the same port.
View http-and-https-proxy.js
var fs = require('fs');
var net = require('net');
var http = require('http');
var https = require('https');
var httpAddress = '/path/to/http.sock';
var httpsAddress = '/path/to/https.sock';
fs.unlinkSync(httpAddress);
fs.unlinkSync(httpsAddress);
@bnoordhuis
bnoordhuis / trace-jit-code-events.patch
Created Jan 25, 2013
Print real-time V8 JIT code events.
View trace-jit-code-events.patch
diff --git a/src/node.cc b/src/node.cc
index 32cff12..3c5b616 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -2954,6 +2954,36 @@ static char **copy_argv(int argc, char **argv) {
return argv_copy;
}
+
+static void OnJitCodeEvent(const JitCodeEvent* event) {
@bnoordhuis
bnoordhuis / pthread_chdir.c
Created Dec 6, 2012
OS X undocumented __pthread_chdir() and __pthread_fchdir() syscalls
View pthread_chdir.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <fcntl.h>
#ifndef SYS___pthread_chdir
# define SYS___pthread_chdir 348
#endif
@bnoordhuis
bnoordhuis / context-1.cc
Created Nov 21, 2012
V8 context GC cleanup failure
View context-1.cc
#include "v8.h"
#include <assert.h>
#include <unistd.h>
using namespace v8;
struct WrappedContext
{
WrappedContext(Handle<Object> obj)
{
@bnoordhuis
bnoordhuis / gc.stp
Created Nov 15, 2012
systemtap script that prints aggregated node.js garbage collector statistics
View gc.stp
#!/usr/bin/env stap
global samples
global all_samples
global timestamp
probe process("node").mark("gc__start")
{
timestamp = gettimeofday_us()
}
@bnoordhuis
bnoordhuis / 1.js
Created Nov 4, 2012
v8 big array performance bugs
View 1.js
for (var a = [], i = 0; i < 64*1024*1024; ++i) a.push(123.456);
@bnoordhuis
bnoordhuis / results.txt
Created Oct 30, 2012
show difference between mmap() and malloc()
View results.txt
$ gcc -DUSE_MMAP=0 tmp/rss.c && ./a.out
rss 360448
==============
rss 360448
rss 1429504
rss 552960
==============
rss 552960
rss 1359872
rss 1359872
@bnoordhuis
bnoordhuis / cpuid.c
Created Sep 13, 2012
print cpuid info
View cpuid.c
/*
* Copyright (c) 2012, Ben Noordhuis <info@bnoordhuis.nl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR