static void OnTimerCallback(object state)
    {
        if (System.Threading.Interlocked.CompareExchange(ref lockTimerCounter, 1, 0) == 0)
        {
            if (pcReqsPerSec == null)
            {
                pcReqsPerSec = new System.Diagnostics.PerformanceCounter("W3SVC_W3WP", "Requests / Sec", "_Total", true);
            }

            if (pcReqsPerSec != null)
            {
                try
                {
                    lock (threadLock)
                    {
                        CurrentRequestsPerSecondValue = Convert.ToDecimal(pcReqsPerSec.NextValue().ToString("N2"));
                    }
                }
                catch (Exception) {
                    // We had problem, just get rid of the performance counter and we'll rebuild it next revision
                    if (pcReqsPerSec != null)
                    {
                        pcReqsPerSec.Close();
                        pcReqsPerSec.Dispose();
                        pcReqsPerSec = null;
                    }
                }
            }

            stateCounter++;

            //Check every 5 seconds or so if anybody is still monitoring the server PerformanceCounter, if not shut down our PerformanceCounter
            if (stateCounter % 5 == 0)
            {
                if (System.Environment.TickCount - LastRequestTicks > 5000)
                {
                    Console.WriteLine("Stopping Poll Timer");

                    pollingTimer.Dispose();
                    pollingTimer = null;

                    if (pcReqsPerSec != null)
                    {
                        pcReqsPerSec.Close();
                        pcReqsPerSec.Dispose();
                        pcReqsPerSec = null;
                    }
                }
            }

            System.Threading.Interlocked.Add(ref lockTimerCounter, -1);
        }
    }
Exemplo n.º 2
0
        private int __available() //MB単位
        {
            if (NWEnviroment.isWindows())
            {
                string mem      = "Memory";
                string countMem = "Available Mbytes";
                System.Diagnostics.PerformanceCounter pcMem = new System.Diagnostics.PerformanceCounter(mem, countMem);
                float available = pcMem.NextValue();
                pcMem.Close();
                pcMem.Dispose();
                return((int)available);
            }
            else
            {
                string free = LinuxCommand.execute("free -m");
                using (StringReader sr = new StringReader(free)){
                    string line = "";
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line.Contains("-/+"))
                        {
                            string[] parts     = Regex.Split(line, @"\s+");
                            int      available = int.Parse(parts[parts.Length - 1]);
                            sr.Close();
                            sr.Dispose();
                            return(available);
//                            Console.WriteLine("rate:{0}",(int)(100*int.Parse(parts[2])/(int.Parse(parts[3])+int.Parse(parts[2]))));
                        }
                    }
                }
            }
            return(0);//TODO: Exception?
        }
        public static System.Data.DataTable GetFileSystemCacheBytes()
        {
            System.Data.DataTable tableReturn = new System.Data.DataTable();
            tableReturn.Columns.Add("Cache Bytes", typeof(long));
            tableReturn.Columns.Add("Cache GB", typeof(decimal));
            tableReturn.Columns.Add("Cache Bytes Peak", typeof(long));
            tableReturn.Columns.Add("Cache GB Peak", typeof(decimal));
            tableReturn.Columns.Add("Standby Cache Bytes", typeof(long));
            tableReturn.Columns.Add("Standby Cache GB", typeof(decimal));

            System.Diagnostics.PerformanceCounter pcCacheBytes     = new System.Diagnostics.PerformanceCounter("Memory", "Cache Bytes", true);
            System.Diagnostics.PerformanceCounter pcCacheBytesPeak = new System.Diagnostics.PerformanceCounter("Memory", "Cache Bytes Peak", true);

            float fltCacheBytes     = pcCacheBytes.NextValue();
            float fltCacheBytesPeak = pcCacheBytesPeak.NextValue();

            float?fltStandbyCacheBytes = null;

            try
            {
                System.Diagnostics.PerformanceCounter pcStandbyCacheBytes = new System.Diagnostics.PerformanceCounter("Memory", "Standby Cache Normal Priority Bytes", true);
                fltStandbyCacheBytes = pcStandbyCacheBytes.NextValue();
                pcStandbyCacheBytes.Close();
            }
            catch
            {
            }

            pcCacheBytes.Close();
            pcCacheBytesPeak.Close();

            object[] row = new object[]
            {
                (long)fltCacheBytes,
                decimal.Round((decimal)(fltCacheBytes / 1024 / 1024 / 1024), 2),
                (long)fltCacheBytesPeak,
                decimal.Round((decimal)(fltCacheBytesPeak / 1024 / 1024 / 1024), 2),
                fltStandbyCacheBytes == null ? null : fltStandbyCacheBytes,
                (fltStandbyCacheBytes == null ? (decimal?)null : (decimal?)decimal.Round((decimal)(fltStandbyCacheBytes / 1024 / 1024 / 1024), 2))
            };

            tableReturn.Rows.Add(row);
            return(tableReturn);
        }
        public static System.Data.DataTable GetFileSystemCacheBytes()
        {
            System.Data.DataTable tableReturn = new System.Data.DataTable();
            tableReturn.Columns.Add("Cache Bytes", typeof(long));
            tableReturn.Columns.Add("Cache GB", typeof(decimal));
            tableReturn.Columns.Add("Cache Bytes Peak", typeof(long));
            tableReturn.Columns.Add("Cache GB Peak", typeof(decimal));
            tableReturn.Columns.Add("Standby Cache Bytes", typeof(long));
            tableReturn.Columns.Add("Standby Cache GB", typeof(decimal));

            System.Diagnostics.PerformanceCounter pcCacheBytes = new System.Diagnostics.PerformanceCounter("Memory", "Cache Bytes", true);
            System.Diagnostics.PerformanceCounter pcCacheBytesPeak = new System.Diagnostics.PerformanceCounter("Memory", "Cache Bytes Peak", true);

            float fltCacheBytes = pcCacheBytes.NextValue();
            float fltCacheBytesPeak = pcCacheBytesPeak.NextValue();

            float? fltStandbyCacheBytes = null;

            try
            {
                System.Diagnostics.PerformanceCounter pcStandbyCacheBytes = new System.Diagnostics.PerformanceCounter("Memory", "Standby Cache Normal Priority Bytes", true);
                fltStandbyCacheBytes = pcStandbyCacheBytes.NextValue();
                pcStandbyCacheBytes.Close();
            }
            catch { }

            pcCacheBytes.Close();
            pcCacheBytesPeak.Close();

            object[] row = new object[] { 
                (long)fltCacheBytes, 
                decimal.Round((decimal)(fltCacheBytes / 1024 / 1024 / 1024), 2), 
                (long)fltCacheBytesPeak, 
                decimal.Round((decimal)(fltCacheBytesPeak / 1024 / 1024 / 1024), 2), 
                (fltStandbyCacheBytes==null?null:fltStandbyCacheBytes), 
                (fltStandbyCacheBytes==null?(decimal?)null:(decimal?)decimal.Round((decimal)(fltStandbyCacheBytes / 1024 / 1024 / 1024), 2))
            };

            tableReturn.Rows.Add(row);
            return tableReturn;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Render the waveform graphically then display it. Return the background worker doing the job.
        /// </summary>
        public BackgroundWorker Render()
        {
            if (mBlock != null && mBlock.Node != null && mBlock.Node.IsRooted)
            {
                if (mNeedsRendering)
                {
                    mNeedsRendering = false;
                    if (mBlock != null && Width > 0 && Height > 0)
                    {
                        BackgroundWorker worker = new BackgroundWorker();

                        worker.WorkerReportsProgress      = false;
                        worker.WorkerSupportsCancellation = false;
                        worker.DoWork += new DoWorkEventHandler(delegate(object sender, DoWorkEventArgs e)
                        {
                            if (!mBlock.ShowWaveform)
                            {
                                return;
                            }
                            m_IsRenderingWaveform  = true;
                            ColorSettings settings = mBlock.ColorSettings;

                            if (mBlock.Strip.ContentView.Settings != null &&
                                mBlock.Strip.ContentView.Settings.Project_OptimizeMemory)
                            {
                                System.Diagnostics.PerformanceCounter ramPerformanceCounter = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes");
                                if (ramPerformanceCounter.NextValue() < 100)
                                {
                                    //Console.WriteLine("RAM near overload " + ramPerformanceCounter.NextValue().ToString());


                                    System.GC.GetTotalMemory(true);

                                    System.GC.WaitForFullGCComplete(500);

                                    float availableRAM = ramPerformanceCounter.NextValue();
                                    Console.WriteLine("RAM after collection " + availableRAM.ToString());
                                }
                                ramPerformanceCounter.Close();
                            }
                            m_CancelRendering = false;
                            mBitmap           = CreateBitmap(mBlock.ColorSettings, false);
                            if (mBitmap == null)
                            {
                                System.Threading.Thread.Sleep(1000);
                                mBitmap = CreateBitmap(mBlock.ColorSettings, false);
                            }
                            if (mBitmap != null)
                            {
                                mBitmap_Highlighted = CreateBitmap(mBlock.ColorSettings, true);
                            }
                            m_IsRenderingWaveform = false;
                        });
                        worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(delegate(object sender, RunWorkerCompletedEventArgs e)
                        {
                            Invalidate();
                            mBlock.ContentView.FinishedRendering(this, mBitmap != null && mBitmap_Highlighted != null);
                        });
                        worker.RunWorkerAsync();
                        return(worker);
                    }
                }
                return(null);
            }
            else
            {
                if (mBitmap != null)
                {
                    mBitmap.Dispose();
                    mBitmap = null;
                }
                if (mBitmap_Highlighted != null)
                {
                    mBitmap_Highlighted.Dispose();
                    mBitmap_Highlighted = null;
                }
                return(null);
            }
        }
Exemplo n.º 6
0
        public void MainFunction()
        {
            IEnumerable <string> files;
            int       count            = 0;
            const int leftoverMemoryMB = 9000;

            files = Directory.EnumerateFiles(Compare.workingDirectory);

            Application.Current.Dispatcher.Invoke((Action) delegate
            {
                ProgressBar.Text = "Progress: 0/" + files.Count();
            }, System.Windows.Threading.DispatcherPriority.Background);

            //int memoryUsage;
            List <Match> matches = new List <Match>();

            count = 0;
            for (int i = 1; i < files.Count(); i++)
            {
                int j = files.Count() - i;
                count += j;
            }

            System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess();

            int memsize = 0; // memsize in MB

            System.Diagnostics.PerformanceCounter PC = new System.Diagnostics.PerformanceCounter
            {
                CategoryName = "Process",
                CounterName  = "Working Set - Private",
                InstanceName = proc.ProcessName
            };
            memsize = Convert.ToInt32(PC.NextValue()) / (int)(1048576);

            DateTime dt1 = DateTime.Now;

            Task <List <Match> >[] taskArray = new Task <List <Match> > [files.Count()];
            for (int i = 0; i < taskArray.Count(); i++)
            {
                ulong availableMemory = new Microsoft.VisualBasic.Devices.ComputerInfo().AvailablePhysicalMemory / 1048576; // memsize in MB
                while (availableMemory <= leftoverMemoryMB)
                {
                    Thread.Sleep(100);
                    availableMemory = new Microsoft.VisualBasic.Devices.ComputerInfo().AvailablePhysicalMemory / 1048576; // memsize in MB
                }

                var newArray = files.ToList().GetRange(i, files.Count() - i);
                taskArray[i] = Task <List <Match> > .Factory.StartNew(() => Compare.Comparerer(newArray, 16));

                Thread.Sleep(50);
            }

            List <int> ignore = new List <int>();

            while (!taskArray.Last().IsCompleted)
            {
                for (int i = 0; i < taskArray.Count(); i++)
                {
                    if (!ignore.Contains(i) && taskArray[i].IsCompleted)
                    {
                        for (int j = 0; j < taskArray[i].Result.Count; j++)
                        {
                            //Causes the UI thread to throw an exeption
                            //MatchingFiles.Add(new Files(taskArray[i].Result[j].FileName1, taskArray[i].Result[j].FileName2));

                            //Tells the UI thread (dispatcher) to do something to the UI
                            Application.Current.Dispatcher.Invoke((Action) delegate
                            {
                                MatchingFiles.Add(new Files(taskArray[i].Result[j].FileName1, taskArray[i].Result[j].FileName2));
                            }, System.Windows.Threading.DispatcherPriority.Loaded);
                        }
                        ignore.Add(i);
                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            ProgressBar.Text = "Progress: " + ignore.Count + "/" + files.Count();
                        }, System.Windows.Threading.DispatcherPriority.Loaded);
                    }
                }
                Task.WaitAll(taskArray, 100);
            }

            Task.WaitAll(taskArray);
            Application.Current.Dispatcher.Invoke((Action) delegate
            {
                ProgressBar.Text = "Progress: " + taskArray.Count() + "/" + files.Count();
            }, System.Windows.Threading.DispatcherPriority.Background);

            PC.Close();
            PC.Dispose();

            for (int i = 0; i < taskArray.Length; i++)
            {
                matches.AddRange(taskArray[i].Result);
                taskArray[i].Dispose();
            }

            matches.Sort();
            foreach (Match item in matches)
            {
                File.AppendAllText(Compare.outputDirectory + "\\" + Compare.workingDirectory.Substring(Compare.workingDirectory.LastIndexOf('\\') + 1) + ".txt", "Files " + item.FileName1 + " and " + item.FileName2 + " are " + item.EqualElements.ToString("P") + " equal" + Environment.NewLine);
                if (item.MarkForDeletion && deleteMode)
                {
                    Compare.Delete(item);
                }
            }

            TimeSpan timeSpan = DateTime.Now - dt1;

            Application.Current.Dispatcher.Invoke((Action) delegate
            {
                MatchingFiles.Add(new Files("Done", "Execution time: " + timeSpan.TotalMinutes.ToString("#.##") + " min"));
            });

            return;
        }
Exemplo n.º 7
0
 private int __available()
 {
     //MB単位
     if(NWEnviroment.isWindows()){
         string mem = "Memory";
         string countMem = "Available Mbytes";
         System.Diagnostics.PerformanceCounter pcMem = new System.Diagnostics.PerformanceCounter(mem,countMem);
         float available = pcMem.NextValue();
         pcMem.Close();
         pcMem.Dispose();
         return (int)available;
     }else{
         string free =LinuxCommand.execute("free -m");
         using(StringReader sr = new StringReader(free)){
             string line = "";
             while((line=sr.ReadLine())!=null){
                 if(line.Contains("-/+")){
                     string[] parts = Regex.Split(line,@"\s+");
                     int available = int.Parse(parts[parts.Length-1]);
                     sr.Close();
                     sr.Dispose();
                     return available;
     //                            Console.WriteLine("rate:{0}",(int)(100*int.Parse(parts[2])/(int.Parse(parts[3])+int.Parse(parts[2]))));
                 }
             }
         }
     }
     return 0;//TODO: Exception?
 }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            IEnumerable <string> files;
            int count = 0;

            if (args.Count() >= 1)
            {
                if (args.Contains("-h"))
                {
                    Console.WriteLine("Usage: ImageComparison [Input path] [Output path] -d -h --debug\n" +
                                      "\nOptions:" +
                                      "\n\t-d\t\tDeletes matches" +
                                      "\n\t-h\t\tDisplays the help" +
                                      "\n\t--debug\t\tEnables debug mode");
                    return;
                }
                if (args.Contains("-d"))
                {
                    deleteMode = true;
                }
                if (args.Count() == 2 && !args.Contains("--debug"))
                {
                    workingDirectory = args[0];
                    outputDirectory  = args[1];

                    if (workingDirectory.Last() == '\\')
                    {
                        workingDirectory.Remove(workingDirectory.Count(), 1);
                    }
                    if (outputDirectory.Last() == '\\')
                    {
                        outputDirectory.Remove(outputDirectory.Count(), 1);
                    }
                }
                else if (args.Count() == 1)
                {
                    workingDirectory = args[0];
                }
            }

            Compare.workingDirectory = workingDirectory;
            Compare.outputDirectory  = outputDirectory;

            files = Directory.EnumerateFiles(workingDirectory);
            //int memoryUsage;
            List <Match> matches = new List <Match>();

            count = 0;
            for (int i = 1; i < files.Count(); i++)
            {
                int j = files.Count() - i;
                count += j;
            }

            System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess();

            int memsize = 0; // memsize in MB

            System.Diagnostics.PerformanceCounter PC = new System.Diagnostics.PerformanceCounter
            {
                CategoryName = "Process",
                CounterName  = "Working Set - Private",
                InstanceName = proc.ProcessName
            };
            memsize = Convert.ToInt32(PC.NextValue()) / (int)(1048576);

            DateTime tt1 = DateTime.Now;

            Task <List <Match> >[] taskArray = new Task <List <Match> > [files.Count()];
            for (int i = 0; i < taskArray.Count(); i++)
            {
                ulong availableMemory = new Microsoft.VisualBasic.Devices.ComputerInfo().AvailablePhysicalMemory / 1048576; // memsize in MB
                while (availableMemory <= leftoverMemoryMB)
                {
                    Thread.Sleep(100);
                    availableMemory = new Microsoft.VisualBasic.Devices.ComputerInfo().AvailablePhysicalMemory / 1048576; // memsize in MB
                }

                var newArray = files.ToList().GetRange(i, files.Count() - i);
                taskArray[i] = Task <List <Match> > .Factory.StartNew(() => Compare.Comparerer(newArray, 16));

                Thread.Sleep(50);
            }

            List <int> ignore = new List <int>();

            while (!taskArray.Last().IsCompleted)
            {
                for (int i = 0; i < taskArray.Count(); i++)
                {
                    if (!ignore.Contains(i) && taskArray[i].IsCompleted)
                    {
                        for (int j = 0; j < taskArray[i].Result.Count; j++)
                        {
                            Console.WriteLine("Files {0} and {1} are equal", taskArray[i].Result[j].FileName1, taskArray[i].Result[j].FileName2);
                        }
                        ignore.Add(i);
                    }
                }
                Task.WaitAll(taskArray, 5000);
            }

            Task.WaitAll(taskArray);
            PC.Close();
            PC.Dispose();

            for (int i = 0; i < taskArray.Length; i++)
            {
                matches.AddRange(taskArray[i].Result);
                taskArray[i].Dispose();
            }

            matches.Sort();
            foreach (Match item in matches)
            {
                File.AppendAllText(outputDirectory + "\\" + workingDirectory.Substring(workingDirectory.LastIndexOf('\\') + 1) + ".txt", "Files " + item.FileName1 + " and " + item.FileName2 + " are " + item.EqualElements.ToString("P") + " equal" + Environment.NewLine);
                if (item.MarkForDeletion && deleteMode)
                {
                    Compare.Delete(item);
                }
            }

            DateTime tt2       = DateTime.Now;
            TimeSpan ttimeSpan = tt2 - tt1;

            Console.WriteLine("Execution time: {0} sec", (ttimeSpan.TotalSeconds).ToString("N2"));

            Console.Write("\nDone.");
            Console.ReadLine();
            return;
        }