Author: mordante
Date: Sun Mar 25 17:23:21 2012
New Revision: 53660
URL: http://svn.gna.org/viewcvs/wesnoth?rev=53660&view=rev
Log:
Add a way to get timing information in wesmage.
The timing info shows the time spend in the filter code. This should
give an indication of the time. The resolution of the time is platform
specific.
Modified:
trunk/src/wesmage/options.cpp
trunk/src/wesmage/options.hpp
trunk/src/wesmage/wesmage.cpp
Modified: trunk/src/wesmage/options.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/wesmage/options.cpp?rev=53660&r1=53659&r2=53660&view=diff
==============================================================================
--- trunk/src/wesmage/options.cpp (original)
+++ trunk/src/wesmage/options.cpp Sun Mar 25 17:23:21 2012
@@ -21,12 +21,14 @@
#include <cassert>
#include <cstdlib>
+#include <ctime>
#include <iostream>
toptions::toptions()
: input_filename()
, output_filename()
, filters()
+ , time(false)
{
}
@@ -110,6 +112,8 @@
"OPTIONS:\n"
"-o, --output FILE The name of the output file to be written.\n"
"-n, --dry-run No output is written.\n"
+"-t, --time Show the time it took to apply the filters.\n"
+" The resolution of the time depends on the platform.\n"
"-f, --filter FILTER Filters to be applied to the image. See FILTERS.\n"
"-h, --help Show this help and terminate the programme.\n"
"\n"
@@ -159,6 +163,8 @@
help = true;
} else if(option == "-n" || option == "--dry-run") {
dry_run = true;
+ } else if(option == "-t" || option == "--time") {
+ result.time = true;
} else if(option == "-o" || option == "--output") {
++i;
VALIDATE_NOT_PAST_END;
@@ -202,6 +208,14 @@
print_help(EXIT_FAILURE);
}
+ if(result.time && (std::clock() == -1)) {
+ std::cerr
+ << "Error: No timing available on your platform, "
+ << "option disabled.\n";
+
+ result.time = false;
+ }
+
/*
* No filter implies a copy, or conversion to png, which is a valid
* way to use the programme, so do not complain.
Modified: trunk/src/wesmage/options.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/wesmage/options.hpp?rev=53660&r1=53659&r2=53660&view=diff
==============================================================================
--- trunk/src/wesmage/options.hpp (original)
+++ trunk/src/wesmage/options.hpp Sun Mar 25 17:23:21 2012
@@ -68,6 +68,10 @@
/** The filters to apply to the input file. */
std::vector<std::string> filters;
+
+ /** Display the time that applying the filters took. */
+ bool time;
+
private:
/**
Modified: trunk/src/wesmage/wesmage.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/wesmage/wesmage.cpp?rev=53660&r1=53659&r2=53660&view=diff
==============================================================================
--- trunk/src/wesmage/wesmage.cpp (original)
+++ trunk/src/wesmage/wesmage.cpp Sun Mar 25 17:23:21 2012
@@ -26,6 +26,7 @@
#include <SDL_image.h>
+#include <ctime>
#include <iostream>
int
@@ -45,8 +46,32 @@
return EXIT_FAILURE;
}
+ clock_t begin = std::clock();
+ clock_t end = std::clock();
+ if(options.time) {
+ while(begin == (end = std::clock())) {
+ /* DO NOTHING */
+ }
+ std::cout << "Clock resolution "
+ << end - begin
+ << " ticks, using " << CLOCKS_PER_SEC
<< " ticks/second.\n"
+ << "This give resolution of about "
+ <<static_cast<double>(end - begin) /
CLOCKS_PER_SEC
+ << " seconds.\n";
+ begin = std::clock();
+ }
+
BOOST_FOREACH(const std::string& filter, options.filters) {
filter_apply(surf, filter);
+ }
+
+ end = std::clock();
+ if(options.time) {
+ std::cout << "Applying the filters took "
+ << end - begin
+ << " ticks, "
+ << static_cast<double>(end - begin) /
CLOCKS_PER_SEC
+ << " seconds.\n";
}
if(!options.output_filename.empty()) {
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits