OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/common/gpu/client/command_buffer_metrics.h" | |
6 | |
7 #include "base/metrics/histogram.h" | |
8 | |
9 namespace content { | |
10 | |
11 namespace { | |
12 | |
13 enum CommandBufferContextLostReason { | |
14 // Don't add new values here. | |
15 CONTEXT_INIT_FAILED, | |
16 CONTEXT_LOST_GPU_CHANNEL_ERROR, | |
17 CONTEXT_PARSE_ERROR_INVALID_SIZE, | |
18 CONTEXT_PARSE_ERROR_OUT_OF_BOUNDS, | |
19 CONTEXT_PARSE_ERROR_UNKNOWN_COMMAND, | |
20 CONTEXT_PARSE_ERROR_INVALID_ARGS, | |
21 CONTEXT_PARSE_ERROR_GENERIC_ERROR, | |
22 CONTEXT_LOST_GUILTY, | |
23 CONTEXT_LOST_INNOCENT, | |
24 CONTEXT_LOST_UNKNOWN, | |
25 CONTEXT_LOST_OUT_OF_MEMORY, | |
26 CONTEXT_LOST_MAKECURRENT_FAILED, | |
27 // Add new values here and update _MAX_ENUM. | |
28 CONTEXT_LOST_REASON_MAX_ENUM = CONTEXT_LOST_MAKECURRENT_FAILED | |
29 }; | |
30 | |
31 CommandBufferContextLostReason GetContextLostReason( | |
32 gpu::error::Error error, | |
33 gpu::error::ContextLostReason reason) { | |
34 if (error == gpu::error::kLostContext) { | |
35 switch (reason) { | |
36 case gpu::error::kGuilty: | |
37 return CONTEXT_LOST_GUILTY; | |
38 case gpu::error::kInnocent: | |
39 return CONTEXT_LOST_INNOCENT; | |
40 case gpu::error::kUnknown: | |
41 return CONTEXT_LOST_UNKNOWN; | |
42 case gpu::error::kOutOfMemory: | |
43 return CONTEXT_LOST_OUT_OF_MEMORY; | |
44 case gpu::error::kMakeCurrentFailed: | |
45 return CONTEXT_LOST_MAKECURRENT_FAILED; | |
46 } | |
47 } | |
48 switch (error) { | |
49 case gpu::error::kInvalidSize: | |
50 return CONTEXT_PARSE_ERROR_INVALID_SIZE; | |
51 case gpu::error::kOutOfBounds: | |
52 return CONTEXT_PARSE_ERROR_OUT_OF_BOUNDS; | |
53 case gpu::error::kUnknownCommand: | |
54 return CONTEXT_PARSE_ERROR_UNKNOWN_COMMAND; | |
55 case gpu::error::kInvalidArguments: | |
56 return CONTEXT_PARSE_ERROR_INVALID_ARGS; | |
57 case gpu::error::kGenericError: | |
58 return CONTEXT_PARSE_ERROR_GENERIC_ERROR; | |
59 case gpu::error::kDeferCommandUntilLater: | |
60 case gpu::error::kNoError: | |
61 case gpu::error::kLostContext: | |
62 NOTREACHED(); | |
63 return CONTEXT_LOST_UNKNOWN; | |
64 } | |
65 NOTREACHED(); | |
66 return CONTEXT_LOST_UNKNOWN; | |
67 } | |
68 | |
69 const char* GetHistogramName(CommandBufferContextType type) { | |
70 switch (type) { | |
71 case BROWSER_COMPOSITOR_ONSCREEN_CONTEXT: | |
72 return "GPU.ContextLost.BrowserCompositor"; | |
73 case BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT: | |
74 return "GPU.ContextLost.BrowserMainThread"; | |
75 case RENDER_COMPOSITOR_CONTEXT: | |
76 return "GPU.ContextLost.RenderCompositor"; | |
77 case RENDER_WORKER_CONTEXT: | |
78 return "GPU.ContextLost.RenderWorker"; | |
79 case RENDERER_MAINTHREAD_CONTEXT: | |
80 return "GPU.ContextLost.RenderMainThread"; | |
81 case GPU_VIDEO_ACCELERATOR_CONTEXT: | |
82 return "GPU.ContextLost.VideoAccelerator"; | |
83 case OFFSCREEN_VIDEO_CAPTURE_CONTEXT: | |
84 return "GPU.ContextLost.VideoCapture"; | |
85 case OFFSCREEN_CONTEXT_FOR_WEBGL: | |
86 return "GPU.ContextLost.WebGL"; | |
87 case CONTEXT_TYPE_UNKNOWN: | |
88 return "GPU.ContextLost.Unknown"; | |
89 } | |
90 } | |
91 | |
92 } // anonymous namespace | |
93 | |
94 std::string CommandBufferContextTypeToString(CommandBufferContextType type) { | |
95 switch (type) { | |
96 case OFFSCREEN_CONTEXT_FOR_TESTING: | |
97 return "Context-For-Testing"; | |
98 case BROWSER_COMPOSITOR_ONSCREEN_CONTEXT: | |
99 return "Compositor"; | |
100 case BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT: | |
101 return "Offscreen-MainThread"; | |
102 case RENDER_COMPOSITOR_CONTEXT: | |
103 return "RenderCompositor"; | |
104 case RENDER_WORKER_CONTEXT: | |
105 return "RenderWorker"; | |
106 case RENDERER_MAINTHREAD_CONTEXT: | |
107 return "Offscreen-MainThread"; | |
108 case GPU_VIDEO_ACCELERATOR_CONTEXT: | |
109 return "GPU-VideoAccelerator-Offscreen"; | |
110 case OFFSCREEN_VIDEO_CAPTURE_CONTEXT: | |
111 return "Offscreen-CaptureThread"; | |
112 case OFFSCREEN_CONTEXT_FOR_WEBGL: | |
113 return "Offscreen-For-WebGL"; | |
114 default: | |
115 NOTREACHED(); | |
116 return "unknown"; | |
117 } | |
118 } | |
119 | |
120 void UmaRecordContextInitFailed(CommandBufferContextType type) { | |
121 const char* histogram_name = GetHistogramName(type); | |
122 if (histogram_name) { | |
123 UMA_HISTOGRAM_ENUMERATION(histogram_name, CONTEXT_INIT_FAILED, | |
124 CONTEXT_LOST_REASON_MAX_ENUM); | |
Alexei Svitkine (slow)
2015/04/24 19:31:58
Unfortunately this won't work.
The UMA histogram
no sievers
2015/04/24 19:56:42
Thanks for catching that. Fixed.
| |
125 } | |
126 } | |
127 | |
128 void UmaRecordContextLost(CommandBufferContextType type, | |
129 gpu::error::Error error, | |
130 gpu::error::ContextLostReason reason) { | |
131 const char* histogram_name = GetHistogramName(type); | |
132 if (histogram_name) { | |
133 CommandBufferContextLostReason converted_reason = | |
134 GetContextLostReason(error, reason); | |
135 UMA_HISTOGRAM_ENUMERATION(histogram_name, converted_reason, | |
136 CONTEXT_LOST_REASON_MAX_ENUM); | |
137 } | |
138 } | |
139 | |
140 } // namespace content | |
OLD | NEW |