Bug 591714 - Remove ancient (and ifdeffed out) heapdump code, r=robarnold,dbaron, a=NPOTB

--HG--
extra : rebase_source : 3aed6d6f6bf57f848cce51e59dbd13a3df590faf
This commit is contained in:
Phil Ringnalda 2010-08-29 18:21:12 -07:00
Родитель 2ce3beeeb9
Коммит 70e5fb2a0d
7 изменённых файлов: 1 добавлений и 445 удалений

Просмотреть файл

@ -1,19 +0,0 @@
while (<>) {
chomp;
if (/^mozilla.exe/) {
$start = 1;
}
if ($start) {
chomp;
@fields = split(/ */);
$bytes = $fields[2];
$bytes =~ s/,//g;
$codesize += $bytes;
}
}
printf "%8.2f K codesize\n", toK($codesize);
sub toK()
{
return $_[0] / 1024;
}

Просмотреть файл

@ -1,135 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001, 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Suresh Duddi <dp@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* heapdump
*
* Sends a message to netscape 6.3 to dump the heap.
*/
#include <windows.h>
#include <stdio.h>
static const char *kMozHeapDumpMessageString = "MOZ_HeapDump";
static const char *kMozAppClassName = "MozillaWindowClass";
BOOL IsMozilla(const char *title)
{
if (!title || !*title)
return FALSE;
// Title containing " - Mozilla" is a mozilla window
if (strstr(title, " - Mozilla"))
return TRUE;
// Title containing "Mozilla {" is a mozilla window
// This form happens when there is no title
if (strstr(title, "Mozilla {"))
return TRUE;
return FALSE;
}
BOOL IsNetscape(const char *title)
{
if (!title || !*title)
return FALSE;
// Skip to where the <space>-<space>Netscape 6 exists
return strstr(title, " - Netscape 6") ? TRUE : FALSE;
}
// Find a mozilla or Netscape top level window in that order
// Pattter we are looking for is
// .* - Netscape 6 [{.*}]
// .* - Mozilla [{.*}]
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
HWND * pwnd = (HWND *)lParam;
char buf[1024];
// Make sure we are dealing with a window of our class name
GetClassName(hwnd, buf, sizeof(buf)-1);
if (strcmp(buf, kMozAppClassName))
return TRUE;
GetWindowText(hwnd, buf, sizeof(buf)-1);
if (IsMozilla(buf)) {
// Yeah. Search ends.
*pwnd = hwnd;
return FALSE;
}
// We continue search if we find a Netscape window
// since we might find a mozilla window next
if (IsNetscape(buf))
*pwnd = hwnd;
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
UINT msgHandle = RegisterWindowMessage(kMozHeapDumpMessageString);
// Find a window to send the message to.
// We look for a mozilla window first and then a netscape window
// logic being that developers run release Netscape (to read mail) and
// mozilla (debug builds).
HWND mozwindow = 0;
EnumWindows(EnumWindowsProc, (LPARAM) &mozwindow);
if (mozwindow == 0) {
printf("Cannot find Mozilla or Netscape 6 window. Exit\n");
exit(-1);
}
char buf[1024];
GetWindowText(mozwindow, buf, sizeof(buf)-1);
if (IsMozilla(buf))
printf("Found Mozilla window with title : %s\n", buf);
else if (IsNetscape(buf))
printf("Found Netscape window with title : %s\n", buf);
SendMessage(mozwindow, msgHandle, 0, 0);
printf("Sending HeapDump Message done. Heapdump available in c:\\heapdump.txt\n");
return 0;
}

Просмотреть файл

@ -1,141 +0,0 @@
use strict;
my ($freeBytes, $freeCount);
my ($usedBytes, $usedCount);
my ($uncommFreeBytes, $uncommFreeCount);
my ($freeAtEndBytes, $freeAtEndCount);
my ($overheadBytes, $overheadCount);
my ($holeBytes, $holeCount, @hole);
my ($commBytes, $uncommBytes);
# track prev address of allocation to detect holes
# Track begin and end address of contiguous block
my ($nextAddr) = 0;
my $holeTolerance = 0;
# Heading for heap dump
my $heading;
# Notes the previous block size if it was a free to track freeAtEnd.
# If prev block was not a free, this would be set to zero.
my $prevFree = 0;
while(<>)
{
if (/BEGIN HEAPDUMP : (.*)$/) {
# Initialize all variables
($freeBytes, $freeCount) = 0;
($usedBytes, $usedCount) = 0;
($uncommFreeBytes, $uncommFreeCount) = 0;
($freeAtEndBytes, $freeAtEndCount) = 0;
($overheadBytes, $overheadCount) = 0;
($holeBytes, $holeCount) = 0;
($commBytes, $uncommBytes) = 0;
$heading = $1;
@hole = ();
next;
}
if (/END HEAPDUMP/) {
# Print results of heapdump
results();
next;
}
# look for blocks that are used or free
if (/BEGIN heap/) {
next;
}
if (/END heap/) {
# Reset nextAddr for overhead detection
$nextAddr = 0;
# See if the previous heap ended with a free block
if ($prevFree) {
$freeAtEndBytes += $prevFree;
$freeAtEndCount++;
}
$prevFree = 0;
next;
}
if (/REGION ([0-9A-Fa-f]*) : *overhead ([0-9]*) committed ([0-9]*) uncommitted ([0-9]*)/) {
# Reset nextAddr for overhead detection
$nextAddr = 0;
# See if the previous heap ended with a free block
if ($prevFree) {
$freeAtEndBytes += $prevFree;
$freeAtEndCount++;
}
$prevFree = 0;
$commBytes += $3;
$uncommBytes += $4;
$overheadBytes += $2;
$overheadCount++;
next;
}
if (/ *FREE ([0-9A-Fa-f]*) : *([0-9]*) overhead *([0-9]*)/)
{
$freeCount++;
$freeBytes += $2;
$overheadCount++;
$overheadBytes += $3;
# This is a free. Notes it size. If the this is the end of the heap,
# this is a candidate for compaction.
$prevFree = $2;
}
elsif (/ *USED ([0-9A-Fa-f]*) : *([0-9]*) overhead *([0-9]*)/)
{
$usedCount++;
$usedBytes += $2;
$overheadCount++;
$overheadBytes += $3;
# This wasn't a free
$prevFree = 0;
}
elsif (/ *---- ([0-9A-Fa-f]*) : *([0-9]*) overhead *([0-9]*)/)
{
$uncommFreeCount++;
$uncommFreeBytes += $2;
# these won't have any overhead
# we shouldn't view this as a free as we could shed this and
# reduce our VmSize
$prevFree = $2;
}
else {
next;
}
my $addr = hex $1;
my $size = $2;
my $overhead = $3;
if ($nextAddr && $addr-$nextAddr > $holeTolerance) {
# found a hole. This is usally alignment overhead
$holeCount ++;
$holeBytes += $addr - $nextAddr;
}
$nextAddr = $addr + $size + $overhead;
}
sub results()
{
printf "Heap statistics : $heading\n";
printf "------------------------------------------------------------\n";
printf "USED : %8.2f K in %6d blocks\n", toK($usedBytes), $usedCount;
printf "FREE : %8.2f K in %6d blocks\n", toK($freeBytes), $freeCount;
printf "Uncommitted FREE : %8.2f K in %6d blocks\n", toK($uncommFreeBytes), $uncommFreeCount;
printf "Overhead : %8.2f K in %6d blocks\n", toK($overheadBytes), $overheadCount;
printf "Alignment overhead : %8.2f K in %6d blocks\n", toK($holeBytes), $holeCount;
printf " Total : %8.2f K\n", toK($freeBytes+$usedBytes+$uncommFreeBytes+$overheadBytes+$holeBytes);
printf "FREE at heap end : %8.2f K in %6d blocks - %5.2f%% of FREE\n", toK($freeAtEndBytes), $freeAtEndCount, $freeAtEndBytes/($freeBytes+$uncommFreeBytes)*100;
printf "\n";
printf "Total Commit : %8.2f K\n", toK($commBytes);
printf "Total Uncommit : %8.2f K\n", toK($uncommBytes);
printf " Total : %8.2f K\n", toK($uncommBytes + $commBytes);
}
sub toK()
{
my $bytes = shift;
return $bytes / 1024;
}

Просмотреть файл

@ -1,55 +0,0 @@
#!nmake
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH=..\..
MAKE_OBJ_TYPE = EXE
PROG1 = .\$(OBJDIR)\heapdump.exe
PROGRAMS = $(PROG1)
PDBFILE=heapdump
include <$(DEPTH)\config\rules.mak>
libs:: $(OBJDIR) $(PROGRAMS)
-for %p in ($(PROGRAMS)) do $(MAKE_INSTALL) %p $(DIST)\bin
$(MAKE_INSTALL) heapmap.pl $(DIST)\bin
$(MAKE_INSTALL) codemap.pl $(DIST)\bin
clobber::
-for %p in ($(PROGRAMS)) do $(RM) %p $(DIST)\bin\%p

Просмотреть файл

@ -437,10 +437,6 @@ nsWindow::nsWindow() : nsBaseWidget()
NS_ASSERTION(sIsOleInitialized, "***** OLE is not initialized!\n");
#endif
#if defined(HEAP_DUMP_EVENT)
InitHeapDump();
#endif
#if !defined(WINCE)
InitTrackPointHack();
#endif
@ -5398,12 +5394,6 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM &wParam, LPARAM &lParam,
nsTextStore::OnTextChangeMsg();
}
#endif //NS_ENABLE_TSF
#if defined(HEAP_DUMP_EVENT)
if (msg == GetHeapMsg()) {
HeapDump(msg, wParam, lParam);
result = PR_TRUE;
}
#endif
#if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_WIN7
if (msg == nsAppShell::GetTaskbarButtonCreatedMessage())
SetHasTaskbarIconBeenCreated();

Просмотреть файл

@ -417,81 +417,6 @@ void PrintEvent(UINT msg, PRBool aShowAllEvents, PRBool aShowMouseMoves)
#endif // defined(POPUP_ROLLUP_DEBUG_OUTPUT) || defined(EVENT_DEBUG_OUTPUT)
#if defined(HEAP_DUMP_EVENT)
// Debug heap dumping helpers.
// XXX for now we use c:\heapdump.txt until we figure out how to
// XXX pass in message parameters.
static const PRUnichar kMozHeapDumpMessageString[] = L"MOZ_HeapDump";
static const char kMozHeapDumpFilenameString[] = "c:\\heapdump.txt";
static const char kMozHeapDumpHeaderString[] = "whatever";
// Windows message that triggers a heap Dump to a file
static UINT uWM_HEAP_DUMP = 0;
void InitHeapDump()
{
if (uWM_HEAP_DUMP == 0)
uWM_HEAP_DUMP = ::RegisterWindowMessageW(kMozHeapDumpMessageString);
}
UINT GetHeapMsg()
{
return uWM_HEAP_DUMP;
}
nsresult HeapDump(UINT msg, WPARAM wParam, LPARAM lParam)
{
#ifdef WINCE
return NS_ERROR_NOT_IMPLEMENTED;
#else
PRFileDesc *prfd = PR_Open(kMozHeapDumpFilenameString, PR_CREATE_FILE | PR_APPEND | PR_WRONLY, 0777);
if (!prfd)
return NS_ERROR_FAILURE;
char buf[1024];
PRUint32 n;
PRUint32 written = 0;
HANDLE heapHandle[64];
DWORD nheap = GetProcessHeaps(64, heapHandle);
if (nheap == 0 || nheap > 64) {
return NS_ERROR_FAILURE;
}
n = PR_snprintf(buf, sizeof buf, "BEGIN HEAPDUMP : %s\n", kMozHeapDumpHeaderString);
PR_Write(prfd, buf, n);
for (DWORD i = 0; i < nheap; i++) {
// Dump each heap
PROCESS_HEAP_ENTRY ent = {0};
n = PR_snprintf(buf, sizeof buf, "BEGIN heap %d : 0x%p\n", i+1, heapHandle[i]);
PR_Write(prfd, buf, n);
ent.lpData = NULL;
while (HeapWalk(heapHandle[i], &ent)) {
if (ent.wFlags & PROCESS_HEAP_REGION)
n = PR_snprintf(buf, sizeof buf, "REGION %08p : overhead %d committed %d uncommitted %d firstblock %08p lastblock %08p\n",
ent.lpData, ent.cbOverhead,
ent.Region.dwCommittedSize, ent.Region.dwUnCommittedSize,
ent.Region.lpFirstBlock, ent.Region.lpLastBlock);
else
n = PR_snprintf(buf, sizeof buf, "%s %08p : %6d overhead %2d\n",
(ent.wFlags & PROCESS_HEAP_UNCOMMITTED_RANGE) ? "----" : ((ent.wFlags & PROCESS_HEAP_ENTRY_BUSY) ? "USED" : "FREE"),
ent.lpData, ent.cbData, ent.cbOverhead);
PR_Write(prfd, buf, n);
}
n = PR_snprintf(buf, sizeof buf, "END heap %d : 0x%p\n", i+1, heapHandle[i]);
PR_Write(prfd, buf, n);
}
n = PR_snprintf(buf, sizeof buf, "END HEAPDUMP : %s\n", kMozHeapDumpHeaderString);
PR_Write(prfd, buf, n);
PR_Close(prfd);
return NS_OK;
#endif // WINCE
}
#endif // defined(HEAP_DUMP_EVENT)
#ifdef DEBUG
void DDError(const char *msg, HRESULT hr)
{

Просмотреть файл

@ -51,9 +51,6 @@
// Enables debug output for popup rollup hooks
//#define POPUP_ROLLUP_DEBUG_OUTPUT
// Enable heap debug dump message handling
//#define HEAP_DUMP_EVENT
// Enable window size and state debug output
//#define WINSTATE_DEBUG_OUTPUT
@ -85,12 +82,6 @@ typedef struct {
#define DISPLAY_NMM_PRT(_arg)
#endif // defined(POPUP_ROLLUP_DEBUG_OUTPUT)
#if defined(HEAP_DUMP_EVENT)
void InitHeapDump();
nsresult HeapDump(UINT msg, WPARAM wParam, LPARAM lParam);
UINT GetHeapMsg();
#endif // defined(HEAP_DUMP_EVENT)
#if defined(DEBUG)
void DDError(const char *msg, HRESULT hr);
#endif // defined(DEBUG)
@ -102,4 +93,4 @@ PRBool is_vk_down(int vk);
#define IS_VK_DOWN(a) (GetKeyState(a) < 0)
#endif // defined(DEBUG_VK)
#endif /* WindowDbg_h__ */
#endif /* WindowDbg_h__ */