Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
fdf45ab6
Commit
fdf45ab6
authored
8 years ago
by
Jan Tattermusch
Browse files
Options
Downloads
Patches
Plain Diff
support threadpool tracing
parent
aaefa958
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/csharp/Grpc.Core/Internal/GrpcThreadPool.cs
+18
-4
18 additions, 4 deletions
src/csharp/Grpc.Core/Internal/GrpcThreadPool.cs
with
18 additions
and
4 deletions
src/csharp/Grpc.Core/Internal/GrpcThreadPool.cs
+
18
−
4
View file @
fdf45ab6
...
@@ -37,6 +37,7 @@ using System.Linq;
...
@@ -37,6 +37,7 @@ using System.Linq;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Grpc.Core.Logging
;
using
Grpc.Core.Logging
;
using
Grpc.Core.Profiling
;
using
Grpc.Core.Utils
;
using
Grpc.Core.Utils
;
namespace
Grpc.Core.Internal
namespace
Grpc.Core.Internal
...
@@ -54,6 +55,8 @@ namespace Grpc.Core.Internal
...
@@ -54,6 +55,8 @@ namespace Grpc.Core.Internal
readonly
int
poolSize
;
readonly
int
poolSize
;
readonly
int
completionQueueCount
;
readonly
int
completionQueueCount
;
readonly
List
<
BasicProfiler
>
threadProfilers
=
new
List
<
BasicProfiler
>();
// profilers assigned to threadpool threads
bool
stopRequested
;
bool
stopRequested
;
IReadOnlyCollection
<
CompletionQueueSafeHandle
>
completionQueues
;
IReadOnlyCollection
<
CompletionQueueSafeHandle
>
completionQueues
;
...
@@ -82,7 +85,8 @@ namespace Grpc.Core.Internal
...
@@ -82,7 +85,8 @@ namespace Grpc.Core.Internal
for
(
int
i
=
0
;
i
<
poolSize
;
i
++)
for
(
int
i
=
0
;
i
<
poolSize
;
i
++)
{
{
threads
.
Add
(
CreateAndStartThread
(
i
));
var
optionalProfiler
=
i
<
threadProfilers
.
Count
?
threadProfilers
[
i
]
:
null
;
threads
.
Add
(
CreateAndStartThread
(
i
,
optionalProfiler
));
}
}
}
}
}
}
...
@@ -111,6 +115,11 @@ namespace Grpc.Core.Internal
...
@@ -111,6 +115,11 @@ namespace Grpc.Core.Internal
{
{
cq
.
Dispose
();
cq
.
Dispose
();
}
}
for
(
int
i
=
0
;
i
<
threadProfilers
.
Count
;
i
++)
{
threadProfilers
[
i
].
Dump
(
string
.
Format
(
"grpc_trace_thread_{0}.txt"
,
i
));
}
});
});
}
}
...
@@ -137,12 +146,12 @@ namespace Grpc.Core.Internal
...
@@ -137,12 +146,12 @@ namespace Grpc.Core.Internal
}
}
}
}
private
Thread
CreateAndStartThread
(
int
threadIndex
)
private
Thread
CreateAndStartThread
(
int
threadIndex
,
IProfiler
optionalProfiler
)
{
{
var
cqIndex
=
threadIndex
%
completionQueues
.
Count
;
var
cqIndex
=
threadIndex
%
completionQueues
.
Count
;
var
cq
=
completionQueues
.
ElementAt
(
cqIndex
);
var
cq
=
completionQueues
.
ElementAt
(
cqIndex
);
var
thread
=
new
Thread
(
new
ThreadStart
(()
=>
RunHandlerLoop
(
cq
)));
var
thread
=
new
Thread
(
new
ThreadStart
(()
=>
RunHandlerLoop
(
cq
,
optionalProfiler
)));
thread
.
IsBackground
=
true
;
thread
.
IsBackground
=
true
;
thread
.
Name
=
string
.
Format
(
"grpc {0} (cq {1})"
,
threadIndex
,
cqIndex
);
thread
.
Name
=
string
.
Format
(
"grpc {0} (cq {1})"
,
threadIndex
,
cqIndex
);
thread
.
Start
();
thread
.
Start
();
...
@@ -153,8 +162,13 @@ namespace Grpc.Core.Internal
...
@@ -153,8 +162,13 @@ namespace Grpc.Core.Internal
/// <summary>
/// <summary>
/// Body of the polling thread.
/// Body of the polling thread.
/// </summary>
/// </summary>
private
void
RunHandlerLoop
(
CompletionQueueSafeHandle
cq
)
private
void
RunHandlerLoop
(
CompletionQueueSafeHandle
cq
,
IProfiler
optionalProfiler
)
{
{
if
(
optionalProfiler
!=
null
)
{
Profilers
.
SetForCurrentThread
(
optionalProfiler
);
}
CompletionQueueEvent
ev
;
CompletionQueueEvent
ev
;
do
do
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment