<commit_before>/**
 * @file performance.js
 * @author <NAME>(<EMAIL>)
 */

define(function (require, exports, module) {

    var _ = require('underscore');
    var logger = require('./logger');
    var config = require('./config');
    var timeline = require('./performance/timeline');
    var memory = require('fc-storage/memory');

    var prefix = config.performanceTargetPrefix;

    var itemMap = {};

    /**
     * 计算性能
     * @param {string} itemKey 监控项名
     * @return {Object} exports 返回模块自身，供链式调用
     */
    exports.measure = function (itemKey) {
        if ('string' !== typeof itemKey) {
            return;
        }
        var item = itemMap[itemKey];
        if (!item || item.process.length === 0) {
            return;
        }
        var markNames = _.map(item.process, function (process) {
            return prefix + itemKey + '_' + process;
        });
        var performanceData = {};
        var measureList = _.chain(timeline.measure(
            [config.firstMark].concat(markNames)
        )).each(function (measure) {
            performanceData[measure.endMark] = measure.duration;
            // clear mark
            if (measure.endMark !== config.firstMark) {
                window.performance.clearMarks(measure.endMark);
            }
        }).value();
        performanceData[prefix + itemKey] = _.max(performanceData);

        var statis = {};
        statis[itemKey] = {
            measure: measureList,
            data: performanceData
        };
        memory.updateItem(config.storageKey, {
            performance: statis
        });

        // clear cached mark info
        delete itemMap[itemKey];

        // send performance log
        logger.log(
            _.extend({performanceId: config.performanceId}, performanceData),
            prefix + itemKey
        );
        return exports;
    };

    /**
     * 性能埋点
     * @param {string} itemKey 监控项名
     * @param {string} process 进度名
     *  为finish时表示该流程结束，开始计算性能
     * @return {Object} exports 返回模块自身，供链式调用
     */
    exports.mark = function (itemKey, process) {
        if ('string' !== typeof itemKey) {
            return;
        }
        itemMap[itemKey] = itemMap[itemKey] || {};
        var item = itemMap[itemKey];
        item.process = item.process || [];

        if ('string' !== typeof process<commit_msg>add field `pageStable` in performance log<commit_after>/**
 * @file performance.js
 * @author <NAME>(<EMAIL>)
 */

define(function (require, exports, module) {

    var _ = require('underscore');
    var logger = require('./logger');
    var config = require('./config');
    var recorder = require('./recorder');
    var timeline = require('./performance/timeline');
    var memory = require('fc-storage/memory');

    var prefix = config.performanceTargetPrefix;

    var itemMap = {};

    /**
     * 计算性能
     * @param {string} itemKey 监控项名
     * @return {Object} exports 返回模块自身，供链式调用
     */
    exports.measure = function (itemKey) {
        if ('string' !== typeof itemKey) {
            return;
        }
        var item = itemMap[itemKey];
        if (!item || item.process.length === 0) {
            return;
        }
        var markNames = _.map(item.process, function (process) {
            return prefix + itemKey + '_' + process;
        });
        var performanceData = {};
        var measureList = _.chain(timeline.measure(
            [config.firstMark].concat(markNames)
        )).each(function (measure) {
            performanceData[measure.endMark] = measure.duration;
            // clear mark
            if (measure.endMark !== config.firstMark) {
                window.performance.clearMarks(measure.endMark);
            }
        }).value();
        performanceData[prefix + itemKey] = _.max(performanceData);

        var statis = {};
        statis[itemKey] = {
            measure: measureList,
            data: performanceData
        };
        memory.updateItem(config.storageKey, {
            performance: statis
        });

        // clear cached mark info
        delete itemMap[itemKey];

        // send performance log
        logger.log(
            _.extend(
                {
                    performanceId: config.performanceId,
                    pageStabled: recorder.stable ? 1 : 0
                },
                performanceData
            ),
            prefix + itemKey
        );
        return exports;
    };

    /**
     * 性能埋点
     * @param {string} itemKey 监控项名
     * @param {string} process 进度名
     *  为finish时表示该流程结束，开始计算性能
     * @return {Object} exports 返回模块自身，供链式调用
     */
    exports.mark = function (itemKey, process) {
        if ('string' !== typeof itemKey) {
            return;
        }
        itemMap[itemKey] = itemMap[itemKey] || {};
        var item = itemMap[itemKey];
        item.process = item.process || [];

        if ('string' !== typeof process
{'fraction_non_alphanumeric': 0.1278118609406953, 'fraction_numerical': 0.0008179959100204499, 'mean_word_length': 1.8386535113174696, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4396303', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1408, 'n_words': 298}