<commit_before>/* See license.txt for terms of usage */

FBL.ns(function() {

// ********************************************************************************************* //

var Cc = Components.classes;
var Ci = Components.interfaces;

var RETURN_CONTINUE = Ci.jsdIExecutionHook.RETURN_CONTINUE;

var memoryReporterManager = Cc["@mozilla.org/memory-reporter-manager;1"].
    getService(Ci.nsIMemoryReporterManager);

// List of memory reports displayed in the result. Append new path in the list in order
// to create a new columnd in the result report.
var MEMORY_PATHS =
{
    "malloc/allocated": true,
    "js/gc-heap": true,
    "js/string-data": true,
    "js/mjit-code": true,
    "images/content/used/raw": true,
};

// ********************************************************************************************* //

Firebug.MemoryProfiler = FBL.extend(Firebug.Module,
{
    initialize: function()  // called once
    {
        Firebug.Module.initialize.apply(this, arguments);

        if (FBTrace.DBG_MEMORY_PROFILER)
            FBTrace.sysout("memoryProfiler; initialize");
    },

    shutdown: function()
    {
        Firebug.Module.shutdown.apply(this, arguments);
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // Activation/deactivation

    toggleProfiling: function(context)
    {
        try
        {
            if (context.memoryProfiling)
                this.stop(context);
            else
                this.start(context);
        }
        catch (err)
        {
            if (FBTrace.DBG_ERRORS)
                FBTrace.sysout("memoryProfiler; toggleProfiling EXCEPTION " + err, err);
        }
    },

    start: function(context)
    {
        context.memoryProfiling = true;
        FBL.fbs.addHandler(this);

        // Initialize structures for collected memory data.
        context.memoryProfileStack = []; // Holds memory reports for called fucntions.
        context.memoryProfileResult = {}; // Holds differences between function-call and function-return.
        context.memoryProfileTime = (new Date()).getTime();

        this.mark(context);

        var title = FBL.$STR("Memory Profiler Started");
        var row = this.logProfileRow(context, title);

        context.memoryProfileRow = row;
        context.memoryProfileRow.customMessage = false;

        // For summary numbers (difference between profiling-start and profiling-end)
        context.memoryProfileStack.push(this.getMemoryReport());
    },

    stop: function(context)
    {
        FBL.fbs.removeHandler(this);
        context.memoryProfiling = false;

        // Calculate total diff
        var oldReport = context.memoryProfileStack.pop();
        var newReport = this.getMemoryReport();

        context.memoryProfileSummary = this.diffMemoryReport(oldReport, newReport);
        context.memoryProfileTime = (new Date()).getTime() - context.memoryProfileTime;

        this.logProfileReport(context, context.memoryProfileResult);

        delete context.memoryProfileRow;
        delete context.memoryProfileStack;
        delete context.memoryProfileResult;

        var deltaObjects = this.sweep(context);

        //Firebug.Console.log(deltaObjects, context, "memoryDelta", Firebug.DOMPanel.DirTable);<commit_msg>[1.8] Initial support for page load memory profiling.<commit_after>/* See license.txt for terms of usage */

FBL.ns(function() {

// ********************************************************************************************* //

var Cc = Components.classes;
var Ci = Components.interfaces;

var RETURN_CONTINUE = Ci.jsdIExecutionHook.RETURN_CONTINUE;

var memoryReporterManager = Cc["@mozilla.org/memory-reporter-manager;1"].
    getService(Ci.nsIMemoryReporterManager);

// List of memory reports displayed in the result. Append new path in the list in order
// to create a new columnd in the result report.
var MEMORY_PATHS =
{
    "malloc/allocated": true,
    "js/gc-heap": true,
    "js/string-data": true,
    "js/mjit-code": true,
    "images/content/used/raw": true,
};

// ********************************************************************************************* //

Firebug.MemoryProfiler = FBL.extend(Firebug.Module,
{
    initialize: function()  // called once
    {
        Firebug.Module.initialize.apply(this, arguments);

        if (FBTrace.DBG_MEMORY_PROFILER)
            FBTrace.sysout("memoryProfiler; initialize");
    },

    shutdown: function()
    {
        Firebug.Module.shutdown.apply(this, arguments);
    },

    initContext: function(context)
    {
        Firebug.Module.initContext.apply(this, arguments);

        // xxxHonza: If profiling is on and the user reloads,needs better testing
        // Profilinig should support reloads to profile page load.
        if (this.profiling)
            this.start(context);
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // Activation/deactivation

    toggleProfiling: function(context)
    {
        try
        {
            if (this.profiling)
                this.stop(context);
            else
                this.start(context);
        }
        catch (err)
        {
            if (FBTrace.DBG_ERRORS)
                FBTrace.sysout("memoryProfiler; toggleProfiling EXCEPTION " + err, err);
        }
    },

    isProfiling: function()
    {
        return this.profiling;
    },

    start: function(context)
    {
        this.profiling = true;
        FBL.fbs.addHandler(this);

        // Initialize structures for collected memory data.
        context.memoryProfileStack = []; // Holds memory reports for called fucntions.
        context.memoryProfileResult = {}; // Holds differences between function-call and function-return.
        context.memoryProfileTime = (new Date()).getTime();

        this.mark(context);

        var title = FBL.$STR("Memory Profiler Started");
        var row = this.logProfileRow(context, title);

        context.memoryProfileRow = row;
        context.memoryProfileRow.customMessage = false;

        // For summary numbers (difference between profiling-start and profiling-end)
        context.memoryProfileStack.push(this.getMemoryReport());
    },

    stop: function(context)
    {
        FBL.fbs.removeHandler(this);
        this.profiling = false;

        // Calculate total diff
        var oldReport = context.memoryProfileStack.pop();
        var newReport = this.getMemoryReport();

        context.memoryProfileSummary = this.diffMemoryReport(oldReport, newReport);
        context.memoryProfileTime = (new Date()).getTime() - context.memoryProfileTime;

        this.logProfileReport(context, context.memoryProfileResult);

        delete context.memoryProfileRow;
        delete context.memoryProfileStack;
        delete context.memoryProfileResult;

        var deltaObjects = this.sweep(context);

        //Firebug.Console.log(deltaObjects, context, "memoryDelta", Firebug.DOMPanel.DirTable);
{'fraction_non_alphanumeric': 0.16621563879789203, 'fraction_numerical': 0.0005697194131890044, 'mean_word_length': 2.6534859521331944, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1204307', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1911, 'n_words': 394}