Exemple #1
0
        private static String uft()
        {
            System.Diagnostics.Process rt = System.Diagnostics.Process.GetCurrentProcess();
            long free = rt.freeMemory(), total = rt.totalMemory(), used = total - free;

            //		long max = rt.maxMemory();
            SupportClass.TextNumberFormat nf = SupportClass.TextNumberFormat.getTextNumberInstance();
            //        System.out.println("used: "+nf.format(used)+" free: "+nf.format(free)+" total: "+nf.format(total)+" max: "+nf.format(max));
            return(", used " + nf.FormatLong(used) + ", free " + nf.FormatLong(free) + ", total " + nf.FormatLong(total));            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }
Exemple #2
0
        /// <summary> Prints a memory test debug statement to stdout
        /// with a tag to reference. After printing the message
        /// the app waits for Pause milliseconds to allow profiling
        ///
        /// Requires memory printing to be enabled, otherwise
        /// is a no-op
        /// </summary>
        /// <param name="tag">
        /// </param>
        /// <param name="pause">
        /// </param>
        public static void  printMemoryTest(System.String tag, int pause)
        {
            if (!MEMORY_PRINT_ENABLED)
            {
                return;
            }
            System.GC.Collect();
            System.Diagnostics.Process r = System.Diagnostics.Process.GetCurrentProcess();
            //UPGRADE_ISSUE: Method 'java.lang.Runtime.freeMemory' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangRuntimefreeMemory'"
            long free = r.freeMemory();
            //UPGRADE_ISSUE: Method 'java.lang.Runtime.totalMemory' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangRuntimetotalMemory'"
            long total = r.totalMemory();

            if (tag != null)
            {
                System.Console.Out.WriteLine("=== Memory Evaluation: " + tag + " ===");
            }

            System.Console.Out.WriteLine("Total: " + total + "\nFree: " + free);

            int chunk       = 100;
            int lastSuccess = 100;

            //Some environments provide better or more accurate numbers for available memory than
            //others. Just in case, we go through and allocate the largest contiguious block of
            //memory that is available to see what the actual upper bound is for what we can
            //use

            //The resolution is the smallest chunk of memory that we care about. We won't bother
            //trying to add resolution more bytes if we couldn't add resolution * 2 bytes.
            int resolution = 10000;

            while (true)
            {
                System.GC.Collect();
                try
                {
                    int     newAmount = lastSuccess + chunk;
                    sbyte[] allocated = new sbyte[newAmount];
                    lastSuccess = newAmount;
                    //If we succeeded, keep trying a larger piece.
                    chunk = chunk * 10;
                }
                catch (System.OutOfMemoryException oom)
                {
                    chunk = chunk / 2;
                    if (chunk < resolution)
                    {
                        break;
                    }
                }
            }


            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            int availPercent = (int)System.Math.Floor((lastSuccess * 1.0 / total) * 100);
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            int fragmentation = (int)System.Math.Floor((lastSuccess * 1.0 / free) * 100);

            System.Console.Out.WriteLine("Usable Memory: " + lastSuccess + "\n" + availPercent + "% of available memory");
            System.Console.Out.WriteLine("Fragmentation: " + fragmentation + "%");

            if (pause != -1)
            {
                try
                {
                    //UPGRADE_TODO: Method 'java.lang.Thread.sleep' was converted to 'System.Threading.Thread.Sleep' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangThreadsleep_long'"
                    System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * pause));
                }
                catch (System.Threading.ThreadInterruptedException e)
                {
                    // TODO Auto-generated catch block
                    SupportClass.WriteStackTrace(e, Console.Error);
                }
            }
        }