Skip to content

Instantly share code, notes, and snippets.

View goldshtn's full-sized avatar

Sasha Goldshtein goldshtn

View GitHub Profile
goldshtn /
Created March 4, 2017 15:22
.NET Core on Linux LLDB analysis scripts
#!/usr/bin/env python
# Example of an LLDB script that loads SOS and runs a command
# for analysis of a .NET Core application on Linux/macOS.
# Requires LLDB matching the version of for your
# CoreCLR version, and gdb.
# USAGE: [--memory] [--stacks] COREFILE
# NOTE: To run this as stand-alone, you might need to fix some bad symlinks
goldshtn /
Last active November 11, 2019 15:26
dotnet-mapgen: generates map files for crossgen-compiled assemblies, and merges them into the main perf map file
#!/usr/bin/env python
# USAGE: dotnet-mapgen [-h] {generate,merge} PID
# In generate mode, this tool reads the /tmp/ file generated
# by the CLR when running with COMPlus_PerfMapEnabled=1, and finds all load
# events for managed assemblies. For each managed assembly found in this way,
# the tool runs crossgen to generate a symbol mapping file (akin to debuginfo).
# In merge mode, this tool finds the load address of each managed assembly in
goldshtn / stackalloc-benchmark.cs
Created October 17, 2013 09:03
Benchmark for comparing stackalloc to heap allocations for small, medium, and large arrays.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StackAllocVsHeapAlloc
public static class Sandbox
goldshtn /
Last active September 13, 2018 16:53
Place a dynamic probe on a .NET Core method
#!/usr/bin/env python
# USAGE: place-probe [-h] [--dry-run] [--debug] PID METHOD
# This tool helps place dynamic probes on .NET methods that were
# CrossGen-generated (compiled ahead of time). To use the tool,
# the CrossGen-generated assemblies need to have perfmaps generated
# by CrossGen /CreatePerfMap, expected in the /tmp directory.
# Copyright (C) 2018, Sasha Goldshtein
goldshtn / cpp11.cpp
Last active May 8, 2018 01:24
A single function that uses a bunch of C++11/14 features and for "old-school" C++ developers will not even read like C++ anymore.Specifically, it uses:- lambda functions (C++11) with generalized capture semantics (C++14)- rvalue references (C++11)- auto variables (C++11)- decltype and trailing function return type syntax (C++11)- std::move and s…
#include <iostream>
#include <future>
using namespace std;
template <typename Fn, typename... Args>
auto do_async_with_log(ostream& os, Fn&& fn, Args&&... args) ->
os << "[TID=" << this_thread::get_id()
goldshtn / vdp.asm
Last active March 23, 2018 13:28
Vectorized dot product of float arrays in C# and C++
; C++ core loop, key intrinsic is _mm_dp_ps
00007fff`548b10d5 0f100c0a movups xmm1,xmmword ptr [rdx+rcx] ; LOOP
00007fff`548b10d9 0f1011 movups xmm2,xmmword ptr [rcx]
00007fff`548b10dc 4883c110 add rcx,10h
00007fff`548b10e0 660f3a40d1f1 dpps xmm2,xmm1,0F1h
00007fff`548b10e6 f30f58c2 addss xmm0,xmm2
00007fff`548b10ea 4983e801 sub r8,1
00007fff`548b10ee 75e5 jne 00007fff`548b10d5 ; LOOP
; C# core loop, key intrinsic is Vector.Dot(Vector<float>, Vector<float>);
goldshtn / coreclr-usdt.patch
Created April 2, 2017 06:57
.NET Core (CoreCLR) patch for emitting USDT probes
diff --git a/src/scripts/ b/src/scripts/
index bacf034..3d40d77 100644
--- a/src/scripts/
+++ b/src/scripts/
@@ -407,8 +407,25 @@ def generateLttngTpProvider(providerName, eventNodes, allTemplates):
for eventNode in eventNodes:
eventName = eventNode.getAttribute('symbol')
templateName = eventNode.getAttribute('template')
+ template = allTemplates[templateName] if templateName else None
goldshtn / argdist-unicode.patch
Created April 2, 2017 08:06
One-time hack for BCC's argdist to support Unicode strings
diff --git a/build/../tools/ b/usr/share/bcc/tools/argdist
index 61f8e00..746d1b7 100755
--- a/build/../tools/
+++ b/usr/share/bcc/tools/argdist
@@ -451,7 +451,10 @@ DATA_DECL
# Most fields can be converted with plain str(), but strings
# are wrapped in a __string_t which has an .s field
if "__string_t" in type(v).__name__:
- return str(v.s)
+ s = bytearray(v.s)
goldshtn /
Last active February 22, 2017 13:27
iOS Lab #2

Download the course materials; this archive contains the presentations, demos, and lab solutions. Please do not distribute these materials outside of your group.

In this lab, you will create a simple tip calculator which you’d then be able to use to split the bill and tip across your friends. You should use the iOS > Application > Single View Application project template in Xcode, because you will only have one screen and one view controller.

Your UI should have the following components:

  • A title label that reads “Tip Calculator” – feel free to use a cute font here.
  • A text field for the bill amount, and a label that explains what it is.
  • A toggle switch that determines whether to round the bill to the nearest dollar, and a label that explains what it is.
  • A button that reads “Split Bill”, which, when tapped, calculates the bill amount and tip amount for each person in your party and displays it in a separate label underneath the button.
goldshtn / clrmd-sdd-demo.cs
Created May 19, 2016 15:28
CLRMD demo shown at SDD 2016
using Microsoft.Diagnostics.Runtime;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SDDTriage