Changeset 202650 in webkit


Ignore:
Timestamp:
Jun 29, 2016 3:00:02 PM (8 years ago)
Author:
mark.lam@apple.com
Message:

Add support for collecting cumulative LLINT stats via a JSC_llintStatsFile option.
https://bugs.webkit.org/show_bug.cgi?id=159274

Reviewed by Keith Miller.

Source/JavaScriptCore:

  • jsc.cpp:

(main):

  • llint/LLIntData.cpp:

(JSC::LLInt::initialize):
(JSC::LLInt::Data::finalizeStats):
(JSC::LLInt::compareStats):
(JSC::LLInt::Data::dumpStats):
(JSC::LLInt::Data::ensureStats):
(JSC::LLInt::Data::loadStats):
(JSC::LLInt::Data::resetStats):
(JSC::LLInt::Data::saveStats):

  • llint/LLIntData.h:

(JSC::LLInt::Data::opcodeStats):

  • runtime/Options.cpp:

(JSC::Options::isAvailable):
(JSC::recomputeDependentOptions):
(JSC::Options::initialize):

  • runtime/Options.h:

Tools:

  • DumpRenderTree/mac/DumpRenderTree.mm:

(DumpRenderTreeMain):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r202648 r202650  
     12016-06-29  Mark Lam  <mark.lam@apple.com>
     2
     3        Add support for collecting cumulative LLINT stats via a JSC_llintStatsFile option.
     4        https://bugs.webkit.org/show_bug.cgi?id=159274
     5
     6        Reviewed by Keith Miller.
     7
     8        * jsc.cpp:
     9        (main):
     10        * llint/LLIntData.cpp:
     11        (JSC::LLInt::initialize):
     12        (JSC::LLInt::Data::finalizeStats):
     13        (JSC::LLInt::compareStats):
     14        (JSC::LLInt::Data::dumpStats):
     15        (JSC::LLInt::Data::ensureStats):
     16        (JSC::LLInt::Data::loadStats):
     17        (JSC::LLInt::Data::resetStats):
     18        (JSC::LLInt::Data::saveStats):
     19        * llint/LLIntData.h:
     20        (JSC::LLInt::Data::opcodeStats):
     21        * runtime/Options.cpp:
     22        (JSC::Options::isAvailable):
     23        (JSC::recomputeDependentOptions):
     24        (JSC::Options::initialize):
     25        * runtime/Options.h:
     26
    1272016-06-29  Saam barati  <sbarati@apple.com>
    228
  • trunk/Source/JavaScriptCore/jsc.cpp

    r202588 r202650  
    19861986        HeapStatistics::reportSuccess();
    19871987    if (Options::reportLLIntStats())
    1988         LLInt::Data::dumpStats();
     1988        LLInt::Data::finalizeStats();
    19891989
    19901990#if PLATFORM(EFL)
  • trunk/Source/JavaScriptCore/llint/LLIntData.cpp

    r202131 r202650  
    11/*
    2  * Copyright (C) 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030#include "CodeBlock.h"
    3131#include "CodeType.h"
     32#include "InitializeThreading.h"
    3233#include "Instruction.h"
    3334#include "JSScope.h"
     
    3940#include "ShadowChicken.h"
    4041#include "WriteBarrier.h"
     42#include <string>
     43#include <wtf/NeverDestroyed.h>
    4144
    4245#define STATIC_ASSERT(cond) static_assert(cond, "LLInt assumes " #cond)
     
    6871
    6972#if ENABLE(LLINT_STATS)
    70     Data::s_opcodeStatsArray = new OpcodeStatsArray();
    71     unsigned i = 0;
    72     for (auto& stats : *Data::s_opcodeStatsArray)
    73         stats.id = static_cast<OpcodeID>(i++);
     73    Data::ensureStats();
    7474#endif
    7575}
     
    229229#endif
    230230
    231 void Data::dumpStats()
     231void Data::finalizeStats()
    232232{
    233233#if ENABLE(LLINT_STATS)
    234234    if (!Options::reportLLIntStats())
    235235        return;
    236 
     236   
     237    if (Options::llintStatsFile())
     238        saveStats();
     239   
     240    dumpStats();
     241#endif
     242}
     243
     244#if ENABLE(LLINT_STATS)
     245static const bool verboseStats = false;
     246
     247static bool compareStats(const OpcodeStats& a, const OpcodeStats& b)
     248{
     249    if (a.count > b.count)
     250        return true;
     251    if (a.count < b.count)
     252        return false;
     253    return a.slowPathCount > b.slowPathCount;
     254}
     255
     256void Data::dumpStats()
     257{
     258    ASSERT(Options::reportLLIntStats());
    237259    auto statsCopy = *s_opcodeStatsArray;
    238     std::sort(statsCopy.begin(), statsCopy.end(), [] (OpcodeStats& a, OpcodeStats& b) -> bool {
    239         if (a.count > b.count)
    240             return true;
    241         if (a.count < b.count)
    242             return false;
    243         return a.slowPathCount > b.slowPathCount;
    244     });
    245    
     260    std::sort(statsCopy.begin(), statsCopy.end(), compareStats);
     261
    246262    dataLog("Opcode stats:\n");
    247263    unsigned i = 0;
    248264    for (auto& stats : statsCopy) {
    249         if (stats.count)
     265        if (stats.count || stats.slowPathCount)
    250266            dataLog("   [", i++, "]: fast:", stats.count, " slow:", stats.slowPathCount, " ", opcodeNames[stats.id], "\n");
    251267    }
    252 #endif
    253 }
    254 
     268}
     269
     270void Data::ensureStats()
     271{
     272    static std::once_flag initializeOptionsOnceFlag;
     273    std::call_once(initializeOptionsOnceFlag, [] {
     274        s_opcodeStatsArray = new OpcodeStatsArray();
     275        resetStats();
     276    });
     277}
     278
     279void Data::loadStats()
     280{
     281    static NeverDestroyed<std::string> installedStatsFile;
     282    if (!Options::llintStatsFile() || !installedStatsFile.get().compare(Options::llintStatsFile()))
     283        return;
     284
     285    Options::reportLLIntStats() = true; // Force stats collection.
     286    installedStatsFile.get() = Options::llintStatsFile();
     287
     288    ensureStats();
     289
     290    const char* filename = Options::llintStatsFile();
     291    FILE* file = fopen(filename, "r");
     292    if (!file) {
     293        dataLogF("Failed to open file %s. Did you add the file-read-write-data entitlement to WebProcess.sb?\n", filename);
     294        return;
     295    }
     296
     297    resetStats();
     298
     299    OpcodeStats loaded;
     300    unsigned index;
     301    char opcodeName[100];
     302    while (fscanf(file, "[%u]: fast:%zu slow:%zu id:%u %s\n", &index, &loaded.count, &loaded.slowPathCount, &loaded.id, opcodeName) != EOF) {
     303        if (verboseStats)
     304            dataLogF("loaded [%u]: fast %zu slow %zu id:%u %s\n", index, loaded.count, loaded.slowPathCount, loaded.id, opcodeName);
     305
     306        OpcodeStats& stats = opcodeStats(loaded.id);
     307        stats.count = loaded.count;
     308        stats.slowPathCount = loaded.slowPathCount;
     309    }
     310
     311    if (verboseStats) {
     312        dataLogF("After loading from %s, ", filename);
     313        dumpStats();
     314    }
     315
     316    int result = fclose(file);
     317    if (result)
     318        dataLogF("Failed to close file %s: %s\n", filename, strerror(errno));
     319}
     320
     321void Data::resetStats()
     322{
     323    unsigned i = 0;
     324    for (auto& stats : *s_opcodeStatsArray) {
     325        stats.id = static_cast<OpcodeID>(i++);
     326        stats.count = 0;
     327        stats.slowPathCount = 0;
     328    }
     329}
     330
     331void Data::saveStats()
     332{
     333    ASSERT(Options::reportLLIntStats() && Options::llintStatsFile());
     334    const char* filename = Options::llintStatsFile();
     335
     336    FILE* file = fopen(filename, "w");
     337    if (!file) {
     338        dataLogF("Failed to open file %s. Did you add the file-read-write-data entitlement to WebProcess.sb?\n", filename);
     339        return;
     340    }
     341
     342    auto statsCopy = *s_opcodeStatsArray;
     343    std::sort(statsCopy.begin(), statsCopy.end(), compareStats);
     344
     345    int index = 0;
     346    for (auto& stats : statsCopy) {
     347        if (!stats.count && !stats.slowPathCount)
     348            break; // stats are sorted. If we encountered 0 counts, then there are no more non-zero counts.
     349
     350        if (verboseStats)
     351            dataLogF("saved [%u]: fast:%zu slow:%zu id:%u %s\n", index, stats.count, stats.slowPathCount, stats.id, opcodeNames[stats.id]);
     352
     353        fprintf(file, "[%u]: fast:%zu slow:%zu id:%u %s\n", index, stats.count, stats.slowPathCount, stats.id, opcodeNames[stats.id]);
     354        index++;
     355    }
     356
     357    int result = fclose(file);
     358    if (result)
     359        dataLogF("Failed to close file %s: %s\n", filename, strerror(errno));
     360}
     361#endif
    255362
    256363} } // namespace JSC::LLInt
  • trunk/Source/JavaScriptCore/llint/LLIntData.h

    r202131 r202650  
    11/*
    2  * Copyright (C) 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5757    static OpcodeStats& opcodeStats(OpcodeID id) { return (*s_opcodeStatsArray)[id]; }
    5858
    59     JS_EXPORT_PRIVATE static void dumpStats();
     59    JS_EXPORT_PRIVATE static void finalizeStats();
     60
     61    static void dumpStats();
     62    static void loadStats();
    6063
    6164private:
     65    static void ensureStats();
     66    static void resetStats();
     67    static void saveStats();
     68
    6269    static Instruction* s_exceptionInstructions;
    6370    static Opcode s_opcodeMap[numOpcodeIDs];
  • trunk/Source/JavaScriptCore/runtime/Options.cpp

    r202402 r202650  
    11/*
    2  * Copyright (C) 2011-2012, 2014-2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011-2012, 2014-2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828
    2929#include "LLIntCommon.h"
     30#include "LLIntData.h"
    3031#include <algorithm>
    3132#include <limits>
     
    133134    UNUSED_PARAM(id);
    134135#if ENABLE(LLINT_STATS)
    135     if (id == reportLLIntStatsID)
     136    if (id == reportLLIntStatsID || id == llintStatsFileID)
    136137        return true;
    137138#endif
     
    390391    ASSERT((static_cast<int64_t>(Options::thresholdForOptimizeAfterLongWarmUp()) << Options::reoptimizationRetryCounterMax()) <= static_cast<int64_t>(std::numeric_limits<int32_t>::max()));
    391392    ASSERT(Options::deferGCProbability() >= 0.0 && Options::deferGCProbability() <= 1.0);
     393
     394#if ENABLE(LLINT_STATS)
     395    LLInt::Data::loadStats();
     396#endif
    392397}
    393398
     
    438443#endif
    439444   
    440             recomputeDependentOptions();
    441 
    442445#if USE(OPTIONS_FILE)
    443446            {
     
    464467            }
    465468#endif
     469
     470            recomputeDependentOptions();
    466471
    467472            // Do range checks where needed and make corrections to the options:
  • trunk/Source/JavaScriptCore/runtime/Options.h

    r202402 r202650  
    376376    v(bool, useSuperSampler, false, Normal, nullptr) \
    377377    \
    378     v(bool, reportLLIntStats, false, Configurable, "Reports LLInt statistics")
     378    v(bool, reportLLIntStats, false, Configurable, "Reports LLInt statistics") \
     379    v(optionString, llintStatsFile, nullptr, Configurable, "File to collect LLInt statistics in") \
    379380
    380381enum OptionEquivalence {
  • trunk/Tools/ChangeLog

    r202640 r202650  
     12016-06-29  Mark Lam  <mark.lam@apple.com>
     2
     3        Add support for collecting cumulative LLINT stats via a JSC_llintStatsFile option.
     4        https://bugs.webkit.org/show_bug.cgi?id=159274
     5
     6        Reviewed by Keith Miller.
     7
     8        * DumpRenderTree/mac/DumpRenderTree.mm:
     9        (DumpRenderTreeMain):
     10
    1112016-06-29  Alex Christensen  <achristensen@webkit.org>
    212
  • trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm

    r202020 r202650  
    14451445        JSC::HeapStatistics::reportSuccess();
    14461446    if (JSC::Options::reportLLIntStats())
    1447         JSC::LLInt::Data::dumpStats();
     1447        JSC::LLInt::Data::finalizeStats();
    14481448    [pool release];
    14491449    returningFromMain = true;
Note: See TracChangeset for help on using the changeset viewer.