Skip to content

Instantly share code, notes, and snippets.

View ivoanjo's full-sized avatar

Ivo Anjo ivoanjo

View GitHub Profile
# This file is used to load the profiling native extension. It works in two steps:
#
# 1. Load the datadog_profiling_loader extension. This extension will be used to load the actual extension, but in
# a special way that avoids exposing native-level code symbols. See `datadog_profiling_loader.c` for more details.
#
# 2. Use the Datadog::Profiling::Loader exposed by the datadog_profiling_loader extension to load the actual
# profiling native extension.
#
# All code on this file is on-purpose at the top-level; this makes it so this file is executed only once,
# the first time it gets required, to avoid any issues with the native extension being initialized more than once.
#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <locale.h>
@ivoanjo
ivoanjo / example1.json
Created July 27, 2022 08:59
Broken gvl-trace on macOS
[
{"ph": "E", "pid": 5454, "tid": 4615450112, "ts": 29.000000},
{"ph": "B", "pid": 5454, "tid": 4615450112, "ts": 29.000000, "name": "started_tracing"},
{"ph": "E", "pid": 5454, "tid": 4615450112, "ts": 223.000000},
{"ph": "B", "pid": 5454, "tid": 4615450112, "ts": 223.000000, "name": "suspended"},
{"ph": "E", "pid": 5454, "tid": 123145516716032, "ts": 254.000000},
{"ph": "B", "pid": 5454, "tid": 123145516716032, "ts": 254.000000, "name": "started"},
{"ph": "E", "pid": 5454, "tid": 123145516716032, "ts": 264.000000},
{"ph": "B", "pid": 5454, "tid": 123145516716032, "ts": 264.000000, "name": "ready"},
{"ph": "E", "pid": 5454, "tid": 123145516716032, "ts": 265.000000},
This file has been truncated, but you can view the full file.
truffleruby 21.1.0-dev-3414643e, like ruby 2.7.2, GraalVM CE Native [x86_64-darwin]
[To redirect Truffle log output to a file use one of the following options:
* '--log.file=<path>' if the option is passed using a guest language launcher.
* '-Dpolyglot.log.file=<path>' if the option is passed using the host Java launcher.
* Configure logging using the polyglot embedding API.]
[ruby] SEVERE: waited 5 seconds in the SafepointManager but 12 of 66 threads did not arrive - a thread is likely making a blocking call - reason for the safepoint: Thread#backtrace_locations
Dumping stacktraces of all threads:
IN SAFEPOINT: Thread[Ruby Thread id=43 from /Users/ivo.anjo/.rvm/gems/truffleruby-head/gems/mongo-2.14.0/lib/mongo/background_thread.rb:98,5,main]
com.oracle.svm.core.posix.headers.Pthread.pthread_cond_wait(Pthread.java)
com.oracle.svm.core.posix.thread.PosixParkEvent.condWait(PosixJavaThreads.java:250)
@ivoanjo
ivoanjo / keybase.md
Created April 18, 2017 13:12
keybase.md

Keybase proof

I hereby claim:

  • I am ivoanjo on github.
  • I am ivoanjo (https://keybase.io/ivoanjo) on keybase.
  • I have a public key ASCduuenszOyBDj-2LP2kk2QWbvprr8qPDjXpqOfH9n5wQo

To claim this, I am signing this object:

@ivoanjo
ivoanjo / rabbit_fail_test.rb
Created September 29, 2016 10:20
Experiment with using several queues to do ttl-based exponential backoff for messages that fail during processing
require 'bunny'
require 'pry'
require 'json'
# Relevant links:
# * http://www.rabbitmq.com/dlx.html
# * https://www.rabbitmq.com/ttl.html
# "While consumers never see expired messages, only when expired messages reach the head of a queue will they actually be discarded (or dead-lettered). When setting a per-queue TTL this is not a problem, since expired messages are always at the head of the queue. When setting per-message TTL however, expired messages can queue up behind non-expired ones until the latter are consumed or expired. Hence resources used by such expired messages will not be freed, and they will be counted in queue statistics (e.g. the number of messages in the queue)."
# * http://bitsuppliers.com/dead-lettering-with-rabbitmq/
@ivoanjo
ivoanjo / test_multiple_queues.rb
Created August 27, 2016 00:02
Consuming multiple queues with MarchHare's low-level api
require 'march_hare'
require 'pry'
connection = MarchHare.connect(thread_pool_size: 10, automatically_recover: false)
connection.start
channel = connection.create_channel
# create queues
queue_names = (1..3).map { |n| "queue#{n}" }
@ivoanjo
ivoanjo / pairs.rb
Created March 16, 2015 22:26
Ruby implementation of pairs game
#!/usr/bin/ruby
def print_number(i)
i.to_s.rjust(2, '0')
end
def validate(result)
result.each do |r1|
result.each do |r2|
next if r1 == r2
@ivoanjo
ivoanjo / heap-navigator.rb
Created March 9, 2015 10:38
Simple ruby heap dump json navigator
#!/usr/bin/env ruby
# encoding: utf-8
require 'pry'
require 'json'
require 'awesome_print'
AP_OPTIONS = {indent: 2, index: false, multiline: false}
def load_heap(file)