Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: base/debug/gdi_debug_util_win.cc

Issue 2452933002: Collect information on the dump when GetDC fails. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "base/debug/gdi_debug_util_win.h" 4 #include "base/debug/gdi_debug_util_win.h"
5 5
6 #include <cmath> 6 #include <cmath>
7 7
8 #include <psapi.h> 8 #include <psapi.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <TlHelp32.h> 10 #include <TlHelp32.h>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 sum_gdi_count += num_gdi_handles; 52 sum_gdi_count += num_gdi_handles;
53 if (peak_gdi_count < num_gdi_handles) 53 if (peak_gdi_count < num_gdi_handles)
54 peak_gdi_count = num_gdi_handles; 54 peak_gdi_count = num_gdi_handles;
55 55
56 } while (Process32Next(snapshot, &proc_entry)); 56 } while (Process32Next(snapshot, &proc_entry));
57 57
58 CloseHandle(snapshot); 58 CloseHandle(snapshot);
59 CHECK(false); 59 CHECK(false);
60 } 60 }
61 61
62 } // namespace 62 void CollectGDIUsageAndDieWithBitmap(BITMAPINFOHEADER* header,
63 63 HANDLE shared_section) {
64 namespace base {
65 namespace debug {
66
67 void GDIBitmapAllocFailure(BITMAPINFOHEADER* header, HANDLE shared_section) {
68 // Make sure parameters are saved in the minidump. 64 // Make sure parameters are saved in the minidump.
69 DWORD last_error = GetLastError(); 65 DWORD last_error = GetLastError();
70 66
71 LONG width = header->biWidth;
72 LONG heigth = header->biHeight;
73
74 base::debug::Alias(&last_error); 67 base::debug::Alias(&last_error);
75 base::debug::Alias(&width);
76 base::debug::Alias(&heigth);
77 base::debug::Alias(&shared_section);
78 68
79 DWORD num_user_handles = GetGuiResources(GetCurrentProcess(), GR_USEROBJECTS); 69 DWORD num_user_handles = GetGuiResources(GetCurrentProcess(), GR_USEROBJECTS);
80 70
81 DWORD num_gdi_handles = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS); 71 DWORD num_gdi_handles = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
82 if (num_gdi_handles == 0) { 72 if (num_gdi_handles == 0) {
83 DWORD get_gui_resources_error = GetLastError(); 73 DWORD get_gui_resources_error = GetLastError();
84 base::debug::Alias(&get_gui_resources_error); 74 base::debug::Alias(&get_gui_resources_error);
85 CHECK(false); 75 CHECK(false);
86 } 76 }
87 77
88 base::debug::Alias(&num_gdi_handles); 78 base::debug::Alias(&num_gdi_handles);
89 base::debug::Alias(&num_user_handles); 79 base::debug::Alias(&num_user_handles);
90 80
91 const DWORD kLotsOfHandles = 9990; 81 const DWORD kLotsOfHandles = 9990;
92 CHECK_LE(num_gdi_handles, kLotsOfHandles); 82 CHECK_LE(num_gdi_handles, kLotsOfHandles);
93 83
94 PROCESS_MEMORY_COUNTERS_EX pmc; 84 PROCESS_MEMORY_COUNTERS_EX pmc;
95 pmc.cb = sizeof(pmc); 85 pmc.cb = sizeof(pmc);
96 CHECK(GetProcessMemoryInfo(GetCurrentProcess(), 86 CHECK(GetProcessMemoryInfo(GetCurrentProcess(),
97 reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmc), 87 reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&pmc),
98 sizeof(pmc))); 88 sizeof(pmc)));
99 const size_t kLotsOfMemory = 1500 * 1024 * 1024; // 1.5GB 89 const size_t kLotsOfMemory = 1500 * 1024 * 1024; // 1.5GB
100 CHECK_LE(pmc.PagefileUsage, kLotsOfMemory); 90 CHECK_LE(pmc.PagefileUsage, kLotsOfMemory);
101 CHECK_LE(pmc.PrivateUsage, kLotsOfMemory); 91 CHECK_LE(pmc.PrivateUsage, kLotsOfMemory);
102 92
103 void* small_data = NULL; 93 void* small_data = nullptr;
104 base::debug::Alias(&small_data); 94 base::debug::Alias(&small_data);
105 95
106 if (std::abs(heigth) * width > 100) { 96 if (header && (std::abs(header->biHeight) * header->biWidth > 100)) {
107 // Huh, that's weird. We don't have crazy handle count, we don't have 97 // Huh, that's weird. We don't have crazy handle count, we don't have
108 // ridiculous memory usage. Try to allocate a small bitmap and see if that 98 // ridiculous memory usage. Try to allocate a small bitmap and see if that
109 // fails too. 99 // fails too.
110 header->biWidth = 5; 100 header->biWidth = 5;
111 header->biHeight = -5; 101 header->biHeight = -5;
112 HBITMAP small_bitmap = CreateDIBSection( 102 HBITMAP small_bitmap = CreateDIBSection(
113 NULL, reinterpret_cast<BITMAPINFO*>(&header), 103 nullptr, reinterpret_cast<BITMAPINFO*>(&header),
114 0, &small_data, shared_section, 0); 104 0, &small_data, shared_section, 0);
115 CHECK(small_bitmap != NULL); 105 CHECK(small_bitmap != nullptr);
116 DeleteObject(small_bitmap); 106 DeleteObject(small_bitmap);
117 } 107 }
108
118 // Maybe the child processes are the ones leaking GDI or USER resouces. 109 // Maybe the child processes are the ones leaking GDI or USER resouces.
119 CollectChildGDIUsageAndDie(GetCurrentProcessId()); 110 CollectChildGDIUsageAndDie(GetCurrentProcessId());
120 } 111 }
121 112
113 } // namespace
114
115 namespace base {
116 namespace debug {
117
118 void CollectGDIUsageAndDie() {
119 CollectGDIUsageAndDieWithBitmap(nullptr, nullptr);
120 }
121
122 void GDIBitmapAllocFailure(BITMAPINFOHEADER* header, HANDLE shared_section) {
123 LONG width = header->biWidth;
124 LONG height = header->biHeight;
125
126 base::debug::Alias(&width);
127 base::debug::Alias(&height);
128 base::debug::Alias(&shared_section);
129
130 CollectGDIUsageAndDieWithBitmap(header, shared_section);
131 }
132
122 } // namespace debug 133 } // namespace debug
123 } // namespace base 134 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698