2 +----------------------------------------------------------------------+
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 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/debuggable.h"
18 #include "hphp/runtime/base/server/server_stats.h"
21 ///////////////////////////////////////////////////////////////////////////////
23 std::string
IDebuggable::FormatNumber(const char *fmt
, int64_t n
) {
25 snprintf(buf
, sizeof(buf
), fmt
, n
);
29 std::string
IDebuggable::FormatSize(int64_t size
) {
38 snprintf(buf
, sizeof(buf
), "%" PRId64
" bytes (%.2fG)", size
, n
);
40 snprintf(buf
, sizeof(buf
), "%" PRId64
" bytes (%.2fM)", size
, n
);
43 snprintf(buf
, sizeof(buf
), "%" PRId64
" bytes (%.2fk)", size
, n
);
46 snprintf(buf
, sizeof(buf
), "%" PRId64
" bytes", size
);
51 std::string
IDebuggable::FormatTime(int64_t milliSeconds
) {
53 double n
= milliSeconds
;
60 snprintf(buf
, sizeof(buf
), "%" PRId64
" ms (%.2f hrs)", milliSeconds
, n
);
62 snprintf(buf
, sizeof(buf
), "%" PRId64
" ms (%.2f min)", milliSeconds
, n
);
65 snprintf(buf
, sizeof(buf
), "%" PRId64
" ms (%.2f sec)", milliSeconds
, n
);
68 snprintf(buf
, sizeof(buf
), "%" PRId64
" ms", milliSeconds
);
73 ///////////////////////////////////////////////////////////////////////////////
75 void IDebuggable::Add(InfoVec
&out
, const char *name
,
76 const std::string
&value
) {
77 out
.push_back(InfoEntry(name
, value
));
80 void IDebuggable::AddServerStats(InfoVec
&out
, const char *name
,
81 const char *statsName
/* = NULL */) {
82 if (statsName
== nullptr) statsName
= name
;
83 Add(out
, name
, FormatNumber("%" PRId64
, ServerStats::Get(statsName
)));
86 ///////////////////////////////////////////////////////////////////////////////