Changeset 34371 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Jun 4, 2008, 9:39:09 PM (17 years ago)
Author:
[email protected]
Message:

2008-06-04 Cameron Zwarich <[email protected]>

Reviewed by Oliver.

Add an option to dump statistics on executed instructions.

JavaScriptCore:

  • VM/Machine.cpp: (KJS::Machine::privateExecute):
  • VM/Opcode.cpp: (KJS::): (KJS::OpcodeStats::~OpcodeStats): (KJS::OpcodeStats::recordInstruction):
  • VM/Opcode.h:

WebKitTools:

  • Scripts/check-for-global-initializers:
Location:
trunk/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r34362 r34371  
     12008-06-04  Cameron Zwarich  <[email protected]>
     2
     3        Reviewed by Oliver.
     4
     5        Add an option to dump statistics on executed instructions.
     6
     7        * VM/Machine.cpp:
     8        (KJS::Machine::privateExecute):
     9        * VM/Opcode.cpp:
     10        (KJS::):
     11        (KJS::OpcodeStats::~OpcodeStats):
     12        (KJS::OpcodeStats::recordInstruction):
     13        * VM/Opcode.h:
     14
    1152008-06-04  Kevin McCullough  <[email protected]>
    216
  • trunk/JavaScriptCore/VM/Machine.cpp

    r34355 r34371  
    909909#if HAVE(COMPUTED_GOTO)
    910910    #define NEXT_OPCODE goto *vPC->u.opcode
     911#if DUMP_OPCODE_STATS
     912    #define BEGIN_OPCODE(opcode) opcode: OpcodeStats::recordInstruction(opcode);
     913#else
    911914    #define BEGIN_OPCODE(opcode) opcode:
     915#endif
    912916    NEXT_OPCODE;
    913917#else
    914918    #define NEXT_OPCODE continue
     919#if DUMP_OPCODE_STATS
     920    #define BEGIN_OPCODE(opcode) case opcode: OpcodeStats::recordInstruction(opcode);
     921#else
    915922    #define BEGIN_OPCODE(opcode) case opcode:
     923#endif
    916924    while(1) // iterator loop begins
    917925    switch (vPC->u.opcode)
  • trunk/JavaScriptCore/VM/Opcode.cpp

    r33979 r34371  
    11/*
    22 * Copyright (C) 2008 Apple Inc. All rights reserved.
     3 * Copyright (C) 2008 Cameron Zwarich <[email protected]>
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2930#include "Opcode.h"
    3031
     32namespace KJS {
     33
     34#if DUMP_OPCODE_STATS
     35
     36unsigned OpcodeStats::opcodeCounts[numOpcodeIDs];
     37
     38static OpcodeStats logger;
     39
     40static const char* opcodeNames[] = {
     41    "load",
     42    "new_object",
     43    "new_array",
     44    "new_regexp",
     45    "mov",
     46   
     47    "not",
     48    "eq",
     49    "neq",
     50    "stricteq",
     51    "nstricteq",
     52    "less",
     53    "lesseq",
     54   
     55    "pre_inc",
     56    "pre_dec",
     57    "post_inc",
     58    "post_dec",
     59    "to_jsnumber",
     60    "negate",
     61    "add",
     62    "mul",
     63    "div",
     64    "mod",
     65    "sub",
     66   
     67    "lshift",
     68    "rshift",
     69    "urshift",
     70    "bitand",
     71    "bitxor",
     72    "bitor",
     73    "bitnot",
     74   
     75    "instanceof",
     76    "typeof",
     77    "in",
     78
     79    "resolve",
     80    "resolve_skip",
     81    "get_scoped_var",
     82    "put_scoped_var",
     83    "resolve_base",
     84    "resolve_with_base",
     85    "resolve_func",
     86    "get_by_id",
     87    "put_by_id",
     88    "del_by_id",
     89    "get_by_val",
     90    "put_by_val",
     91    "del_by_val",
     92    "put_by_index",
     93    "put_getter",
     94    "put_setter",
     95
     96    "jmp",
     97    "jtrue",
     98    "jfalse",
     99    "jmp_scopes",
     100
     101    "new_func",
     102    "new_func_exp",
     103    "call",
     104    "call_eval",
     105    "ret",
     106
     107    "construct",
     108
     109    "get_pnames",
     110    "next_pname",
     111
     112    "push_scope",
     113    "pop_scope",
     114
     115    "catch",
     116    "throw",
     117    "new_error",
     118
     119    "jsr",
     120    "sret",
     121
     122    "debug",
     123
     124    "end"   
     125};
     126
     127OpcodeStats::OpcodeStats()
     128{
     129    for (int i = 0; i < numOpcodeIDs; ++i)
     130        opcodeCounts[i] = 0;
     131}
     132
     133OpcodeStats::~OpcodeStats()
     134{
     135    int totalInstructions = 0;
     136    int sortedIndices[numOpcodeIDs];
     137   
     138    for (int i = 0; i < numOpcodeIDs; ++i) {
     139        totalInstructions += opcodeCounts[i];
     140        sortedIndices[i] = i;
     141    }
     142       
     143    for (int i = 0; i < numOpcodeIDs - 1; ++i) {
     144        int max = i;
     145       
     146        for (int j = i + 1; j < numOpcodeIDs; ++j) {
     147            if (opcodeCounts[sortedIndices[j]] > opcodeCounts[sortedIndices[max]])
     148                max = j;
     149        }
     150       
     151        int temp = sortedIndices[i];
     152        sortedIndices[i] = sortedIndices[max];
     153        sortedIndices[max] = temp;
     154    }
     155 
     156    printf("\nExecuted opcode statistics:\n\n");
     157   
     158    printf("Total instructions executed: %d\n\n", totalInstructions);
     159
     160    for (int i = 0; i < numOpcodeIDs; ++i) {
     161        int index = sortedIndices[i];
     162        printf("%s: %.2f%%\n", opcodeNames[index], ((double) opcodeCounts[index]) / ((double) totalInstructions) * 100.0);   
     163    }
     164   
     165    printf("\n");
     166}
     167
     168void OpcodeStats::recordInstruction(int opcode)
     169{
     170    opcodeCounts[opcode]++;
     171}
     172
     173#endif
     174
     175} // namespace WTF
  • trunk/JavaScriptCore/VM/Opcode.h

    r33979 r34371  
    3434
    3535namespace KJS {
    36        
     36
     37#define DUMP_OPCODE_STATS 0
     38
    3739    #define FOR_EACH_OPCODE_ID(macro) \
    3840        macro(op_load) \
     
    137139#endif
    138140
     141#if DUMP_OPCODE_STATS
     142
     143    struct OpcodeStats {
     144        OpcodeStats();
     145        ~OpcodeStats();
     146        static unsigned opcodeCounts[numOpcodeIDs];
     147        static void recordInstruction(int opcode);
     148    };
     149
     150#endif
     151
    139152} // namespace KJS
    140153
Note: See TracChangeset for help on using the changeset viewer.