1
|
/*
|
2
|
Copyright (c) 2003-2006 Niels Kokholm and Peter Sestoft
|
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
of this software and associated documentation files (the "Software"), to deal
|
5
|
in the Software without restriction, including without limitation the rights
|
6
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
copies of the Software, and to permit persons to whom the Software is
|
8
|
furnished to do so, subject to the following conditions:
|
9
|
|
10
|
The above copyright notice and this permission notice shall be included in
|
11
|
all copies or substantial portions of the Software.
|
12
|
|
13
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
SOFTWARE.
|
20
|
*/
|
21
|
|
22
|
using System;
|
23
|
using System.IO;
|
24
|
using System.Reflection;
|
25
|
using System.Xml;
|
26
|
using System.Diagnostics;
|
27
|
|
28
|
namespace DocNet
|
29
|
{
|
30
|
class Timer
|
31
|
{
|
32
|
static System.Diagnostics.Process p;
|
33
|
|
34
|
static long sws;
|
35
|
|
36
|
static long svm;
|
37
|
|
38
|
static double stt;
|
39
|
|
40
|
static DateTime swc;
|
41
|
|
42
|
public long ws;
|
43
|
|
44
|
public long vm;
|
45
|
|
46
|
public double tt;
|
47
|
|
48
|
public DateTime wc;
|
49
|
|
50
|
public double deltat;
|
51
|
|
52
|
public double deltac;
|
53
|
|
54
|
|
55
|
public Timer()
|
56
|
{
|
57
|
if (p == null)
|
58
|
{
|
59
|
p = System.Diagnostics.Process.GetCurrentProcess();
|
60
|
stt = p.TotalProcessorTime.TotalMilliseconds;
|
61
|
sws = p.WorkingSet64;
|
62
|
svm = p.VirtualMemorySize64;
|
63
|
swc = DateTime.Now;
|
64
|
}
|
65
|
}
|
66
|
|
67
|
|
68
|
public double snap()
|
69
|
{
|
70
|
double oldt = tt;
|
71
|
DateTime oldc = wc; p.Refresh();
|
72
|
tt = p.TotalProcessorTime.TotalMilliseconds - stt;
|
73
|
deltat = tt - oldt;
|
74
|
ws = p.WorkingSet64 - sws;
|
75
|
vm = p.VirtualMemorySize64 - svm;
|
76
|
wc = DateTime.Now;
|
77
|
|
78
|
TimeSpan x = oldc.Subtract(wc);
|
79
|
|
80
|
deltac = -x.TotalMilliseconds;
|
81
|
return deltac;
|
82
|
}
|
83
|
}
|
84
|
}
|