Supported enregistered string and int keys in the vector translator
[hiphop-php.git] / src / runtime / vm / stats.cpp
blobac218a712d0fde8c3e72030edf232908cee274f3
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
16 #include <util/base.h>
17 #include <runtime/vm/translator/x64-util.h>
18 #include <runtime/vm/translator/translator-x64.h>
19 #include <runtime/vm/stats.h>
21 namespace HPHP {
22 namespace VM {
23 namespace Stats {
25 TRACE_SET_MOD(stats);
27 __thread uint64_t tl_counters[kNumStatCounters];
28 __thread uint64_t tl_helper_counters[kMaxNumTrampolines];
30 // Only the thread holding the write lease will set the entries in the
31 // helperNames array but other threads may concurrently read these
32 // entries, so each entry is volatile (or an atomic type per the new
33 // C++11 standard).
34 const char* volatile helperNames[kMaxNumTrampolines];
36 void
37 emitInc(Transl::X64Assembler& a,uint64_t* tl_table,uint index,int n) {
38 using namespace HPHP::VM::Transl;
39 uintptr_t virtualAddress = uintptr_t(&tl_table[index]) - tlsBase();
40 emitImmReg(a, virtualAddress, reg::rScratch);
41 a. fs();
42 a. add_imm64_disp_reg64(n, 0, reg::rScratch);
47 void emitInc(Transl::X64Assembler& a, StatCounter stat, int n /* = 1*/) {
48 if (!enabled()) return;
49 emitInc(a,&tl_counters[0],stat,n);
52 void emitIncTranslOp(Transl::X64Assembler& a, Opcode opc) {
53 if (!enableInstrCount()) return;
54 emitInc(a, &tl_counters[0], opcodeToTranslStatCounter(opc), 1);
57 static __thread int64 epoch;
58 void dump() {
59 if (!enabled()) return;
60 TRACE(1, "STATS %lld %s\n", epoch, g_context->getRequestUrl(50).c_str());
61 #include "runtime/vm/stats-opcodeDef.h"
62 #define STAT(s) \
63 if (tl_counters[s]) TRACE(1, "STAT %-50s %15ld\n", \
64 #s, tl_counters[s]);
65 STATS
66 #undef STAT
67 #undef O
68 for (int i=0; helperNames[i]; i++) {
69 if (tl_helper_counters[i]) {
70 TRACE(1, "STAT %-50s %15ld\n",
71 helperNames[i],
72 tl_helper_counters[i]);
77 void clear() {
78 if (!enabled()) return;
79 ++epoch;
80 memset(&tl_counters[0], 0, sizeof(tl_counters));
81 memset(&tl_helper_counters[0], 0, sizeof(tl_helper_counters));
84 } } }