Skip to content

Instantly share code, notes, and snippets.

View markpapadakis's full-sized avatar
💭
Seeking Knowledge 24x7

Mark Papadakis markpapadakis

💭
Seeking Knowledge 24x7
View GitHub Profile
static int8_t TryAppend(const ColumnFamily *__restrict const self, const ColumnFamily *__restrict const cf, colNameCmpProc_t cmpProc)
{
const uint32_t cfColumnsCnt = cf->columns.Size();
if (unlikely(cfColumnsCnt == 0))
return 0;
const uint32_t selfColumnsCnt = self->columns.Size();
if (unlikely(selfColumnsCnt == 0))
struct IColumn
: public RefCounted<IColumn>, public IExpirable
{
column_name name;
};
struct IColumnsContainer
: public IColumn
{
Vector<IColumn *, ReleaseRefDestructor> columns;
struct NPC
{
uint8_t activeScale; // higher => will execute more logic / TICK
void AdjustActivityScale(const float normalizedDistanceFromPC) // Clamped to 0...1
{
activeScale = normalizedDistanceFromPC * 10.0;
}
// A simple std::function alternative.
// You can use e.g variadic templates to support arbitrary signatures, but this here demonstrates how
// type erasure makes it possible to wrap any callable function
//
// type erasure is a nifty C++ pattern. There are alternatives to it, but this is usually a better fit.
//
// move/copy constructors and assignemnt operators not implemented, but trivial to do so anyway
// May be worth using e.g std::unique_ptr or whatever for ref-counted wrapped object for sharing, but should
// also be trivial to implement. Apparenly you need a few different alternative implementations to satisfy different
// requirements; can't practically have one impl. for everything.
template<typename T>
void SimpleMovingAverage(const T *const timeSeries, const uint32_t timeSeriesCnt, const uint32_t windowSize, Vector<T> &res)
{
T window[128], sum = 0;
uint8_t windowIndex, windowBase = 0;
uint32_t i = 0;
const auto n = Min<uint32_t>(timeSeriesCnt, windowSize - 1);
runtime_assert(windowSize <= ARRAY_SIZE(window), "Too large window");
static_assert((ARRAY_SIZE(window)&(ARRAY_SIZE(window) - 1)) == 0, "window size not base 2");
int SwitchFS::EnumResidentVMAs(const uint8_t *const base, const uint64_t size, const uint8_t *offset, uint64_t len, std::function<void(const uint8_t *, const uint64_t)> cb)
{
#ifdef SWITCH_OS_LINUX
static const uint32_t pageSize = getpagesize();
#else
static const uint32_t pageSize = sysconf(_SC_PAGESIZE);
#endif
const uint8_t *const end = offset + len;
const uint8_t *const upto = base + Min<uint64_t>(size, ALIGNUP_TO_POWEROF2BOUNDARY((uint64_t)(uintptr_t)(end - base), pageSize));
int SSTable::VMResidentRows(Vector<token_t> *const out) const
{
uint8_t *const fileData = (uint8_t *)mmapReader->Data();
Vector<token_offset> tokens;
tokens.EnsureCapacity(metadata.rowsCnt);
if (offsetSize == 8)
{
for (const uint8_t *indexIt = fileData + indexChunkOffset, *const indexEnd = indexIt + indexChunkSize; indexIt != indexEnd; )
{
if (const auto cnt = rowsToWarmup.Size())
{
int fd = open(finalPath, O_RDONLY|O_LARGEFILE);
const row *const all = rowsToWarmup.Values();
const auto shift = __builtin_ffs(getpagesize()) - 1;
volatile uint32_t ac = 0;
const auto before = Timings::Microseconds::Tick();
if (unlikely(fd == -1))
{
@markpapadakis
markpapadakis / enum_dyn_syms.cpp
Last active August 29, 2015 14:06
Scans an ELF DLL/DSO looking for globally exported syms/objects. Useful for App Servers, game engines, etc
#include <elf.h>
// Scans an ELF DLL/DSO looking for globally epxorted symbols/objects of type object or function
// Very useful for e.g application servers or games where you don't really want to pre-define those functions/objects in e.g a list
// and instead you can define them in any file that makes up the module. That way you will scan them and identfiy what you need and load it later
//
// e.g
// EnumDynSyms("AppServerModules/search.dso", [](const char *const name, const uint8_t type)
// {

As I outlined in this overseer post, we aggregate all crashes so that we know about any serious issue the moment it happens, and we have some consumers that deal with them individually, one of them notifying us on Slack, others logging them, etc.

Because everyone can build and run a consumer, here's one that I 'll personally use: For each abort event (system.apps.abort), a key comprised of the source code file and line where it happened (filename:line) is created.

A lookup on a CloudDS 'table' checks if we have encountered that before; if not, then it's set there and a nice Wunderlist task, complete with stacktrace frames, node name, and more, is created and placed in a special list, via RPC.