Skip to content

Instantly share code, notes, and snippets.

@dt
dt / glittery-toasting-pebble.md
Last active April 9, 2026 13:46
Zero-Allocation pprof Labels — design doc

Zero-Allocation pprof Labels

Motivation

We want the cost of applying pprof labels to be low enough that we stop conditionally labeling. Today, CockroachDB only applies labels when a profile is actively being collected, checked via an atomic. This means operations that passed the labeling point before profiling started are unlabeled, goroutine dumps are unlabeled, and when labeling IS on, it costs more than it should.

Why isn't the cost zero today?

pprof.Do(ctx, Labels("req", strconv.Itoa(id)), func(ctx) { ... }) triggers 4-5 heap allocations:

package main
import (
"compress/gzip"
"fmt"
"os"
"runtime"
"sync"
"sync/atomic"
"time"
@dt
dt / debug_4.txt
Created August 12, 2025 22:14
debug=4 example
goroutine profile: total 545
1 @ 0x100df3960 0x100e31b9c 0x101590bfc 0x100e387c4
# goroutine: 37
# created by: 12
# created at: os/signal.Notify.func1.1, GOROOT/src/os/signal/signal.go:152 +0x101590cf8
# state: syscall
# waiting: 92 minutes
# 0x100e31b9b os/signal.signal_recv+0x2b GOROOT/src/runtime/sigqueue.go:149
# 0x101590bfb os/signal.loop+0x1b GOROOT/src/os/signal/signal_unix.go:23
@dt
dt / test
Created February 11, 2022 22:11
// Copyright 2022 The Cockroach Authors.
//
// Licensed as a CockroachDB Enterprise file under the Cockroach Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt
package backupccl_test
@dt
dt / google-script-append
Created March 29, 2019 03:42
google append to sheet
var f = SpreadsheetApp.openById('1ZPixvI2lBGPTC-3YmmtbRqEJHU5-A02k9Jfhpw2vw9Q');
var sheet = f.getSheetByName('Sheet1');
function doPost(e) {
Logger.log(e);
console.log(e);
parsedData = JSON.parse(e.postData.contents);
var nextFreeRow = sheet.getLastRow() + 1;
sheet.appendRow([parsedData.co2]);
@dt
dt / co2-sensor-google-log.ino
Last active March 30, 2019 20:58
google logging co2 sensor
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WebServer.h>
#include <ArduinoOTA.h>
#include "HTTPSRedirect.h"
#include <SoftwareSerial.h>
@dt
dt / gist:0f658f7a96af08cec26af8f0cfb52d08
Created March 26, 2019 12:17
import timings for tpcc 1k
distsql import, csv reader (i.e. master): 55m
I190326 04:27:02.291051 1 ccl/workloadccl/cliccl/fixtures.go:325 starting import of 9 tables
W190326 04:27:02.293200 1 ccl/workloadccl/fixture.go:541 error retrieving automatic stats cluster setting: pq: unknown setting: "sql.stats.automatic_collection.enabled"
I190326 04:27:12.273697 84 ccl/workloadccl/fixture.go:516 imported warehouse (10s, 1000 rows, 0 index entries, 53 KiB)
I190326 04:27:15.543774 85 ccl/workloadccl/fixture.go:516 imported district (13s, 10000 rows, 0 index entries, 1005 KiB)
I190326 04:27:16.486648 90 ccl/workloadccl/fixture.go:516 imported item (14s, 100000 rows, 0 index entries, 7.8 MiB)
I190326 04:29:01.189457 89 ccl/workloadccl/fixture.go:516 imported new_order (1m59s, 9000000 rows, 0 index entries, 126 MiB)
I190326 04:43:08.922034 88 ccl/workloadccl/fixture.go:516 imported order (16m7s, 30000000 rows, 60000000 index entries, 1.8 GiB)
I190326 04:46:40.282246 87 ccl/workloadccl/fixture.go:516 imported history (19m38s, 30000000 row
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WebServer.h>
#include <ArduinoOTA.h>
#include <SoftwareSerial.h>
byte cmdRead[2] = {0x86, 0x00};
@dt
dt / backup-cockroach.sh
Created July 24, 2018 19:39
daily cockroachdb backup script
#!/bin/bash
set -euxo pipefail
# this script runs backups, creating full backups when run on the configured
# day of the week and incremental backups when run on other days, tracking the
# backups it has created recently to correctly construct the list of path for
# the INCREMENTAL option.
full_day="Sunday" # Must match (including case) the output of `date +%A`.
what="DATABASE mydb" # what to backup.
We can't make this file beautiful and searchable because it's too large.
TsvHttpData-1.0
https://roachfixtureswestus.blob.core.windows.net/tpch-csv/schema/customer.sql 443 rv/C6ONfr0GbLWxU+OiEWQ==
https://roachfixtureswestus.blob.core.windows.net/tpch-csv/schema/lineitem.sql 1080 sB5XH/PGvwzhc5tFdEwoYQ==
https://roachfixtureswestus.blob.core.windows.net/tpch-csv/schema/nation.sql 244 UcNJfOiDKzURD2mE30xVrA==
https://roachfixtureswestus.blob.core.windows.net/tpch-csv/schema/orders.sql 544 VvHfU/2KyB4RPYM+LAdB4A==
https://roachfixtureswestus.blob.core.windows.net/tpch-csv/schema/part.sql 437 Suxl0WfMb2NxbbM+TcdMBQ==
https://roachfixtureswestus.blob.core.windows.net/tpch-csv/schema/partsupp.sql 518 2v4BEsinf0YT0pUQA6XrPQ==
https://roachfixtureswestus.blob.core.windows.net/tpch-csv/schema/region.sql 163 luoOoSlPBa9fZbQTObyS7Q==
https://roachfixtureswestus.blob.core.windows.net/tpch-csv/schema/supplier.sql 395 Qkn26eOFJzLdmfV/3AmSiA==
https://roachfixtureswestus.blob.core.windows.net/tpch-csv/sf-1/customer.tbl.1 3032883 XNOiON5TjyD+xRBOypeZRw==