2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present 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/tools/hfsort/hfutil.h"
19 #include <folly/Format.h>
21 namespace HPHP::hfsort
{
23 bool CallGraph::addFunc(
29 if (name
.empty()) return false;
30 auto it
= addr2TargetId
.find(addr
);
31 if (it
!= addr2TargetId
.end()) {
32 auto& base
= funcs
[it
->second
];
33 auto& baseTarget
= targets
[it
->second
];
34 base
.mangledNames
.push_back(name
);
35 // Store the same id for different symbol name with same start address
36 func2TargetId
[name
] = it
->second
;
37 if (size
> baseTarget
.size
) baseTarget
.size
= size
;
38 HFTRACE(2, "Func: adding '%s' to (%u)\n", name
.c_str(), it
->second
);
41 auto id
= addTarget(size
);
42 funcs
.emplace_back(name
, addr
, group
);
43 func2TargetId
[name
] = id
;
44 addr2TargetId
[addr
] = id
;
45 HFTRACE(2, "Func: adding (%u): %016lx %s %u\n", id
, (long)addr
, name
.c_str(),
50 TargetId
CallGraph::addrToTargetId(uint64_t addr
) const {
51 auto it
= addr2TargetId
.upper_bound(addr
);
52 if (it
== addr2TargetId
.begin()) return InvalidId
;
54 const auto &f
= funcs
[it
->second
];
55 const auto &fTarget
= targets
[it
->second
];
56 assert(f
.addr
<= addr
);
57 if (f
.addr
+ fTarget
.size
<= addr
) {
63 TargetId
CallGraph::funcToTargetId(const std::string
&func
) const {
64 auto it
= func2TargetId
.find(func
);
65 if (it
!= func2TargetId
.end()) {
71 std::string
CallGraph::toString(TargetId id
) const {
72 return folly::sformat("func = {:5} : samples = {:6} : size = {:6} : {}\n",
73 id
, targets
[id
].samples
, targets
[id
].size
,
74 funcs
[id
].mangledNames
[0]);