MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / sample

Method sample

src/hx/Profiler.cpp:65–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63 }
64
65 void sample(hx::StackContext *stack)
66 {
67 if (mT0 == gProfileClock) {
68 return;
69 }
70
71 // Latch the profile clock and calculate the time since the last profile
72 // clock tick
73 int clock = gProfileClock;
74 int delta = clock - mT0;
75 if (delta < 0) {
76 delta = 1;
77 }
78 mT0 = clock;
79
80 int depth = stack->getDepth();
81
82 std::map<const char *, bool> alreadySeen;
83
84 // Add children time in to each stack element
85 for (int i = 0; i < (depth - 1); i++) {
86 const char *fullName = stack->getFullNameAtDepth(i);
87 ProfileEntry &pe = mProfileStats[fullName];
88 if (!alreadySeen.count(fullName)) {
89 pe.total += delta;
90 alreadySeen[fullName] = true;
91 }
92 // For everything except the very bottom of the stack, add the time to
93 // that child's total with this entry
94 pe.children[stack->getFullNameAtDepth(i + 1)] += delta;
95 }
96
97 // Add the time into the actual function being executed
98 if (depth > 0) {
99 mProfileStats[stack->getFullNameAtDepth(depth - 1)].self += delta;
100 }
101 }
102
103
104

Callers 1

profSampleFunction · 0.80

Calls 2

getDepthMethod · 0.80
getFullNameAtDepthMethod · 0.80

Tested by

no test coverage detected