Skip to content

Instantly share code, notes, and snippets.

@pankkor
pankkor / psmon.sh
Last active July 4, 2025 12:17
Monitor specific process tree hierarchy with `pgrep` and `pstree`
#!/bin/sh
help="
Monitor specific process tree hierarchy.
Pass case instensitive name of a process as a first argument.
USAGE:
./psmon.sh [proccess_name]
"
if [ $# -lt 1 ]; then
@pankkor
pankkor / on_writing_code.md
Last active October 20, 2025 09:19
Brain dump on writing code

“There are no solutions. There are only trade-offs.” ― Thomas Sowel

TL;DR:

  • Writing code is craft. Master your craft.
  • Keep it simple.
  • Writing simple code is hard.
  • Simple code is rarely celebrated as an achievement. Folks worship meta-programming when old school macro can do the trick.
  • Code is liability. Prefer removing code over adding it. Strongly prefer removing code in big codebases.
  • Complexity kills. Kills UX, development times, quality, costs, debugability, comprehensibility.
@pankkor
pankkor / perf.md
Created May 1, 2025 14:58
Linux perf howto.

Installation

sudo apt install linux-tools-common

Setup

To be able to grab performance and kernel events. Lower sampling rate to 10000, if it takes too much time. If it happens kernel will automatically lower perf_event_max_sample_rate. Examine dmesg  output for perf: interrupt took too long, lowering kernel.perf_event_max_sample_rate to value.

sudo dmesg -wH | grep perf:
@pankkor
pankkor / reduce_variance_lin.sh
Created April 29, 2025 08:45
Reduce performance variance of Linux machine.
#!/bin/sh
help="Reduce performance variance of the system.
OPTIONS:
-h, --help This help.
* ANY other argument reverts the changes.
"
case "$1" in
@pankkor
pankkor / perf_variance.md
Last active April 28, 2025 12:56
Reduce performance variance of benchmarks

Reduce performance variance of benchmarks

Linux

  • Set/Reset the CPU governor
    cpupower frequency-info -o proc
    sudo cpupower frequency-set --governor performance
    
  • Disable CPU boosting
@pankkor
pankkor / perf_archive.md
Last active October 14, 2024 12:59
Linux: gather profiles on remote machine with `perf archive`.

Perf: Profiling on machine A and investigating on machine B

Perf setup

Apt (Debian, Ubuntu)

  • On newer systems:
sudo apt install linux_perf
  • On older systems:
FORCE_INLINE static f32 absf32(f32 v) {
f32 ret;
__asm__ volatile (
"fabs %s0, %s1\n"
: "=w" (ret)
: "w" (v)
);
return ret;
}
@pankkor
pankkor / macOS_input_monitor.md
Last active July 4, 2024 13:57
macOS input monitoring and data collection

Snippets

Quickly limit resources for the process with ulimit

LIMIT_MB=50
(ulimit -Sv $((LIMIT_MB << 10)); /path/to/binary)

On OpenBSD use