| 1 |
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 |
/* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
| 3 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#ifndef ProfilerBufferSize_h |
| 8 |
#define ProfilerBufferSize_h |
| 9 |
|
| 10 |
#include "mozilla/ProfileBufferChunkManager.h" |
| 11 |
|
| 12 |
// We need to decide how many chunks of what size we want to fit in the given |
| 13 |
// total maximum capacity for this process, in the (likely) context of |
| 14 |
// multiple processes doing the same choice and having an inter-process |
| 15 |
// mechanism to control the overall memory limit. |
| 16 |
|
| 17 |
// The buffer size is provided as a number of "entries", this is their size in |
| 18 |
// bytes. |
| 19 |
constexpr static uint32_t scBytesPerEntry = 8; |
| 20 |
|
| 21 |
// Minimum chunk size allowed, enough for at least one stack. |
| 22 |
constexpr static uint32_t scMinimumChunkSize = |
| 23 |
2 * mozilla::ProfileBufferChunkManager::scExpectedMaximumStackSize; |
| 24 |
|
| 25 |
// Ideally we want at least 2 unreleased chunks to work with (1 current and 1 |
| 26 |
// next), and 2 released chunks (so that one can be recycled when old, leaving |
| 27 |
// one with some data). |
| 28 |
constexpr static uint32_t scMinimumNumberOfChunks = 4; |
| 29 |
|
| 30 |
// And we want to limit chunks to a maximum size, which is a compromise |
| 31 |
// between: |
| 32 |
// - A big size, which helps with reducing the rate of allocations and IPCs. |
| 33 |
// - A small size, which helps with equalizing the duration of recorded data |
| 34 |
// (as the inter-process controller will discard the oldest chunks in all |
| 35 |
// Firefox processes). |
| 36 |
constexpr static uint32_t scMaximumChunkSize = 1024 * 1024; |
| 37 |
|
| 38 |
// Limit to 128MiB as a lower buffer size usually isn't enough. |
| 39 |
constexpr static uint32_t scMinimumBufferSize = 128u * 1024u * 1024u; |
| 40 |
// Note: Keep in sync with GeckoThread.maybeStartGeckoProfiler: |
| 41 |
// https://searchfox.org/mozilla-central/source/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java |
| 42 |
constexpr static uint32_t scMinimumBufferEntries = |
| 43 |
scMinimumBufferSize / scBytesPerEntry; |
| 44 |
|
| 45 |
// Limit to 2GiB. |
| 46 |
constexpr static uint32_t scMaximumBufferSize = 2u * 1024u * 1024u * 1024u; |
| 47 |
constexpr static uint32_t scMaximumBufferEntries = |
| 48 |
scMaximumBufferSize / scBytesPerEntry; |
| 49 |
|
| 50 |
constexpr static uint32_t ClampToAllowedEntries(uint32_t aEntries) { |
| 51 |
if (aEntries <= scMinimumBufferEntries) { |
| 52 |
return scMinimumBufferEntries; |
| 53 |
} |
| 54 |
if (aEntries >= scMaximumBufferEntries) { |
| 55 |
return scMaximumBufferEntries; |
| 56 |
} |
| 57 |
return aEntries; |
| 58 |
} |
| 59 |
|
| 60 |
#endif // ProfilerBufferSize_h |