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 before _MAX_ENUM to keep the histogram consistent. |
| 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 above this point. |
| 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 } |
| 66 |
| 67 const char* GetHistogramName(CommandBufferContextType type) { |
| 68 switch (type) { |
| 69 case OFFSCREEN_CONTEXT_FOR_TESTING: |
| 70 return ""; |
| 71 case BROWSER_COMPOSITOR_ONSCREEN_CONTEXT: |
| 72 return "GPU.BrowserCompositorContextLost"; |
| 73 case BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT: |
| 74 return "GPU.BrowserMainThreadContextLost"; |
| 75 case RENDER_COMPOSITOR_CONTEXT: |
| 76 return "GPU.RenderCompositorContextLost"; |
| 77 case RENDER_WORKER_CONTEXT: |
| 78 return "GPU.RenderWorkerContextLost"; |
| 79 case RENDERER_MAINTHREAD_CONTEXT: |
| 80 return "GPU.RenderMainThreadContextLost"; |
| 81 case GPU_VIDEO_ACCELERATOR_CONTEXT: |
| 82 return "GPU.VideoAcceleratorContextLost"; |
| 83 case OFFSCREEN_VIDEO_CAPTURE_CONTEXT: |
| 84 return "GPU.VideoCaptureContextLost"; |
| 85 case OFFSCREEN_CONTEXT_FOR_WEBGL: |
| 86 return "GPU.WebGLContextLost"; |
| 87 case CONTEXT_TYPE_UNKNOWN: |
| 88 return "GPU.UnknownContextTypeLost"; |
| 89 default: |
| 90 NOTREACHED(); |
| 91 return ""; |
| 92 } |
| 93 } |
| 94 |
| 95 } // anonymous namespace |
| 96 |
| 97 std::string CommandBufferContextTypeToString(CommandBufferContextType type) { |
| 98 switch (type) { |
| 99 case OFFSCREEN_CONTEXT_FOR_TESTING: |
| 100 return "Context-For-Testing"; |
| 101 case BROWSER_COMPOSITOR_ONSCREEN_CONTEXT: |
| 102 return "Compositor"; |
| 103 case BROWSER_OFFSCREEN_MAINTHREAD_CONTEXT: |
| 104 return "Offscreen-MainThread"; |
| 105 case RENDER_COMPOSITOR_CONTEXT: |
| 106 return "RenderCompositor"; |
| 107 case RENDER_WORKER_CONTEXT: |
| 108 return "RenderWorker"; |
| 109 case RENDERER_MAINTHREAD_CONTEXT: |
| 110 return "Offscreen-MainThread"; |
| 111 case GPU_VIDEO_ACCELERATOR_CONTEXT: |
| 112 return "GPU-VideoAccelerator-Offscreen"; |
| 113 case OFFSCREEN_VIDEO_CAPTURE_CONTEXT: |
| 114 return "Offscreen-CaptureThread"; |
| 115 case OFFSCREEN_CONTEXT_FOR_WEBGL: |
| 116 return "Offscreen-For-WebGL"; |
| 117 default: |
| 118 NOTREACHED(); |
| 119 return "unknown"; |
| 120 } |
| 121 } |
| 122 |
| 123 void UmaRecordContextInitFailed(CommandBufferContextType type) { |
| 124 const char* histogram_name = GetHistogramName(type); |
| 125 if (histogram_name) { |
| 126 UMA_HISTOGRAM_ENUMERATION(histogram_name, CONTEXT_INIT_FAILED, |
| 127 CONTEXT_LOST_REASON_MAX_ENUM); |
| 128 } |
| 129 } |
| 130 |
| 131 void UmaRecordContextLost(CommandBufferContextType type, |
| 132 gpu::error::Error error, |
| 133 gpu::error::ContextLostReason reason) { |
| 134 const char* histogram_name = GetHistogramName(type); |
| 135 if (histogram_name) { |
| 136 CommandBufferContextLostReason converted_reason = |
| 137 GetContextLostReason(error, reason); |
| 138 UMA_HISTOGRAM_ENUMERATION(histogram_name, converted_reason, |
| 139 CONTEXT_LOST_REASON_MAX_ENUM); |
| 140 } |
| 141 } |
| 142 |
| 143 } // namespace content |
OLD | NEW |