| 112 | } |
| 113 | |
| 114 | void FlameGraph::dump(Writer& out, bool tree) { |
| 115 | _name_order = new u32[_cpool.size() + 1](); |
| 116 | _mintotal = _minwidth == 0 && tree ? _root._total / 1000 : (u64)(_root._total * _minwidth / 100); |
| 117 | int depth = _root.depth(_mintotal, _name_order); |
| 118 | |
| 119 | if (tree) { |
| 120 | const char* tail = TREE_TEMPLATE; |
| 121 | |
| 122 | tail = printTill(out, tail, "/*title:*/"); |
| 123 | out << (_reverse ? "Backtrace" : "Call tree"); |
| 124 | |
| 125 | tail = printTill(out, tail, "/*type:*/"); |
| 126 | out << (_counter == COUNTER_SAMPLES ? "samples" : "counter"); |
| 127 | |
| 128 | tail = printTill(out, tail, "/*count:*/"); |
| 129 | out << Format().thousands(_root._total); |
| 130 | |
| 131 | tail = printTill(out, tail, "/*tree:*/"); |
| 132 | |
| 133 | const char** names = new const char*[_cpool.size() + 1]; |
| 134 | for (std::map<std::string, u32>::const_iterator it = _cpool.begin(); it != _cpool.end(); ++it) { |
| 135 | names[it->second] = it->first.c_str(); |
| 136 | } |
| 137 | printTreeFrame(out, _root, 0, names); |
| 138 | delete[] names; |
| 139 | |
| 140 | out << tail; |
| 141 | } else { |
| 142 | const char* tail = FLAMEGRAPH_TEMPLATE; |
| 143 | |
| 144 | tail = printTill(out, tail, "/*height:*/300"); |
| 145 | out << std::min(depth * 16, MAX_CANVAS_HEIGHT); |
| 146 | |
| 147 | tail = printTill(out, tail, "/*title:*/"); |
| 148 | out << _title; |
| 149 | |
| 150 | tail = printTill(out, tail, "/*inverted:*/false"); |
| 151 | // _inverted toggles the layout for reversed stacktraces from icicle to flamegraph |
| 152 | // and for default stacktraces from flamegraphs to icicle. |
| 153 | out << (_reverse ^ _inverted ? "true" : "false"); |
| 154 | |
| 155 | tail = printTill(out, tail, "/*depth:*/0"); |
| 156 | out << depth; |
| 157 | |
| 158 | tail = printTill(out, tail, "/*cpool:*/"); |
| 159 | printCpool(out); |
| 160 | |
| 161 | tail = printTill(out, tail, "/*frames:*/"); |
| 162 | printFrame(out, FRAME_NATIVE << 28, _root, 0, 0); |
| 163 | |
| 164 | tail = printTill(out, tail, "/*highlight:*/"); |
| 165 | |
| 166 | out << tail; |
| 167 | } |
| 168 | |
| 169 | delete[] _name_order; |
| 170 | } |
| 171 | |