void GCGV_ReqGetNodes::BuildReply() { size_t pwdLen = parent->PWD().ToString().length() +1; reply.StartArray("nodes"); for (SortedNodes::reverse_iterator it = sortedNodes.rbegin(); it != sortedNodes.rend(); ++it) { NodePtr node = it->second; long total = node->Costs()[0]; long average = double(total) / node->Calls(); std::string path = GCGV_Callgraph::GetPath(node).ToString(); if (path.length() > pwdLen) { path = path.c_str() + pwdLen; } reply.StartAnonymousObject(); reply.Add("path", path); reply.Add("calls", node->Calls()); reply.Add("cost", total); reply.Add("avCost", average); reply.EndObject(); } reply.EndArray(); }
void GCGV_ReqGetNodes::SortedNodes::AddNode(NodePtr node, SORT_BY sort) { long idx = 0; switch (sort) { case COST: idx = node->Costs()[0]; break; case AV_COST: idx = node->Costs()[0] / node->Calls(); break; default: throw InvalidRequestException { 0, "Invalid Sort Type" }; } insert(SortedNodes::value_type(idx, node)); }