Package Androidapi;
Import Android.util.Log;
Class monitoring implements Runnable
{
public void Run ()
{
while (! Thread.CurrentThread (). isinterrupted ())
{
Try
{
Thread.Sleep (100);
catch (Interruptedexception s)
{
Thread.CurrentThread (). interrupt ();
}
Androiddebug.printvarymemory ();
}
}
}
public class Androiddebug
{
private static Boolean m_bisdebug = false;
/**
* Set Debug mode
*
* @param bisdebug
*/
public static void SetMode (Boolean bisdebug)
{
M_bisdebug = Bisdebug;
}
/**
* Whether to debug mode
* @return
*/
public static Boolean Isdebug ()
{
return m_bisdebug;
}
/**
* Print Information
*
* @param strtxt
*/
public static void println (String strtxt)
{
if (M_bisdebug)
{
System.out.println (Strtxt);
}
}
/**
* Print Information
*
* @param strtxt
*/
public static void Log (String strtag, String strtxt)
{
if (M_bisdebug)
{
LOG.I (Strtag,strtxt);
}
}
/**
* Forced garbage collection, which can be used to detect destructors, detect whether unused objects have
*/
public static void GC ()
{
if (M_bisdebug)
{
System.GC ();
}
}
/**
* Print Heap Total
*/
public static void Printtotalmemory ()
{
Runtime r = Runtime.getruntime ();
ANDROIDDEBUG.PRINTLN ("Total memory are:" + r.totalmemory ());
}
/**
* Print Heap Remaining Amount
*/
public static void Printfreememory ()
{
GC (); Perform a forced recycle to get the exact remaining amount
Runtime r = Runtime.getruntime ();
Androiddebug.println ("Free memory are:" + r.freememory ());
}
/**
* Print Heap Change volume
*/
static long Longpre = 0;
public static void Printvarymemory ()
{
GC (); Perform a forced recycle to get the exact remaining amount
Runtime r = Runtime.getruntime ();
Long Longnow = R.freememory ();
if (Longnow > Longpre)
{
Androiddebug.println ("Free memory->:" + (Longnow-longpre));
Longpre = Longnow;
else if (Longnow < Longpre)
{
Androiddebug.println ("Free memory <-:" + (Longpre-longnow));
Longpre = Longnow;
}
}
/**
* Monitor Memory
*
* @param bisopen
*/
private static Thread m_pthread = null;
public static void Setmonitore (Boolean bisopen)
{
if (Bisopen)
{
if (null = = M_pthread)
M_pthread = new Thread (new Monitoring ());
M_pthread.setdaemon (TRUE);
M_pthread.start ();
}
Else
{
if (null!= m_pthread)
{
M_pthread.interrupt ();
M_pthread = null;
}
}
}