Bug 986082 - add memory reporters for SPDY zlib buffers; r=hurley,njn

This commit is contained in:
Nathan Froyd 2014-03-20 14:22:17 -04:00
Родитель 52ddeb17ca
Коммит 719e6a25de
10 изменённых файлов: 106 добавлений и 44 удалений

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

@ -23,6 +23,7 @@
#include "SpdySession3.h"
#include "SpdyStream3.h"
#include "PSpdyPush.h"
#include "SpdyZlibReporter.h"
#include <algorithm>
@ -586,14 +587,14 @@ SpdySession3::DecrementConcurrent(SpdyStream3 *aStream)
void
SpdySession3::zlibInit()
{
mDownstreamZlib.zalloc = SpdyStream3::zlib_allocator;
mDownstreamZlib.zfree = SpdyStream3::zlib_destructor;
mDownstreamZlib.zalloc = SpdyZlibReporter::Alloc;
mDownstreamZlib.zfree = SpdyZlibReporter::Free;
mDownstreamZlib.opaque = Z_NULL;
inflateInit(&mDownstreamZlib);
mUpstreamZlib.zalloc = SpdyStream3::zlib_allocator;
mUpstreamZlib.zfree = SpdyStream3::zlib_destructor;
mUpstreamZlib.zalloc = SpdyZlibReporter::Alloc;
mUpstreamZlib.zfree = SpdyZlibReporter::Free;
mUpstreamZlib.opaque = Z_NULL;
// mixing carte blanche compression with tls subjects us to traffic

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

@ -24,6 +24,7 @@
#include "SpdyPush31.h"
#include "SpdySession31.h"
#include "SpdyStream31.h"
#include "SpdyZlibReporter.h"
#include <algorithm>
@ -591,14 +592,14 @@ SpdySession31::DecrementConcurrent(SpdyStream31 *aStream)
void
SpdySession31::zlibInit()
{
mDownstreamZlib.zalloc = SpdyStream31::zlib_allocator;
mDownstreamZlib.zfree = SpdyStream31::zlib_destructor;
mDownstreamZlib.zalloc = SpdyZlibReporter::Alloc;
mDownstreamZlib.zfree = SpdyZlibReporter::Free;
mDownstreamZlib.opaque = Z_NULL;
inflateInit(&mDownstreamZlib);
mUpstreamZlib.zalloc = SpdyStream31::zlib_allocator;
mUpstreamZlib.zfree = SpdyStream31::zlib_destructor;
mUpstreamZlib.zalloc = SpdyZlibReporter::Alloc;
mUpstreamZlib.zfree = SpdyZlibReporter::Free;
mUpstreamZlib.opaque = Z_NULL;
// mixing carte blanche compression with tls subjects us to traffic

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

@ -25,6 +25,7 @@
#include "SpdySession3.h"
#include "SpdyStream3.h"
#include "PSpdyPush.h"
#include "SpdyZlibReporter.h"
#include <algorithm>
@ -986,20 +987,6 @@ const unsigned char SpdyStream3::kDictionary[] = {
0x2c, 0x65, 0x6e, 0x71, 0x3d, 0x30, 0x2e // - e n q - 0 -
};
// use for zlib data types
void *
SpdyStream3::zlib_allocator(void *opaque, uInt items, uInt size)
{
return moz_xmalloc(items * size);
}
// use for zlib data types
void
SpdyStream3::zlib_destructor(void *opaque, void *addr)
{
moz_free(addr);
}
// This can be called N times.. 1 for syn_reply and 0->N for headers
nsresult
SpdyStream3::Uncompress(z_stream *context,

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

@ -66,11 +66,8 @@ public:
void UpdateTransportSendEvents(uint32_t count);
void UpdateTransportReadEvents(uint32_t count);
// The zlib header compression dictionary defined by SPDY,
// and hooks to the mozilla allocator for zlib to use.
// The zlib header compression dictionary defined by SPDY.
static const unsigned char kDictionary[1423];
static void *zlib_allocator(void *, uInt, uInt);
static void zlib_destructor(void *, void *);
nsresult Uncompress(z_stream *, char *, uint32_t);
nsresult ConvertHeaders(nsACString &);

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

@ -1003,20 +1003,6 @@ const unsigned char SpdyStream31::kDictionary[] = {
0x2c, 0x65, 0x6e, 0x71, 0x3d, 0x30, 0x2e // - e n q - 0 -
};
// use for zlib data types
void *
SpdyStream31::zlib_allocator(void *opaque, uInt items, uInt size)
{
return moz_xmalloc(items * size);
}
// use for zlib data types
void
SpdyStream31::zlib_destructor(void *opaque, void *addr)
{
moz_free(addr);
}
// This can be called N times.. 1 for syn_reply and 0->N for headers
nsresult
SpdyStream31::Uncompress(z_stream *context,

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

@ -61,11 +61,8 @@ public:
void UpdateTransportSendEvents(uint32_t count);
void UpdateTransportReadEvents(uint32_t count);
// The zlib header compression dictionary defined by SPDY,
// and hooks to the mozilla allocator for zlib to use.
// The zlib header compression dictionary defined by SPDY.
static const unsigned char kDictionary[1423];
static void *zlib_allocator(void *, uInt, uInt);
static void zlib_destructor(void *, void *);
nsresult Uncompress(z_stream *, char *, uint32_t);
nsresult ConvertHeaders(nsACString &);

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

@ -0,0 +1,38 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SpdyZlibReporter.h"
namespace mozilla {
NS_IMPL_ISUPPORTS1(SpdyZlibReporter, nsIMemoryReporter)
/* static */ Atomic<size_t> SpdyZlibReporter::sAmount;
/* static */ void*
SpdyZlibReporter::Alloc(void*, uInt items, uInt size)
{
void* p = moz_xmalloc(items * size);
sAmount += MallocSizeOfOnAlloc(p);
return p;
}
/* static */ void
SpdyZlibReporter::Free(void*, void* p)
{
sAmount -= MallocSizeOfOnFree(p);
moz_free(p);
}
NS_IMETHODIMP
SpdyZlibReporter::CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData)
{
return MOZ_COLLECT_REPORT(
"explicit/network/spdy-zlib-buffers", KIND_HEAP, UNITS_BYTES, sAmount,
"Memory allocated for SPDY zlib send and receive buffers.");
}
} // namespace mozilla

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

@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* A memory allocator for zlib use in SPDY that reports to about:memory. */
#include "mozilla/Assertions.h"
#include "mozilla/Atomics.h"
#include "mozilla/Attributes.h"
#include "nsIMemoryReporter.h"
#include "zlib.h"
namespace mozilla {
class SpdyZlibReporter MOZ_FINAL : public nsIMemoryReporter
{
public:
NS_DECL_ISUPPORTS
SpdyZlibReporter()
{
#ifdef DEBUG
// There must be only one instance of this class, due to |sAmount|
// being static.
static bool hasRun = false;
MOZ_ASSERT(!hasRun);
hasRun = true;
#endif
sAmount = 0;
}
static void* Alloc(void*, uInt items, uInt size);
static void Free(void*, void* p);
private:
// |sAmount| can be (implicitly) accessed by multiple threads, so it
// must be thread-safe.
static Atomic<size_t> sAmount;
MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf)
MOZ_DEFINE_MALLOC_SIZE_OF_ON_ALLOC(MallocSizeOfOnAlloc)
MOZ_DEFINE_MALLOC_SIZE_OF_ON_FREE(MallocSizeOfOnFree)
NS_IMETHODIMP
CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData);
};
} // namespace mozilla

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

@ -77,6 +77,7 @@ SOURCES += [
'SpdySession31.cpp',
'SpdyStream3.cpp',
'SpdyStream31.cpp',
'SpdyZlibReporter.cpp',
]
# These files cannot be built in unified mode because of OS X headers.

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

@ -45,6 +45,8 @@
#include "nsIStreamConverterService.h"
#include "nsITimer.h"
#include "nsCRT.h"
#include "SpdyZlibReporter.h"
#include "nsIMemoryReporter.h"
#include "mozilla/net/NeckoChild.h"
#include "mozilla/Telemetry.h"
@ -209,6 +211,8 @@ nsHttpHandler::nsHttpHandler()
LOG(("Creating nsHttpHandler [this=%p].\n", this));
RegisterStrongMemoryReporter(new SpdyZlibReporter());
MOZ_ASSERT(!gHttpHandler, "HTTP handler already created!");
gHttpHandler = this;
}