X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/1a7e3f61d38d679bba59130891c2031b5a0092b6..bd6521f0fc816ab056bc71376f9706a69b3b52c1:/KDBG/MachineCPU.impl.hpp diff --git a/KDBG/MachineCPU.impl.hpp b/KDBG/MachineCPU.impl.hpp new file mode 100644 index 0000000..0c048ac --- /dev/null +++ b/KDBG/MachineCPU.impl.hpp @@ -0,0 +1,36 @@ +// +// MachineCPU.impl.hpp +// KDBG +// +// Created by James McIlree on 11/7/12. +// Copyright (c) 2014 Apple. All rights reserved. +// + +// +// NOTE! activity match behavior explanation... +// +// CPUActivity entries are contiguous, there are no holes in the timeline. +// +// Note the operator< definitions above, std::lower_bounds is not using the +// default AbsInterval <. The comparsions are against the interval(s) max() - 1. +// +// std::lower_bound returns a match doing <=, std::upper_bound returns a match doing < +// +// 8/26/13... +// +// Okay, based on a better understanding of the behavior of xxx_bounds, this +// should be switchable to std::upper_bounds using a comparator without the +// subtraction, and so slightly more efficient. +// + +template +const CPUActivity* MachineCPU::activity_for_timestamp(AbsTime timestamp) const { + auto it = std::upper_bound(_timeline.begin(), _timeline.end(), timestamp, AbsIntervalMaxVsAbsTimeComparator()); + + // The upper bound will report that 0 is lower than [ 10, 20 ), need to check contains! + if (it != _timeline.end() && it->contains(timestamp)) { + return &*it; + } + + return NULL; +}