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.
5 #include "content/common/gpu/client/command_buffer_metrics.h"
7 #include "base/metrics/histogram.h"
13 enum CommandBufferContextLostReason
{
14 // Don't add new values here.
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
,
23 CONTEXT_LOST_INNOCENT
,
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
31 CommandBufferContextLostReason
GetContextLostReason(
32 gpu::error::Error error
,
33 gpu::error::ContextLostReason reason
) {
34 if (error
== gpu::error::kLostContext
) {
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 case gpu::error::kGpuChannelLost
:
47 return CONTEXT_LOST_GPU_CHANNEL_ERROR
;
51 case gpu::error::kInvalidSize
:
52 return CONTEXT_PARSE_ERROR_INVALID_SIZE
;
53 case gpu::error::kOutOfBounds
:
54 return CONTEXT_PARSE_ERROR_OUT_OF_BOUNDS
;
55 case gpu::error::kUnknownCommand
:
56 return CONTEXT_PARSE_ERROR_UNKNOWN_COMMAND
;
57 case gpu::error::kInvalidArguments
:
58 return CONTEXT_PARSE_ERROR_INVALID_ARGS
;
59 case gpu::error::kGenericError
:
60 return CONTEXT_PARSE_ERROR_GENERIC_ERROR
;
61 case gpu::error::kDeferCommandUntilLater
:
62 case gpu::error::kNoError
:
63 case gpu::error::kLostContext
:
65 return CONTEXT_LOST_UNKNOWN
;
68 return CONTEXT_LOST_UNKNOWN
;
71 void RecordContextLost(CommandBufferContextType type
,
72 CommandBufferContextLostReason reason
) {
74 case BROWSER_COMPOSITOR_ONSCREEN_CONTEXT
:
75 UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.BrowserCompositor", reason
,
76 CONTEXT_LOST_REASON_MAX_ENUM
);
78 case BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT
:
79 UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.BrowserMainThread", reason
,
80 CONTEXT_LOST_REASON_MAX_ENUM
);
82 case RENDER_COMPOSITOR_CONTEXT
:
83 UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.RenderCompositor", reason
,
84 CONTEXT_LOST_REASON_MAX_ENUM
);
86 case RENDER_WORKER_CONTEXT
:
87 UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.RenderWorker", reason
,
88 CONTEXT_LOST_REASON_MAX_ENUM
);
90 case RENDERER_MAINTHREAD_CONTEXT
:
91 UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.RenderMainThread", reason
,
92 CONTEXT_LOST_REASON_MAX_ENUM
);
94 case GPU_VIDEO_ACCELERATOR_CONTEXT
:
95 UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.VideoAccelerator", reason
,
96 CONTEXT_LOST_REASON_MAX_ENUM
);
98 case OFFSCREEN_VIDEO_CAPTURE_CONTEXT
:
99 UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.VideoCapture", reason
,
100 CONTEXT_LOST_REASON_MAX_ENUM
);
102 case OFFSCREEN_CONTEXT_FOR_WEBGL
:
103 UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.WebGL", reason
,
104 CONTEXT_LOST_REASON_MAX_ENUM
);
106 case CONTEXT_TYPE_UNKNOWN
:
107 UMA_HISTOGRAM_ENUMERATION("GPU.ContextLost.Unknown", reason
,
108 CONTEXT_LOST_REASON_MAX_ENUM
);
113 } // anonymous namespace
115 std::string
CommandBufferContextTypeToString(CommandBufferContextType type
) {
117 case OFFSCREEN_CONTEXT_FOR_TESTING
:
118 return "Context-For-Testing";
119 case BROWSER_COMPOSITOR_ONSCREEN_CONTEXT
:
121 case BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT
:
122 return "Offscreen-MainThread";
123 case RENDER_COMPOSITOR_CONTEXT
:
124 return "RenderCompositor";
125 case RENDER_WORKER_CONTEXT
:
126 return "RenderWorker";
127 case RENDERER_MAINTHREAD_CONTEXT
:
128 return "Offscreen-MainThread";
129 case GPU_VIDEO_ACCELERATOR_CONTEXT
:
130 return "GPU-VideoAccelerator-Offscreen";
131 case OFFSCREEN_VIDEO_CAPTURE_CONTEXT
:
132 return "Offscreen-CaptureThread";
133 case OFFSCREEN_CONTEXT_FOR_WEBGL
:
134 return "Offscreen-For-WebGL";
141 void UmaRecordContextInitFailed(CommandBufferContextType type
) {
142 RecordContextLost(type
, CONTEXT_INIT_FAILED
);
145 void UmaRecordContextLost(CommandBufferContextType type
,
146 gpu::error::Error error
,
147 gpu::error::ContextLostReason reason
) {
148 CommandBufferContextLostReason converted_reason
=
149 GetContextLostReason(error
, reason
);
150 RecordContextLost(type
, converted_reason
);
153 } // namespace content