#!/usr/sbin/dtrace -qs

/*
  Program: Print object allocation statistics <newobjects>

  Author: Matty < matty91 at gmail dot com >

  Current Version: 1.0

  Date: 8-29-2007

  Revision History: 
  
  Version 1.0
   - initial release

  License:
    The contents of this file are subject to the terms of the
    Common Development and Distribution License, Version 1.0 only
    (the "License").  You may not use this file except in compliance
    with the License.
 
    You can obtain a copy of the license at Docs/cddl1.txt
    or http://www.opensolaris.org/os/licensing.
    See the License for the specific language governing permissions
    and limitations under the License.

  Purpose: Prints the total number of objects allocated, as well as the
  number of bytes that are allocated as part of the obejct creations.

  Sample output:

  $ newobejcts
  Class                           Objects     Bytes Allocated
  MyTest                          35          560       
  java/nio/HeapCharBuffer         210         10080     
*/


hotspot*:::object-alloc 
{ 
     @totalobjects[copyinstr(arg1,arg2)] = count();
     @objectbytes[copyinstr(arg1,arg2)] = sum(arg3);
}

profile:::tick-5sec
{
     printf("%-30s  %-15s  %-10s\n", "Class", 
                                     "Objects created", 
                                     "Bytes Allocated");

     printa("%-30s  %-15@d  %-10@d\n", @totalobjects, 
                                       @objectbytes);
     printf("\n");

     trunc(@totalobjects);
     trunc(@objectbytes);
}
