Skip to content

Instantly share code, notes, and snippets.

@303248153
303248153 / CaptureEtwEventFromCoreClr.cpp
Last active December 25, 2017 03:51
The code is a piece of shit invokes the worst api microsoft ever made but should just work, requires mingw and win above vista
// https://github.com/packetzero/etwrealtime/blob/master/etwrealtime/packet_trace.cpp
// https://mollyrocket.com/casey/stream_0029.html
// https://docs.microsoft.com/en-us/dotnet/framework/performance/clr-etw-providers
#define WINNT
#include <windows.h>
#include <evntrace.h>
#include <evntprov.h>
#include <iostream>
#include <array>
/* g++ -Wall -Wextra --std=c++14 -g abc.cpp -lbfd && valgrind ./a.out */
#include <bfd.h>
#include <elf.h>
#include <cassert>
#include <cstring>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <array>
# allocator
### [ spans, bitmap, arena ]
schedinit
mallocinit
calculate arena, spans, bitmap size
arena = 512GB
spans = 512MB (arena / page * ptr, 512G / 8K * 8, map page => *span)
bitmap = 16GB (arena / (ptr * 8 / 2), 512G / 32, map 1 byte => 4 pointer | 2 bit => pointer)
G - goroutine
M - worker thread, or machine (native thread)
P - processor, a resource that is required to execute Go code
M must have an associated P to execute Go code,
however it can be blocked or in a syscall without an associated P
Worker thread parking/unparking
A worker thread is considered spinning if
if it is out of local work and did not find work in global run queue/netpoller
https://hub.docker.com/r/scylladb/scylla
docker pull scylladb/scylla
mkdir -p /var/lib/scylla-node-1/data /var/lib/scylla-node-1/commitlog
docker run --name scylla-node-1 --volume /var/lib/scylla-node-1:/var/lib/scylla -d scylladb/scylla
docker exec -it scylla-node-1 bash
docker logs scylla-node-1 | tail
mkdir -p /var/lib/scylla-node-2/data /var/lib/scylla-node-2/commitlog
docker run --name scylla-node-2 --volume /var/lib/scylla-node-2:/var/lib/scylla -d scylladb/scylla --seeds="$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' scylla-node-1)"
sudo apt-get install vim python3-pip
sudo update-alternatives --config vi # choose vim.basic auto mode
# https://github.com/tpope/vim-pathogen
mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
# https://github.com/morhetz/gruvbox/wiki/Installation
git clone https://github.com/morhetz/gruvbox.git ~/.vim/bundle/gruvbox
@303248153
303248153 / jit_dump_example.debug.txt
Last active October 19, 2017 02:32
jit_dump_example
****** START compiling ConsoleApplication.Program:Main(ref) (MethodHash=1499abcb)
Generating code for Unix x64
OPTIONS: compCodeOpt = BLENDED_CODE
OPTIONS: compDbgCode = true
OPTIONS: compDbgInfo = true
OPTIONS: compDbgEnC = false
OPTIONS: compProcedureSplitting = false
OPTIONS: compProcedureSplittingEH = false
OPTIONS: Stack probing is DISABLED
IL to import:
链接
https://github.com/dotnet/coreclr/blob/master/Documentation/botr/ryujit-tutorial.md
https://github.com/dotnet/coreclr/blob/release/1.1.0/Documentation/botr/ryujit-overview.md
https://github.com/dotnet/coreclr/blob/release/1.1.0/Documentation/botr/porting-ryujit.md
https://github.com/dotnet/coreclr/blob/release/1.1.0/Documentation/building/viewing-jit-dumps.md
https://github.com/dotnet/coreclr/blob/release/1.1.0/Documentation/project-docs/clr-configuration-knobs.md
https://github.com/dotnet/coreclr/blob/release/1.1.0/Documentation/building/debugging-instructions.md
https://github.com/dotnet/coreclr/blob/release/1.1.0/Documentation/botr/clr-abi.md
https://github.com/dotnet/coreclr/blob/release/1.1.0/Documentation/design-docs/finally-optimizations.md
https://github.com/dotnet/coreclr/blob/release/1.1.0/Documentation/design-docs/jit-call-morphing.md
public static uint SizeOf(object obj)
{
unsafe
{
var objRef = __makeref(obj);
var objPtr = **(IntPtr**)(&objRef);
var mtPtr = *((IntPtr*)objPtr);
var componentSize = *((ushort*)(mtPtr + 0));
var flags = *((ushort*)(mtPtr + 2));