private static synchronized void initialize ( ) { PlatformProperties pp = PlatformProperties . getPlatformProperties ( ) ; String processName = java . lang . management . ManagementFactory . getRuntimeMXBean ( ) . getName ( ) ; String pidString = processName . substring ( 0 , processName . indexOf ( ' ' ) ) ; pid = Integer . valueOf ( pidString ) ; initialized = true ; // get the RSS and other stats from scraping "ps" from the command line PSScraper . PSData psdata = PSScraper . getPSData ( pid ) ; assert ( psdata . rss > 0 ) ; // figure out how much memory this thing has memorysize = pp . ramInMegabytes ; assert ( memorysize > 0 ) ; // now try to figure out the best way to get the rss size long rss = - 1 ; // try the mac method try { rss = ExecutionEngine . nativeGetRSS ( ) ; } // This catch is broad to specifically include the UnsatisfiedLinkError that arises when // using the hsqldb backend on linux -- along with any other exceptions that might arise. // Otherwise, the hsql backend would get an annoying report to stdout // as the useless stats thread got needlessly killed. catch ( Throwable e ) { } if ( rss > 0 ) mode = GetRSSMode . MACOSX_NATIVE ; // try procfs rss = getRSSFromProcFS ( ) ; if ( rss > 0 ) mode = GetRSSMode . PROCFS ; // notify users if stats collection might be slow if ( mode == GetRSSMode . PS ) { VoltLogger logger = new VoltLogger ( "HOST" ) ; logger . warn ( "System statistics will be collected in a sub-optimal " + "manner because either procfs couldn't be read from or " + "the native library couldn't be loaded." ) ; } }
Get the process id the total memory size and determine the best way to get the RSS on an ongoing basis .