Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Misc/ILPerformanceCounterThreadPool.cs @ 12547

Last change on this file since 12547 was 9102, checked in by gkronber, 12 years ago

#1967: ILNumerics source for experimentation

File size: 5.4 KB
Line 
1///
2///    This file is part of ILNumerics Community Edition.
3///
4///    ILNumerics Community Edition - high performance computing for applications.
5///    Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
6///
7///    ILNumerics Community Edition is free software: you can redistribute it and/or modify
8///    it under the terms of the GNU General Public License version 3 as published by
9///    the Free Software Foundation.
10///
11///    ILNumerics Community Edition is distributed in the hope that it will be useful,
12///    but WITHOUT ANY WARRANTY; without even the implied warranty of
13///    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14///    GNU General Public License for more details.
15///
16///    You should have received a copy of the GNU General Public License
17///    along with ILNumerics Community Edition. See the file License.txt in the root
18///    of your distribution package. If not, see <http://www.gnu.org/licenses/>.
19///
20///    In addition this software uses the following components and/or licenses:
21///
22///    =================================================================================
23///    The Open Toolkit Library License
24///   
25///    Copyright (c) 2006 - 2009 the Open Toolkit library.
26///   
27///    Permission is hereby granted, free of charge, to any person obtaining a copy
28///    of this software and associated documentation files (the "Software"), to deal
29///    in the Software without restriction, including without limitation the rights to
30///    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
31///    the Software, and to permit persons to whom the Software is furnished to do
32///    so, subject to the following conditions:
33///
34///    The above copyright notice and this permission notice shall be included in all
35///    copies or substantial portions of the Software.
36///
37///    =================================================================================
38///   
39
40using System;
41using System.Collections.Generic;
42using System.Linq;
43using System.Text;
44using System.Diagnostics;
45
46namespace ILNumerics.Misc {
47
48    internal partial class ILThreadPool  {
49        internal class ILPerformanceCounter {
50            // some constants (may get localized)
51            private static readonly string PERFORMANCECOUNTER_CATEGORY_NAME = "ILNumerics Thread Pool";
52            private static readonly string PERFORMANCECOUNTER_CATEGORY_NAME_HELP = "Monitors treading related data.";
53            private static readonly string PERFORMANCECOUNTER_CURRENT_NUMBER_THREADS = "Number of worker threads";
54            private static readonly string PERFORMANCECOUNTER_CURRENT_NUMBER_THREADS_HELP = "Number of threads currently active for parallel operations.";
55            private static readonly string PERFORMANCECOUNTER_TIME_WAITING_FOR_THREADS = "Time waited for other threads";
56            private static readonly string PERFORMANCECOUNTER_TIME_WAITING_FOR_THREADS_HELP = "Timespan in milliseconds, which the main thread was waiting for worker threads to finish the last operation.";
57           
58            private bool m_countingActive = false;
59            public PerformanceCounter m_PCcurThreadsCount;
60            public PerformanceCounter m_PCwait4Threads;
61
62            public ILPerformanceCounter() {
63                if (!Settings.s_measurePerformanceAtRuntime) return;
64                // check if the category is installed
65                if (!PerformanceCounterCategory.Exists(PERFORMANCECOUNTER_CATEGORY_NAME)) {
66                    // even if we handle to install the category, the counters will be
67                    // not available immediately. So we disable them for this session.
68                    m_countingActive = false;
69                    try {
70                        // try to install
71                        CounterCreationDataCollection ccdc = new CounterCreationDataCollection();
72                        ccdc.Add(new CounterCreationData(PERFORMANCECOUNTER_CURRENT_NUMBER_THREADS, PERFORMANCECOUNTER_CURRENT_NUMBER_THREADS_HELP, PerformanceCounterType.NumberOfItems32));
73                        ccdc.Add(new CounterCreationData(PERFORMANCECOUNTER_TIME_WAITING_FOR_THREADS, PERFORMANCECOUNTER_TIME_WAITING_FOR_THREADS_HELP, PerformanceCounterType.NumberOfItems64));
74                       
75                        PerformanceCounterCategory.Create(PERFORMANCECOUNTER_CATEGORY_NAME, PERFORMANCECOUNTER_CATEGORY_NAME_HELP
76                                                        ,PerformanceCounterCategoryType.SingleInstance,ccdc);
77                    } catch (System.Security.SecurityException) { }
78                }
79                m_countingActive = true;
80                m_PCcurThreadsCount = new PerformanceCounter(PERFORMANCECOUNTER_CATEGORY_NAME, PERFORMANCECOUNTER_CURRENT_NUMBER_THREADS, false);
81                m_PCwait4Threads = new PerformanceCounter(PERFORMANCECOUNTER_CATEGORY_NAME, PERFORMANCECOUNTER_TIME_WAITING_FOR_THREADS, false);
82
83                m_PCcurThreadsCount.RawValue = 0;
84                m_PCwait4Threads.RawValue = 0;
85
86            }
87            public void PCcurNumberThreadsSet(int val) {
88                if (m_PCcurThreadsCount != null)
89                    m_PCcurThreadsCount.RawValue = val;
90            }
91            public void PCwaited4ThreadsSet(long value) {
92                if (m_PCwait4Threads != null)
93                    m_PCwait4Threads.RawValue = value;
94            }
95        }
96    }
97}
98
Note: See TracBrowser for help on using the repository browser.