Skip to content

Instantly share code, notes, and snippets.

--- a/include/seastar/core/internal/pollable_fd.hh
+++ b/include/seastar/core/internal/pollable_fd.hh
@@ -57,6 +57,7 @@ class pollable_fd_state {
int events_requested = 0; // wanted by pollin/pollout promises
int events_epoll = 0; // installed in epoll
int events_known = 0; // returned from epoll
+ bool is_acceptor = false; // put acceptor to disinct epoll
promise<> pollin;
promise<> pollout;
friend class reactor;
--- a/src/core/reactor.cc
+++ b/src/core/reactor.cc
@@ -124,6 +124,12 @@
#include <typeinfo>
#endif
+namespace {
+ thread_local static int schedule_count = 0;
+ thread_local static int schedule_urgent_count = 0;
+ thread_local static int epoll_count = 0;
@303248153
303248153 / CpuProfiler.cs
Created August 23, 2018 10:26
Cpu Profiler for .Net Framework on Windows
// A cpu profiler used to find out hot functions
// modified from https://github.com/jitbit/cpu-analyzer
// require nuget package:
// https://www.nuget.org/packages/Microsoft.Samples.Debugging.CorApi
// https://www.nuget.org/packages/Microsoft.Samples.Debugging.MdbgEngine
//
// Copyright 2012 - Sam Saffron
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
import numpy as np
# todo:
# - train bias
# - increase alpha when learning progress is slow
# - fix bugs
# - produce nan when weights_expected are all 0
np.random.seed(1)
np.set_printoptions(suppress=True)
@303248153
303248153 / GetFunctionInfoFromGit.cs
Created April 27, 2018 02:31
Find function author and last changed date from git blame
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace ConsoleApp1
{
public class Program
@303248153
303248153 / 32-int80.S
Last active April 21, 2018 00:48
system call example, use gcc -m32 32-{name}.S or gcc 64-{name}.S
.intel_syntax noprefix
.data
hello_string:
.ascii "Hello World!\n"
len:
.long len-hello_string
.text
.global main
@303248153
303248153 / ptrace_child.cpp
Created March 23, 2018 07:58
ptrace capture syscall
// g++ ptrace_child.cpp -o ptrace_child && ./ptrace_child
#include <unistd.h>
#include <iostream>
#include <chrono>
#include <thread>
void testAAA() {
std::cout << "testaaa" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
#include <memory>
#include <atomic>
namespace {
class AImpl {
public:
void test() { ++value; }
std::atomic_int value;
};
Install windbg from:
http://msdn.microsoft.com/windows/hardware/hh852362
Execute windbg, select File => Open Executable,
choose C:\Program Files\dotnet\dotnet.exe and use "c:\path\to\application.dll" as arguments (don't forget the double quotes if path contains space).
Use commands:
sxe ld clr
g
.loadby sos coreclr
@303248153
303248153 / CaptureLttngEventFromCoreClr.cpp
Last active December 27, 2017 03:55
Even shitter than etw, worse than the worst api
// sudo apt-get install liblttng-ctl-dev
// g++ -Wall -Wextra --std=c++11 CaptureLttngEventFromCoreClr.cpp -llttng-ctl && ./a.out
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// ! !
// ! Don't copy this code to your project, !
// ! it contains GPL licensed code from lttng-tools (lttng-viewer-abi.h).!
// ! !
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include <lttng/lttng.h>
#include <sys/socket.h>