diff --git a/hphp/runtime/base/profile_dump.h b/hphp/runtime/base/profile_dump.h new file mode 100644 index 000000000..10763dd96 --- /dev/null +++ b/hphp/runtime/base/profile_dump.h @@ -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 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 ¤t = 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 ¤t = m_currentlyAllocated[trace]; + current.m_count--; + current.m_bytes -= size; + assert(current.m_count >= 0 && current.m_bytes >= 0); + } + +private: + std::map m_currentlyAllocated; + std::map m_accumAllocated; +}; + +} + +#endif // incl_HPHP_PROFILE_DUMP_H_