Use folly::dynamic::object and folly::dynamic::string exclusivly
[hiphop-php.git] / hphp / runtime / base / debuggable.cpp
blob756c41d559cb702517295163fc8d58862dbad974
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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/server/server-stats.h"
20 namespace HPHP {
21 ///////////////////////////////////////////////////////////////////////////////
23 std::string IDebuggable::FormatNumber(const char *fmt, int64_t n) {
24 char buf[64];
25 snprintf(buf, sizeof(buf), fmt, n);
26 return buf;
29 std::string IDebuggable::FormatSize(int64_t size) {
30 char buf[64];
31 double n = size;
32 if (n >= 1024) {
33 n /= 1024;
34 if (n >= 1024) {
35 n /= 1024;
36 if (n >= 1024) {
37 n /= 1024;
38 snprintf(buf, sizeof(buf), "%" PRId64" bytes (%.2fG)", size, n);
39 } else {
40 snprintf(buf, sizeof(buf), "%" PRId64" bytes (%.2fM)", size, n);
42 } else {
43 snprintf(buf, sizeof(buf), "%" PRId64" bytes (%.2fk)", size, n);
45 } else {
46 snprintf(buf, sizeof(buf), "%" PRId64" bytes", size);
48 return buf;
51 std::string IDebuggable::FormatTime(int64_t milliSeconds) {
52 char buf[64];
53 double n = milliSeconds;
54 if (n >= 1000) {
55 n /= 1000;
56 if (n >= 60) {
57 n /= 60;
58 if (n >= 60) {
59 n /= 60;
60 snprintf(buf, sizeof(buf), "%" PRId64 " ms (%.2f hrs)", milliSeconds, n);
61 } else {
62 snprintf(buf, sizeof(buf), "%" PRId64 " ms (%.2f min)", milliSeconds, n);
64 } else {
65 snprintf(buf, sizeof(buf), "%" PRId64 " ms (%.2f sec)", milliSeconds, n);
67 } else {
68 snprintf(buf, sizeof(buf), "%" PRId64 " ms", milliSeconds);
70 return buf;
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 ///////////////////////////////////////////////////////////////////////////////