Add structs for holding heap profile dumps

These structs will eventually hold the heap profiling data
for PHP request heaps, so that it can be gathered and displayed
using the pprof tool.

This was tested by layering the smart allocator stuff on top and
making sure everything worked as planned. Nothing uses the structs
in this diff, so it's kind of difficult to test otherwise.
Esse commit está contido em:
Eric Caruso
2013-07-24 13:49:33 -07:00
commit de Sara Golemon
commit a06d5fcbdf
+66
Ver Arquivo
@@ -0,0 +1,66 @@
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef incl_HPHP_PROFILE_DUMP_H_
#define incl_HPHP_PROFILE_DUMP_H_
#include "hphp/runtime/vm/srckey.h"
namespace HPHP {
// A StackTrace is represented by SrcKeys, which uniquely identify logical
// source locations. The lowermost stack frame recorded should go in the
// lowest index of the vector.
typedef std::vector<SrcKey> ProfileStackTrace;
// pprof format requires us to keep track of the number of live objects
// (or total in the accumulative case), and the number of bytes they occupy.
struct SiteAllocations {
size_t m_count;
size_t m_bytes;
};
// Allocation data for each stack trace. pprof wants both what is currently
// being used and what was allocated across the lifetime of the heap.
struct ProfileDump {
void clear() {
m_currentlyAllocated.clear();
m_accumAllocated.clear();
}
void addAlloc(size_t size, const ProfileStackTrace &trace) {
auto &current = m_currentlyAllocated[trace];
current.m_count++;
current.m_bytes += size;
auto &accum = m_accumAllocated[trace];
accum.m_count++;
accum.m_bytes += size;
}
void removeAlloc(size_t size, const ProfileStackTrace &trace) {
auto &current = m_currentlyAllocated[trace];
current.m_count--;
current.m_bytes -= size;
assert(current.m_count >= 0 && current.m_bytes >= 0);
}
private:
std::map<ProfileStackTrace, SiteAllocations> m_currentlyAllocated;
std::map<ProfileStackTrace, SiteAllocations> m_accumAllocated;
};
}
#endif // incl_HPHP_PROFILE_DUMP_H_