Files
palemoon27/memory/replace/logalloc
roytam1 f7679e4701 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1219066 - Make sure to traverse and unlink HeapSnapshot::mParent in cycle collection; r=mccr8 (a25aab429d)
- Bug 1220918 - Serialize and deseriliaze JS::ubi::Node's script filenames in heap snapshots; r=sfink (7bd216ff4d)
- Bug 1219073 - part 1 - Add to sdk/url#URL objects. r=gozala (535e8fa870)
- Bug 1205733 - Add move overloads to dom::Nullable's constructor and SetValue method, r=bz (44a2684efe)
- Bug 1151884 - Enable the uint32_t overload of ToJSValue; r=smaug (989d3e5b5f)
- obvious fix (76ba7249fb)
- Bug 1225219 Implement ErrorResult::CloneTo(). r=bz (1a05be13c3)
- Bug 1219749. Add a way to faithfully propagate the "exception is already on JSContext" state through an ErrorResult. r=peterv (cb1713a7b9)
- Bug 1204501 - Update the documentation for DOMJSClass::mParticipant; r=peterv (2c0b22cfed)
- Bug 979591. Disallow calling WebIDL constructors as functions even for system callers in release builds. r=peterv (7ad3312248)
- Bug 1180921 - Give Optional<T> Maybe<T>-like operator== semantics. r=bz (aadc8d552d)
- Bug 1188207 - Fix more constructors in DOM; r=baku (4609640af9)
- Bug 1191918 - Round battery level to nearest 10% r=bz (0c98c214b1)
- Bug 1221009. Part 1 - add a class to forward notifications from MediaResource to MediaDecoder. r=roc. (90ca84d0f9)
- Bug 1221009. Part 2 - remove unused code. r=roc. (789b0a0e74)
- Bug 1221009. Part 3 - add assertions to functions that shouldn't be called after shutdown. r=roc. (d292c1701f)
- Bug 1217653 - MediaDecoder::GetOwner() should return null after shutdown. r=kinetik. (f071ecf2ee)
- Bug 1219142. Part 1 - add AbstractMediaDecoder::DataArrivedEvent() to publish events. r=jya. (15e67bbd3e)
- Bug 1219142. Part 2 - remove unused code. r=jya. (e2be34e25a)
- bug 681602 - Implement xptcall for arm iOS. r=glandium (3be41176bc)
- Bug 1188209 - Fix more constructors in memory; r=njn (28b833e741)
- Bug 1222171 - Re-establish equivalence between gfxImageFormat and cairo_format_t. r=mstange. (6e50fcea80)
- Bug 1215898 - Fix clang's -Wimplicit-fallthrough warnings in gfx/thebes. r=jdaggett r=jmuizelaar (db0f7ec46c)
- Bug 598900 - GDI: use typo metrics when USE_TYPO_METRICS is specified. r=karlt (0fb2af92ce)
- Bug 964512 - Check for existence of character before trying to get its metrics in gfxGDIFont::Initialize. r=jdaggett (bc88ee4252)
- Bug 691581 - Don't let a zero-sized font result in assertions from FUnitsToDevUnitsFactor(). r=jdaggett (3408c67dbf)
- clean spaces (ffdccafdea)
- Bug 1192666 - Emit '[]' around origin strings for ipv6 origins, r=ehsan (cc5fcdb711)
- Bug 1195415 - Add asciiHostPort field to nsIURI, and use it in the implementation of nsPrincipal::GetOriginForURI, r=bholley (7793745ecb)
- Bug 1204610 - Use a smart pointer in nsNullPrincipalURI. r=mrbkap (082fedf3e7)
- Bug 859764 - Part 1.1: Turn IDL Implementation into Internal-Only Interface. r=echen, r=smaug (900ae90da3)
- Bug 1043250 - Part 2: Update MobileMessageCallback and SmsService. r=btseng (fc2a0ed029)
- Bug 1175430 - Expose Network-Specific Error Cause for Various Error Handling in App Layer. r=btseng (c3abacd9e1)
- Bug 859764 - Part 1.2: Clearn Up Naming in IDL. r=echen (41f70a1f4c)
- Bug 1152730 - Part 3: Add owner window checks on DOM object operations. r=btseng (2c09378b02)
- Bug 1043250 - Part 3: Update MozMobileMessageManager WebIDL interface and implementation. r=hsinyi (06feae677b)
- Bug 859764 - Part 2: Define New WebIDL interfaces for MobileMessage Objects. r=echen r=smaug (54cb39df82)
- Bug 859764 - Part 3: The Implementation for WebIDL Change. r=echen, r=smaug (be0d0439dc)
- Bug 984413 - Add JSdoc in MobileMessageDB.jsm. r=btseng (a3f15e291a)
- Bug 1154186 - Deprecate nsISmsMessenger_new.idl. r=echen (b179f3343c)
- Bug 1152730 - Part 1: Update retry logic in SmsService and remove the retry in ril_worker. r=btseng (d8e5b520f2)
- Bug 1197010 - Implement Android backend for createMessageCursor/createThreadCursor. r=snorp (9e4506b4a2)
- Bug 748391 - Implement markMessageRead on the Android backend. r=snorp (d969455588)
- Bug 859764 - Part 4: Implementation Change in Different Backend. r=echen (607b9bb53f)
- Bug 1043250 - Part 4: Update SMS IPC implementation. r=btseng (264cd87721)
- Bug 1197008 - Stop assuming 0 is an invalid threadId. r=btseng r=hsinyi (5498728784)
2023-01-13 13:25:15 +08:00
..

Logalloc is a replace-malloc library for Firefox (see
memory/build/replace_malloc.h) that dumps a log of memory allocations to a
given file descriptor or file name. That log can then be replayed against
Firefox's default memory allocator independently or through another
replace-malloc library, allowing the testing of other allocators under the
exact same workload.

To get an allocation log the following environment variables need to be set
when starting Firefox:
- on Linux:
  LD_PRELOAD=/path/to/liblogalloc.so
- on Mac OSX:
  DYLD_INSERT_LIBRARIES=/path/to/liblogalloc.dylib
- on Windows:
  MOZ_REPLACE_MALLOC_LIB=/path/to/logalloc.dll
- on Android:
  MOZ_REPLACE_MALLOC_LIB=/path/to/liblogalloc.so
  (see https://wiki.mozilla.org/Mobile/Fennec/Android#Arguments_and_Environment_Variables
  for how to pass environment variables to Firefox for Android)

- on all platforms:
  MALLOC_LOG=/path/to/log-file
  or
  MALLOC_LOG=number

When MALLOC_LOG is a number below 10000, it is considered as a file
descriptor number that is fed to Firefox when it is started. Otherwise,
it is considered as a file name.

As those allocation logs can grow large quite quickly, it can be useful
to pipe the output to a compression tool.

MALLOC_LOG=1 would send to Firefox's stdout, MALLOC_LOG=2 would send to
its stderr. Since in both cases that could be mixed with other output
from Firefox, it is usually better to use another file descriptor
by shell redirections, such as:

  MALLOC_LOG=3 firefox 3>&1 1>&2 | gzip -c > log.gz

(3>&1 copies the `| gzip` pipe file descriptor to file descriptor #3, 1>&2
then copies stderr to stdout. This leads to: fd1 and fd2 sending to stderr
of the parent process (the shell), and fd3 sending to gzip.)

Each line of the allocations log is formatted as follows:
  <pid> <function>([<args>])[=<result>]
where <args> is a comma separated list of values. The number of <args> and
the presence of <result> depend on the <function>.

Example log:
  18545 malloc(32)=0x7f90495120e0
  18545 calloc(1,148)=0x7f9049537480
  18545 realloc(0x7f90495120e0,64)=0x7f9049536680
  18545 posix_memalign(256,240)=0x7f9049583300
  18545 jemalloc_stats()
  18545 free(0x7f9049536680)

This log can be replayed with the logalloc-replay tool in
memory/replace/logalloc/replay. However, as the goal of that tool is to
reproduce the recorded memory allocations, it needs to avoid as much as
possible doing its own allocations for bookkeeping. Reading the logs as
they are would require data structures and memory allocations. As a
consequence, the logs need to be preprocessed beforehand.

The logalloc_munge.py script is responsible for that preprocessing. It simply
takes a raw log on its stdin, and outputs the preprocessed log on its stdout.
It replaces pointer addresses with indexes the logalloc-replay tool can use
in a large (almost) linear array of allocation tracking slots (prefixed with
'#'). It also replaces the pids with numbers starting from 1 (such as the
first seen pid number is 1, the second is 2, etc.).

The above example log would become the following, once preprocessed:
  1 malloc(32)=#1
  1 calloc(1,148)=#2
  1 realloc(#1,64)=#1
  1 posix_memalign(256,240)=#3
  1 jemalloc_stats()
  1 free(#1)

The logalloc-replay tool then takes the preprocessed log on its stdin and
replays the allocations printed there, but will only replay those with the
same process id as the first line (which normally is 1).

As the log files are simple text files, though, it is easy to separate out
the different processes log with e.g. grep, and feed the separate processes
logs to logalloc-replay.

The logalloc-replay program won't output anything unless jemalloc_stats
records appears in the log. You can expect those to be recorded when going
to about:memory in Firefox, but they can also be added after preprocessing.

Here is an example of what one can do:

  gunzip -c log.gz | python logalloc_munge.py | \
  awk '$1 == "2" { print $0 } !(NR % 10000) { print "2 jemalloc_stats()" }' | \
    ./logalloc-replay

The above command replays the allocations of process #2, with some stats
output every 10000 records.

The logalloc-replay tool itself being hooked with replace-malloc, it is possible
to set LD_PRELOAD/DYLD_INSERT_LIBRARIES/MOZ_REPLACE_MALLOC_LIB and replay a log
through a different allocator. For example:

  LD_PRELOAD=libreplace_jemalloc.so logalloc-replay < log

Will replay the log against jemalloc3 (which is, as of writing, what
libreplace_jemalloc.so contains).