Ejemplo n.º 1
0
func TestOrderByPid(t *testing.T) {
	reader := strings.NewReader(`
2014-12-31 11:01:49
Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.65-b04 mixed mode):

"AWT-Windows" daemon prio=6 tid=0x0000000007e88800 nid=0x17a4 runnable [0x0000000009bef000]
   java.lang.Thread.State: BLOCKED (on object monitor)
"zZ" daemon prio=6 tid=0x0000000007e88800 nid=0x17a5 runnable [0x0000000009bef000]
   java.lang.Thread.State: RUNNABLE
"a" prio=1 tid=0x2 nid=0x3 waiting on condition [0x4]
   java.lang.Thread.State: WAITING (parking)
"AWT-Shutdown" prio=6 tid=0x0000000007e31800 nid=0xb34 in Object.wait() [0x0000000009aef000]
   java.lang.Thread.State: WAITING (on object monitor)
"ZZ" prio=6 tid=0x00000000092e4000 nid=0x7fc in Object.wait() [0x000000000a70e000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
`)

	parser := tdformat.NewParser(reader)
	assert.NotNil(t, parser)

	var out bytes.Buffer

	listThreads(parser, Conf{"pid", false, printDecimalPid}, &out)
	assert.Equal(t, `
a                                   P      3
ZZ                                  T   2044
AWT-Shutdown                        W   2868
AWT-Windows                         B   6052
zZ                                  R   6053
`, "\n"+out.String())
}
Ejemplo n.º 2
0
func TestClassFilter(t *testing.T) {
	reader := strings.NewReader(`
2014-12-31 11:01:49
Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.65-b04 mixed mode):

"filteredOut" daemon prio=8 tid=0x00000000094ce800 nid=0xe2c in Object.wait() [0x000000000ce3e000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
	- locked <0x123> (a java.lang.Object)

"holder1" daemon prio=8 tid=0x00000000094ce800 nid=0xe2c in Object.wait() [0x000000000ce3e000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
	- locked <0x456> (a a.b.C)
`)

	parser := tdformat.NewParser(reader)
	assert.NotNil(t, parser)

	var out bytes.Buffer

	listLocks(parser, 0, "a.b.C", &out)
	assert.Equal(t, `
Dump: 2014-12-31 11:01:49
"holder1" holds 0x456 (a.b.C)

`, "\n"+out.String())
}
Ejemplo n.º 3
0
func TestSingleDump(t *testing.T) {
	reader := strings.NewReader(`
2014-12-31 11:01:49
Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.65-b04 mixed mode):

"AWT-Windows" daemon prio=6 tid=0x0000000007e88800 nid=0x17a4 runnable [0x0000000009bef000]
   java.lang.Thread.State: RUNNABLE
"AWT-Shutdown" prio=6 tid=0x0000000007e31800 nid=0xb34 in Object.wait() [0x0000000009aef000]
   java.lang.Thread.State: WAITING (on object monitor)
"a" prio=1 tid=0x2 nid=0x3 waiting on condition [0x4]
   java.lang.Thread.State: WAITING (parking)
"AWT-Windows" daemon prio=6 tid=0x0000000007e88800 nid=0x17a4 runnable [0x0000000009bef000]
   java.lang.Thread.State: RUNNABLE
"Thread-2" prio=6 tid=0x00000000092e4000 nid=0x7fc in Object.wait() [0x000000000a70e000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
"My thread" prio=10 tid=0x00007fffec015800 nid=0x1775 waiting for monitor entry [0x00007ffff15e5000]
   java.lang.Thread.State: BLOCKED (on object monitor)
"Thread-2" prio=6 tid=0x00000000092e4000 nid=0x7fc in Object.wait() [0x000000000a70e000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
`)
	parser := tdformat.NewParser(reader)
	assert.NotNil(t, parser)

	stats := allStats(parser)
	assert.NotNil(t, stats)
	assert.Equal(t, 1, len(stats))
	assert.Equal(t, 5, len(stats[0].stats))
	assert.Equal(t, 2, stats[0].stats[tdformat.THREAD_RUNNING])
	assert.Equal(t, 1, stats[0].stats[tdformat.THREAD_WAITING])
	assert.Equal(t, 2, stats[0].stats[tdformat.THREAD_TIMED_WAITING])
	assert.Equal(t, 1, stats[0].stats[tdformat.THREAD_BLOCKED])
	assert.Equal(t, 1, stats[0].stats[tdformat.THREAD_PARKED])
}
Ejemplo n.º 4
0
/*
	A special test for Object.wait() because the thread is then both locker and waiting.
*/
func TestObjectWait(t *testing.T) {
	reader := strings.NewReader(`
2014-12-31 11:01:49
Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.65-b04 mixed mode):

"D3D Screen Updater" daemon prio=8 tid=0x00000000094ce800 nid=0xe2c in Object.wait() [0x000000000ce3e000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
	- waiting on <0x00000000c0092b98> (a java.lang.Object)
	- locked <0x00000000c0092b98> (a java.lang.Object)

`)

	parser := tdformat.NewParser(reader)
	assert.NotNil(t, parser)

	var out bytes.Buffer

	listLocks(parser, 0, "", &out)
	assert.Equal(t, `
Dump: 2014-12-31 11:01:49
"D3D Screen Updater" holds 0x00000000c0092b98 (java.lang.Object)
- D3D Screen Updater

`, "\n"+out.String())
}
Ejemplo n.º 5
0
func InitTool() tdformat.Parser {
	showHelp := flag.Bool("h", false, "shows this help")
	fileName := flag.String("f", "", "the file to use (stdin is used per default)")

	flag.Parse()

	if *showHelp {
		flag.PrintDefaults()
		os.Exit(0)
	}

	reader, err := tdformat.OpenFile(fileName)
	// FIXME: the reader has to be closed somehow
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not open file '%v': %v\n", *fileName, err)
		os.Exit(1)
	}

	return tdformat.NewParser(reader)
}