Showing posts with label utilities. Show all posts
Showing posts with label utilities. Show all posts

Sunday, July 17, 2011

Tracing Java Applications with BTrace

BTrace is a dynamic tracing tool for Java. It allows you to insert tracing actions into the classes of a running Java program. This is especially useful, if you are using a third-party library. So, if you want to know whenever a certain method is called in your program, you can tell BTrace to print out a message whenever that method is hit. See the User Guide for more information.

Quick Start:

  • Download BTrace from here
  • Extract the release to a directory e.g. ~/btrace
  • Write a BTrace program. There are many samples present in the samples directory. Here is one of mine: the program below prints a message whenever the target program calls the ArrayList.add() method.
  • import com.sun.btrace.annotations.*;
    import static com.sun.btrace.BTraceUtils.*;
    import java.util.*;
    @BTrace
    public class ArrayListTrace {
    
        // @OnMethod annotation tells where to probe.
        // In this example, we are interested in entry
        // into the ArrayList.add() method.
        @OnMethod(
            clazz="java.util.ArrayList",
            method="add";
        )
        // print out what was added
        public static void alert(@Self ArrayList self, Object o) {
            print("ADDED ");
            println(o);
        }
    }
    
  • Compile your script:
  • javac -cp "~/btrace/build/*" ArrayListTrace.java
    
  • Start the java program you want to probe and get its pid.
  • Run BTrace and watch the messages appear:
  • ~/btrace/bin/btrace -cp ".:~/btrace/build/*" <PID> ArrayListTrace.class
    
Useful BTrace Programs:

Here are a few useful BTrace programs I have used in the past:
  • OnThrow: Prints out the stack trace of an exception whenever a Throwable is created. This way you can capture all exceptions, even those that have been swallowed.
  • LogTracer: Prints out log messages.
  • AllMethods: Prints out the name of every method entered.

Wednesday, August 25, 2010

Software Inventory of my Windows Machine

As I will be leaving my computer soon, I have decided to make a quick list of useful applications currently installed:
CategoryNameDescription
DatabaseAqua Data StudioDatabase Query Tool
DatabaseJaySQLJDBC Database Tool
DatabaseToadOracle Database Tool
DevAntBuild Tool
DevAxis 1.4Web Services Engine
DevAxis 2Web Services Engine
DevChainsawLog Viewer
DevCoberturaCode Coverage Tool
DevEclipseIDE
DevGroovyProgramming Language
DevGWTGoogle Web Toolkit
DevHermesJMSJMS Browser
DevHSQLDBJava Database Engine
DevJADJava Decompiler
DevJavaProgramming Language
DevMavenProject Build Tool
DevPerlProgramming Language
DevPuTTySSH Client
DevPython 2.6Programming Language
DevSciTESource Code Editor
DevsoapUIWeb Service Caller
DevSQLiteSQL database engine
DevTomcatServlet Engine
DevTortoiseCVSCVS Client
DevWinMergeDifferencing and Merging Tool
Devxmlbeans-2.4.0XML to Java type binding
EditorAltova XML SpyXML Editor
EditorEmacs 22.3Text Editor
EditorTextPad 4Text Editor
PerformanceCachemanXPWindows Tuneup Utility
PerformanceCCleanerPC Cleaner
PerformanceDefragglerDisk Defragmenter
PerformanceHijackThisSystem Scanner
ProductivityAlt-Tab Task SwitcherMS Powertoys
ProductivityCalculator PowertoyMS Powertoys
ProductivityClipXClipboard History Manager
ProductivityCmdHere PowertoyMS Powertoys
ProductivityLClockClock
ProductivityPassword SafePassword Manager
ProductivityProcessExplorerTask Manager
ProductivityPsToolsWindows Tools
ProductivitySlickRunQuick Application Launcher
ProductivityTaskixReorder taskbar items
ProductivityTweak UIMS Powertoys
ProductivityUnxUtilsGNU Utilities for Windows
Productivityxplorer² liteWindows File Manager
UtilitiesConvert Image To PDFPDF Converter
UtilitiesdoPDF 7PDF Converter
UtilitiesFoxitPDF Reader
UtilitiesWinRARArchive Manager
UtilitiesxmltidyTextPad addon
WebMozilla FirefoxWeb Browser
WebPidginInstant Messenger
And, ofcourse, browsing wouldn't be the same without my Firefox addons:
Firefox Addons
Adblock Plus
All-in-One Sidebar
British English Dictionary
Cache Status
Colorful Tabs
Delicious Bookmarks
Download Statusbar
DownThemAll!
dragdropupload
FaviconizeTab
Firebug
Fission
Flashblock
Forecastfox
FoxClocks
Greasemonkey
Mouse Gestures Redox
Tab Mix Plus
Tab Preview
Ubiquity
URL Fixer
If you think you have better alternatives for any of the applications above, please write a comment!

Thursday, August 12, 2010

Java Monitoring Tools

JDK 6.0 comes bundled with a number of handy, but often overlooked, utilities to monitor, manage and troubleshoot Java applications. They can be found in the bin directory of your installation. Here are a few of them explained:

1) jps - report java process status
This command prints information about active java processes running on a given machine. The output contains the JVMID, the name of the main class and any arguments passed to it or the JVM.

sharfah@starship:~> jps -lmv
3936 sun.tools.jps.Jps -lmv -Xms8m
5184 test.TestClient -Xmx1024m

2) jstat - statistics monitoring tool
This command allows you to monitor memory spaces of a JVM. For example, using the "-gcutil" option will show you the utilisation of the eden (E), survivor (S0, S1), old (O) and permanent (P) generations and how long the minor and major GCs are taking. You can gather these statistics continuously by specifying a sampling interval and how many samples you wish to take.

sharfah@starship:~> jstat -gcutil 5184 1s 5
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT
  0.00   0.00   3.04  85.47  11.68      5    0.009     1    0.023    0.032
  0.00   0.00   3.04  85.47  11.68      5    0.009     1    0.023    0.032
  0.00   0.00   3.04  85.47  11.68      5    0.009     1    0.023    0.032
  0.00   0.00   3.04  85.47  11.68      5    0.009     1    0.023    0.032
  0.00   0.00   3.04  85.47  11.68      5    0.009     1    0.023    0.032

3) jstack - stack trace
Prints out a complete thread dump of your application (just like "kill -3"). Useful for investigating what your application is doing and identifying deadlocks.

4) jmap - memory map
Use this command to print a histogram of the heap to show you the number of instances of each java class and how much memory they are occupying. You can also dump the heap to a file in binary format and then load it into Eclipse Memory Analyser as I described here.

sharfah@starship:~> jmap -histo 5184
sharfah@starship:~> jmap -dump:format=b,file=heap.bin 5184

5) jhat - heap analysis tool
This command reads a binary heap file (produced by the jmap command, for example). It launches a local webserver so that you can browse the heap using a web browser. The cool thing is being able to execute your own queries using Object Query Language (OQL) on the heap dump.

sharfah@starship:~> jhat heap.bin

6) jinfo - configuration info
Prints out java system properties (like the classpath and library path) and JVM command line flags. Doesn't work on Windows though! Also allows you to enable/disable/change VM flags.

sharfah@starship:~> jinfo -flag PrintGCDetails  4648
-XX:-PrintGCDetails
sharfah@starship:~> jinfo -flag +PrintGCDetails 4648

Monday, January 11, 2010

Find out who is logged on to a computer

Download PsTools from here which contains a suite of useful utilities. One of them is called psloggedon which allows you to see who is logged onto a specific computer.
C:\program files\PsTools>psloggedon.exe \\computername

loggedon v1.33 - See who's logged on
Copyright ® 2000-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

Users logged on locally:
     Error: could not retrieve logon time
NT AUTHORITY\LOCAL SERVICE
     Error: could not retrieve logon time
NT AUTHORITY\NETWORK SERVICE
     Error: could not retrieve logon time
domain\xpid
     Error: could not retrieve logon time
NT AUTHORITY\SYSTEM

Users logged on via resource shares:
     11/01/2010 13:36:31    domain\myxpid

Wednesday, February 21, 2007

Windows System Tools

These are useful tools which will tell you all you need to know about your Windows system:


BUILT-IN UTILITIES

  • MS INFO
    Start > Run > msinfo32
    System information.
    You will need to have the 'Help and Support' service enabled

  • DEVICE MANAGER
    Start > Run > devmgmt.msc
    Displays your hardware devices which you can choose to update or uninstall

  • DIRECTX DIAGNOSTICS
    Start > Run > dxdiag
    The most useful function for DXDiag is its ability to create a text file with all your major system information, including your main hardware specifications, driver files, and environmental settings.

  • MSCONFIG
    Start > Run > msconfig
    Allows you to select which programs are automatically launched when your computer first starts up. Also allows you to stop/start services.

  • REGEDIT
    Start > Run > regedit
    Launches the Registry Editor. The Registry contains information that Windows continually references during operation, such as profiles for each user, the applications installed on the computer and the types of documents that each can create, property sheet settings for folders and application icons, what hardware exists on the system, and the ports that are being used.


EXTERNAL SOFTWARE
  • System Information for Windows
    SIW is the System Information for Windows tool which can be downloaded from the SIW Website. "Everything you want to know about your computer."

  • CPU-Z
    You can download CPU-Z from the CPU-Z Website. Provides you with everything you need to know about your CPU, such as its name/number, core stepping, package, voltage, cache information etc. It will also tell you about your system's current Bus speed under the CPU tab, your full motherboard details under the Motherboard tab, and your RAM's complete details under the Memory and SPD tabs. Note that for information to appear under the SPD tab you will have to first select the slot(s) on the motherboard that your RAM stick(s) occupy, otherwise the box will be empty.

  • NERO INFOTOOL
    You can download the Nero Disk InfoTool Utility from the CD Speed Website. It is a utility which analyses and displays the most important information about a drive, disc, configuration and software. The information can also be printed or saved to a text file.

  • JDiskReport
    You can download it from JGoodies. Illustrates with the help of graphs, how much space the files and directories consume on your disk drives and it helps you find where space is being used up.