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"
40 using StatGroupMap
= hphp_const_char_map
<hphp_const_char_map
<uint64_t>>;
42 RDS_LOCAL(StatCounters
, rl_counters
);
43 RDS_LOCAL(StatGroupMap
*, rl_stat_groups
);
46 if (!enabledAny()) return;
47 assertx(*rl_stat_groups
== nullptr);
48 *rl_stat_groups
= new StatGroupMap();
51 static RDS_LOCAL(int64_t, epoch
);
53 if (!enabledAny()) return;
55 auto url
= g_context
->getRequestUrl(50);
56 TRACE(0, "STATS %" PRId64
" %s\n", *epoch
, url
.c_str());
57 #include "hphp/runtime/vm/stats-opcodeDef.h"
59 if (!rl_counters->counters[s]) {} else \
60 TRACE(0, "STAT %-50s %15" PRId64 "\n", #s, rl_counters->counters[s]);
65 using StatPair
= std::pair
<const char*, uint64_t>;
66 for (auto const& group
: **rl_stat_groups
) {
68 auto const& map
= group
.second
;
69 uint64_t total
= 0, accum
= 0;
72 std::vector
<StatPair
> rows(map
.begin(), map
.end());
73 for (auto const& p
: rows
) {
74 nameWidth
= std::max(nameWidth
, strlen(p
.first
));
77 auto gt
= [](const StatPair
& a
, const StatPair
& b
) {
78 return a
.second
> b
.second
;
80 std::sort(rows
.begin(), rows
.end(), gt
);
82 folly::format(&stats
, "{:-^80}\n",
83 folly::format(" group {} ",group
.first
, url
));
85 folly::format("{{:>{}}} {{:>9}} {{:>8}} {{:>8}}\n",
87 "name", "count", "% total", "accum %");
89 static const auto maxGroupEnv
= getenv("HHVM_STATS_GROUPMAX");
90 static const auto maxGroup
= maxGroupEnv
? atoi(maxGroupEnv
) : INT_MAX
;
93 auto const fmt
= folly::format("{{:>{}}} : {{:9}} {{:8.2%}} {{:8.2%}}\n",
95 for (auto const& row
: rows
) {
97 folly::format(&stats
, fmt
, row
.first
, row
.second
,
98 (double)row
.second
/ total
, (double)accum
/ total
);
99 if (++counter
>= maxGroup
) break;
101 FTRACE(0, "{}\n", stats
);
106 if (!enabledAny()) return;
108 memset(&rl_counters
->counters
[0], 0, sizeof(rl_counters
->counters
));
110 assertx(*rl_stat_groups
);
111 delete *rl_stat_groups
;
112 *rl_stat_groups
= nullptr;
115 void incStatGrouped(const StringData
* category
, const StringData
* name
, int n
) {
116 assertx(*rl_stat_groups
);
117 (**rl_stat_groups
)[category
->data()][name
->data()] += n
;