From a06d5fcbdfc75d9926866e2812969fc6b1729a18 Mon Sep 17 00:00:00 2001 From: Eric Caruso Date: Wed, 24 Jul 2013 13:49:33 -0700 Subject: [PATCH] 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. --- hphp/runtime/base/profile_dump.h | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 hphp/runtime/base/profile_dump.h 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_