-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Execution time measurement patch #923
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
#include "../Descriptors/JSONDescriptor.h" | ||
#include "../Util/SimpleLogger.h" | ||
#include "../Util/StringUtil.h" | ||
#include "../Util/TimingUtil.h" | ||
|
||
#include <boost/unordered_map.hpp> | ||
|
||
|
@@ -81,6 +82,7 @@ class ViaRoutePlugin : public BasePlugin { | |
return; | ||
} | ||
|
||
TimeMeasurement exec_time; | ||
RawRouteData rawRoute; | ||
rawRoute.checkSum = facade->GetCheckSum(); | ||
const bool checksumOK = (routeParameters.checkSum == rawRoute.checkSum); | ||
|
@@ -156,17 +158,16 @@ class ViaRoutePlugin : public BasePlugin { | |
descriptorConfig.geometry = routeParameters.geometry; | ||
descriptorConfig.encode_geometry = routeParameters.compression; | ||
|
||
std::string exec_time_token; | ||
switch(descriptorType){ | ||
case 0: | ||
desc = new JSONDescriptor<DataFacadeT>(); | ||
|
||
break; | ||
case 1: | ||
desc = new GPXDescriptor<DataFacadeT>(); | ||
|
||
exec_time_token = "<metadata>"; | ||
break; | ||
case 0: | ||
default: | ||
desc = new JSONDescriptor<DataFacadeT>(); | ||
exec_time_token = "{"; | ||
|
||
break; | ||
} | ||
|
@@ -177,6 +178,25 @@ class ViaRoutePlugin : public BasePlugin { | |
desc->SetConfig(descriptorConfig); | ||
|
||
desc->Run(rawRoute, phantomNodes, facade, reply); | ||
|
||
if (routeParameters.exec_time) { | ||
int64_t time_ms = exec_time.toNowInMs(); | ||
std::vector<std::string>::iterator it = reply.content.begin(); | ||
for (; it != reply.content.end(); ++it) { | ||
if (0 == (*it).compare(0, exec_time_token.size(), exec_time_token)) { | ||
break; // we have found place to insert exec time metric | ||
} | ||
} | ||
if (it != reply.content.end()) { | ||
std::string temp_string; | ||
int64ToString(time_ms, temp_string); | ||
reply.content.insert(++it, (1 == descriptorType)? | ||
"<exec_time_ms>" + temp_string + "</exec_time_ms>" : "\"exec_time_ms\":" + temp_string + "," | ||
); | ||
} else { | ||
SimpleLogger().Write(logDEBUG) << "Can't find place to insert exec time metric"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to throw an exception as this is not expected to happen. On the other hand, finding a proper place to add the information should take O(1) time and making this check superfluous. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
} | ||
} | ||
if("" != routeParameters.jsonpParameter) { | ||
reply.content.push_back(")\n"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still, this is effort linear in the size of the string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed