2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present 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 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/stats.h"
23 #include "hphp/runtime/base/execution-context.h"
24 #include "hphp/runtime/base/string-data.h"
25 #include "hphp/util/data-block.h"
32 const char* g_counterNames
[] = {
33 #include "hphp/runtime/vm/stats-opcodeDef.h"
39 __thread
uint64_t tl_counters
[kNumStatCounters
];
41 typedef hphp_const_char_map
<hphp_const_char_map
<uint64_t>> StatGroupMap
;
42 __thread StatGroupMap
* tl_stat_groups
= nullptr;
45 if (!enabledAny()) return;
46 assert(tl_stat_groups
== nullptr);
47 tl_stat_groups
= new StatGroupMap();
50 static __thread
int64_t epoch
;
52 if (!enabledAny()) return;
54 auto url
= g_context
->getRequestUrl(50);
55 TRACE(0, "STATS %" PRId64
" %s\n", epoch
, url
.c_str());
56 #include "hphp/runtime/vm/stats-opcodeDef.h"
58 if (!tl_counters[s]) {} else \
59 TRACE(0, "STAT %-50s %15" PRId64 "\n", #s, tl_counters[s]);
64 typedef std::pair
<const char*, uint64_t> StatPair
;
65 for (auto const& group
: *tl_stat_groups
) {
67 auto const& map
= group
.second
;
68 uint64_t total
= 0, accum
= 0;
71 std::vector
<StatPair
> rows(map
.begin(), map
.end());
72 for (auto const& p
: rows
) {
73 nameWidth
= std::max(nameWidth
, strlen(p
.first
));
76 auto gt
= [](const StatPair
& a
, const StatPair
& b
) {
77 return a
.second
> b
.second
;
79 std::sort(rows
.begin(), rows
.end(), gt
);
81 folly::format(&stats
, "{:-^80}\n",
82 folly::format(" group {} ",group
.first
, url
));
84 folly::format("{{:>{}}} {{:>9}} {{:>8}} {{:>8}}\n",
86 "name", "count", "% total", "accum %");
88 static const auto maxGroupEnv
= getenv("HHVM_STATS_GROUPMAX");
89 static const auto maxGroup
= maxGroupEnv
? atoi(maxGroupEnv
) : INT_MAX
;
92 auto const fmt
= folly::format("{{:>{}}} : {{:9}} {{:8.2%}} {{:8.2%}}\n",
94 for (auto const& row
: rows
) {
96 folly::format(&stats
, fmt
, row
.first
, row
.second
,
97 (double)row
.second
/ total
, (double)accum
/ total
);
98 if (++counter
>= maxGroup
) break;
100 FTRACE(0, "{}\n", stats
);
105 if (!enabledAny()) return;
107 memset(&tl_counters
[0], 0, sizeof(tl_counters
));
109 assert(tl_stat_groups
);
110 delete tl_stat_groups
;
111 tl_stat_groups
= nullptr;
114 void incStatGrouped(const StringData
* category
, const StringData
* name
, int n
) {
115 assert(tl_stat_groups
);
116 (*tl_stat_groups
)[category
->data()][name
->data()] += n
;