Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
c4623a83
Commit
c4623a83
authored
Aug 08, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DebuggingAids: Move PerfCounterHelper out on its own
parent
e4ff06f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
47 deletions
+52
-47
DebuggingAids.cs
StackExchange.Redis/StackExchange/Redis/DebuggingAids.cs
+0
-47
PerfCounterHelper.cs
StackExchange.Redis/StackExchange/Redis/PerfCounterHelper.cs
+52
-0
No files found.
StackExchange.Redis/StackExchange/Redis/DebuggingAids.cs
View file @
c4623a83
using
System
;
using
System.Diagnostics
;
using
System.Runtime.InteropServices
;
namespace
StackExchange.Redis
{
internal
static
class
PerfCounterHelper
{
private
static
readonly
object
staticLock
=
new
object
();
private
static
volatile
PerformanceCounter
_cpu
;
private
static
volatile
bool
_disabled
=
!
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
);
public
static
bool
TryGetSystemCPU
(
out
float
value
)
{
value
=
-
1
;
try
{
if
(!
_disabled
&&
_cpu
==
null
)
{
lock
(
staticLock
)
{
if
(
_cpu
==
null
)
{
_cpu
=
new
PerformanceCounter
(
"Processor"
,
"% Processor Time"
,
"_Total"
);
// First call always returns 0, so get that out of the way.
_cpu
.
NextValue
();
}
}
}
}
catch
(
UnauthorizedAccessException
)
{
// Some environments don't allow access to Performance Counters, so stop trying.
_disabled
=
true
;
}
catch
(
Exception
e
)
{
// this shouldn't happen, but just being safe...
Trace
.
WriteLine
(
e
);
}
if
(!
_disabled
&&
_cpu
!=
null
)
{
value
=
_cpu
.
NextValue
();
return
true
;
}
return
false
;
}
}
#if VERBOSE
partial
class
ConnectionMultiplexer
...
...
StackExchange.Redis/StackExchange/Redis/PerfCounterHelper.cs
0 → 100644
View file @
c4623a83
using
System
;
using
System.Diagnostics
;
using
System.Runtime.InteropServices
;
namespace
StackExchange.Redis
{
internal
static
class
PerfCounterHelper
{
private
static
readonly
object
staticLock
=
new
object
();
private
static
volatile
PerformanceCounter
_cpu
;
private
static
volatile
bool
_disabled
=
!
RuntimeInformation
.
IsOSPlatform
(
OSPlatform
.
Windows
);
public
static
bool
TryGetSystemCPU
(
out
float
value
)
{
value
=
-
1
;
try
{
if
(!
_disabled
&&
_cpu
==
null
)
{
lock
(
staticLock
)
{
if
(
_cpu
==
null
)
{
_cpu
=
new
PerformanceCounter
(
"Processor"
,
"% Processor Time"
,
"_Total"
);
// First call always returns 0, so get that out of the way.
_cpu
.
NextValue
();
}
}
}
}
catch
(
UnauthorizedAccessException
)
{
// Some environments don't allow access to Performance Counters, so stop trying.
_disabled
=
true
;
}
catch
(
Exception
e
)
{
// this shouldn't happen, but just being safe...
Trace
.
WriteLine
(
e
);
}
if
(!
_disabled
&&
_cpu
!=
null
)
{
value
=
_cpu
.
NextValue
();
return
true
;
}
return
false
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment