Skip to content

Instantly share code, notes, and snippets.

@ytoshima
ytoshima / CoreAmap.scala
Created March 12, 2012 04:40
Prints address map with gap size between segment within a core file
/**
* Prints address map with gap size between segment
* within a core file. This program uses readelf
* command and expects the output is same as the
* readelf on Linux.
*/
object CoreAmap {
def main(args: Array[String]) {
for (a <- args) doAmapCore(a)
}
@ytoshima
ytoshima / PmapFilter.scala
Created April 24, 2012 10:59
A filter for pmap putout
object PmapFilter {
case class Mr(start: Long, end: Long, desc: String) {
override def toString =
"%08x-%08x %6dk %s".format(start, end, (end-start)/1024, desc)
}
def process(path: String) : String = {
import scala.io.Source
def procMr(current: Mr, prevEnd: Long) = prevEnd match {
case 0 => current.toString
case x if prevEnd == current.start => current.toString
@ytoshima
ytoshima / javamem.scala
Last active October 5, 2015 06:48
misc snippets
import collection.JavaConversions._
import java.lang.management._
val MB = (1024*1024).toFloat
def b2mb(bval: Long): Float = bval / MB
def mpoolSum(mp: MemoryPoolMXBean) = "%s: use %.2f comm %.2f max %.2f".format(mp.getName, b2mb(mp.getUsage.getUsed), b2mb(mp.getUsage.getCommitted), b2mb(mp.getUsage.getMax))
def minfo = ManagementFactory.getMemoryPoolMXBeans.filter(_.getType == MemoryType.HEAP).map(mpoolSum).mkString("\n")
@ytoshima
ytoshima / cpumem.cpp
Created May 23, 2012 09:05
Simple stress program
/*
* A small cpu and memory stress program
* compile: CC cpumem.cpp -o cpumem -lpthread
* or: make LDFLAGS=-lpthread cpumem
*/
#include <pthread.h>
#include <iostream>
#include <vector>
#include <sys/types.h>
#include <assert.h>
@ytoshima
ytoshima / StackUse.scala
Last active October 7, 2015 03:18
Print process' stack use on modern Linux
/**
* Print thread stack use for each thread.
* This is for linux which has /proc/<pid>/smaps and /proc/<pid>/task/<tid>/stat.
*/
object StackUse extends App {
import scala.util.control.Exception._
import scala.io.Source
import java.io.File
/**
* Parse (pid, task stat string) tuple and returns (pid, sp) tuple.
@ytoshima
ytoshima / gist:4747954
Created February 10, 2013 01:46
A simple script to show screen resolution
#!/bin/sh
exec ~/local/scala-2.10.0/bin/scala "$0" "$@"
!#
val ge = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment
val mode = ge.getDefaultScreenDevice.getDisplayMode
println("%dx%d".format(mode.getWidth, mode.getHeight))
@ytoshima
ytoshima / ck-runtime.c
Created February 21, 2013 09:18
Check whether the specified command line completed in the specified duration in seconds.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <signal.h>
#include <string.h>
@ytoshima
ytoshima / build.bat
Created March 23, 2013 05:04
ps like command for windows
cl /Zi -D_UNICODE ps2.cpp Psapi.lib
@ytoshima
ytoshima / trapex.c
Created May 31, 2013 01:10
A simple program to verify si_code=128 behaviour .
/* Simple test program to verify si_code=SI_KERNEL(128) for address
* above TASK_SIZE64 or TASK_SIZE_MAX (0x800000000000 - 4096 = 0x7ffffffff000)
* See do_page_fault(k).
*/
#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
@ytoshima
ytoshima / DBLEx.scala
Created June 17, 2013 02:56
Berkley-DB Java Edition examples in scala...
package persist.gettingStarted
import com.sleepycat.persist.model.{Entity, PrimaryKey, SecondaryKey}
import com.sleepycat.persist.model.Relationship._
@Entity
class Vendor {
var address: String = _
var bizPhoneNumber: String = _
var city: String = _