Skip to content

Instantly share code, notes, and snippets.

Sasha Goldshtein goldshtn

View GitHub Profile
@goldshtn
goldshtn / place-probe.py
Last active Sep 13, 2018
Place a dynamic probe on a .NET Core method
View place-probe.py
#!/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
goldshtn / argdist-unicode.patch
Created Apr 2, 2017
One-time hack for BCC's argdist to support Unicode strings
View argdist-unicode.patch
diff --git a/build/../tools/argdist.py b/usr/share/bcc/tools/argdist
index 61f8e00..746d1b7 100755
--- a/build/../tools/argdist.py
+++ 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
goldshtn / coreclr-usdt.patch
Created Apr 2, 2017
.NET Core (CoreCLR) patch for emitting USDT probes
View coreclr-usdt.patch
diff --git a/src/scripts/genXplatLttng.py b/src/scripts/genXplatLttng.py
index bacf034..3d40d77 100644
--- a/src/scripts/genXplatLttng.py
+++ b/src/scripts/genXplatLttng.py
@@ -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
goldshtn / analyze.py
Created Mar 4, 2017
.NET Core on Linux LLDB analysis scripts
View analyze.py
#!/usr/bin/env python
#
# analyze.py 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 libsosplugin.so for your
# CoreCLR version, and gdb.
#
# USAGE: analyze.py [--memory] [--stacks] COREFILE
#
# NOTE: To run this as stand-alone, you might need to fix some bad symlinks
@goldshtn
goldshtn / dotnet-mapgen-v2.py
Last active Nov 11, 2019
dotnet-mapgen: generates map files for crossgen-compiled assemblies, and merges them into the main perf map file
View dotnet-mapgen-v2.py
#!/usr/bin/env python
#
# USAGE: dotnet-mapgen [-h] {generate,merge} PID
#
# In generate mode, this tool reads the /tmp/perfinfo-PID.map 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
goldshtn / clrmd-sdd-demo.cs
Created May 19, 2016
CLRMD demo shown at SDD 2016
View clrmd-sdd-demo.cs
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
goldshtn / vdp.asm
Last active Mar 23, 2018
Vectorized dot product of float arrays in C# and C++
View vdp.asm
; 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
goldshtn / dp.asm
Created Aug 15, 2015
Dot product of shorts and floats: C# vs. C++
View dp.asm
; 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
goldshtn / typelist_sort.cpp
Last active Aug 29, 2015
Sort a typelist by size at compile-time, using quicksort.
View typelist_sort.cpp
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>,
typelist<Head>,
@goldshtn
goldshtn / ioslab2.md
Last active Feb 22, 2017
iOS Lab #2
View ioslab2.md

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.
You can’t perform that action at this time.