6 #include "trace_profiler.hpp"
11 * Select and show the call in main window.
13 static void jumpToCall(int index);
16 * Convert a CPU / GPU time to a textual representation.
17 * This includes automatic unit selection.
19 static QString getTimeString(int64_t time, int64_t unitTime = 0)
29 if (unitTime >= 60e9) {
30 int64_t mins = time / 60e9;
31 text += QString("%1 m ").arg(mins);
36 } else if (unitTime >= 1e9) {
39 } else if (unitTime >= 1e6) {
42 } else if (unitTime >= 1e3) {
43 unit = QString::fromUtf8(" µs");
47 /* 3 decimal places */
48 text += QString("%1").arg(time / unitScale, 0, 'f', 3);
50 /* Remove trailing 0 */
51 while(text.endsWith('0'))
52 text.truncate(text.length() - 1);
54 /* Remove trailing decimal point */
55 if (text.endsWith(QLocale::system().decimalPoint()))
56 text.truncate(text.length() - 1);
61 template<typename val_ty, int64_t val_ty::* mem_ptr_start, int64_t val_ty::* mem_ptr_dura>
62 static typename std::vector<val_ty>::const_iterator binarySearchTimespan(
63 typename std::vector<val_ty>::const_iterator begin,
64 typename std::vector<val_ty>::const_iterator end,
69 int upper = end - begin;
70 int pos = (lower + upper) / 2;
71 typename std::vector<val_ty>::const_iterator itr = begin + pos;
73 while (!((*itr).*mem_ptr_start <= time && (*itr).*mem_ptr_start + (*itr).*mem_ptr_dura > time) && (lower <= upper)) {
74 if ((*itr).*mem_ptr_start > time) {
80 pos = (lower + upper) / 2;
84 if (nearest || lower <= upper) {
91 static std::vector<unsigned>::const_iterator binarySearchTimespanIndexed(
92 const std::vector<trace::Profile::Call>& calls,
93 std::vector<unsigned>::const_iterator begin,
94 std::vector<unsigned>::const_iterator end,
99 int upper = end - begin - 1;
100 int pos = (lower + upper) / 2;
101 std::vector<unsigned>::const_iterator itr = begin + pos;
103 while (lower <= upper) {
104 const trace::Profile::Call& call = calls[*itr];
106 if (call.gpuStart <= time && call.gpuStart + call.gpuDuration > time) {
110 if (call.gpuStart > time) {
116 pos = (lower + upper) / 2;
120 if (nearest || lower <= upper) {