OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 4 |
5 #include <windows.h> | 5 #include <windows.h> |
6 #include <tlhelp32.h> // for CreateToolhelp32Snapshot() | 6 #include <tlhelp32.h> // for CreateToolhelp32Snapshot() |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "tools/memory_watcher/memory_watcher.h" | 9 #include "tools/memory_watcher/memory_watcher.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 tmp_name += ".tmp"; | 75 tmp_name += ".tmp"; |
76 file_ = fopen(tmp_name.c_str(), "w+"); | 76 file_ = fopen(tmp_name.c_str(), "w+"); |
77 } | 77 } |
78 | 78 |
79 void MemoryWatcher::CloseLogFile() { | 79 void MemoryWatcher::CloseLogFile() { |
80 if (file_ != NULL) { | 80 if (file_ != NULL) { |
81 fclose(file_); | 81 fclose(file_); |
82 file_ = NULL; | 82 file_ = NULL; |
83 std::wstring tmp_name = ASCIIToWide(file_name_); | 83 std::wstring tmp_name = ASCIIToWide(file_name_); |
84 tmp_name += L".tmp"; | 84 tmp_name += L".tmp"; |
85 file_util::Move(FilePath::FromWStringHack(tmp_name), | 85 file_util::Move(tmp_name, ASCIIToWide(file_name_)); |
86 FilePath::FromWStringHack(ASCIIToWide(file_name_))); | |
87 } | 86 } |
88 } | 87 } |
89 | 88 |
90 void MemoryWatcher::OnTrack(HANDLE heap, int32 id, int32 size) { | 89 void MemoryWatcher::OnTrack(HANDLE heap, int32 id, int32 size) { |
91 // AllocationStack overrides new/delete to not allocate | 90 // AllocationStack overrides new/delete to not allocate |
92 // from the main heap. | 91 // from the main heap. |
93 AllocationStack* stack = new AllocationStack(size); | 92 AllocationStack* stack = new AllocationStack(size); |
94 { | 93 { |
95 // Don't track zeroes. It's a waste of time. | 94 // Don't track zeroes. It's a waste of time. |
96 if (size == 0) { | 95 if (size == 0) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 std::string output; | 197 std::string output; |
199 stack->ToString(&output); | 198 stack->ToString(&output); |
200 fprintf(file_, "%s", output.c_str()); | 199 fprintf(file_, "%s", output.c_str()); |
201 it++; | 200 it++; |
202 } | 201 } |
203 fprintf(file_, "Total Leaks: %d\n", block_map_->size()); | 202 fprintf(file_, "Total Leaks: %d\n", block_map_->size()); |
204 fprintf(file_, "Total Stacks: %d\n", stack_map_->size()); | 203 fprintf(file_, "Total Stacks: %d\n", stack_map_->size()); |
205 fprintf(file_, "Total Bytes: %d\n", block_map_size_); | 204 fprintf(file_, "Total Bytes: %d\n", block_map_size_); |
206 CloseLogFile(); | 205 CloseLogFile(); |
207 } | 206 } |
OLD | NEW |