Skip to content

Instantly share code, notes, and snippets.

View goldshtn's full-sized avatar

Sasha Goldshtein goldshtn

View GitHub Profile
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 / 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 / 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 /
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 / 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
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 / dp.asm
Created August 15, 2015 07:12
Dot product of shorts and floats: C# vs. C++
; C#, RyuJIT, release, x64
00007ffe`fc6808ec 4c63c8 movsxd r9,eax ; loop: r9 = i
00007ffe`fc6808ef 4e0fbf4c4910 movsx r9,word ptr [rcx+r9*2+10h] ; r9 = a[i]
00007ffe`fc6808f5 f3410f2ac9 cvtsi2ss xmm1,r9d ; xmm1 = (float)r9d
00007ffe`fc6808fa 4c63c8 movsxd r9,eax ; r9 = i
00007ffe`fc6808fd f3420f594c8a10 mulss xmm1,dword ptr [rdx+r9*4+10h] ; xmm1 *= b[i]
00007ffe`fc680904 f30f58c1 addss xmm0,xmm1 ; sum += xmm1
00007ffe`fc680908 ffc0 inc eax ; ++i
00007ffe`fc68090a 443bc0 cmp r8d,eax ; if i < a.Length
00007ffe`fc68090d 7fdd jg 00007ffe`fc6808ec ; goto loop
goldshtn / typelist_sort.cpp
Last active August 29, 2015 14:13
Sort a typelist by size at compile-time, using quicksort.
template <typename Predicate, typename Head, typename... Tail>
struct typelist_sort_t<Predicate, typelist<Head, Tail...>>
using predicate = meta_partial_apply<Predicate, Head>;
using notpredicate = meta_negate<predicate>;
using smaller_than = typelist_filter<notpredicate, typelist<Tail...>>;
using greater_than = typelist_filter<predicate, typelist<Tail...>>;
using type = typelist_cat<
typelist_sort<Predicate, smaller_than>,
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.