int Builder::build(unsigned jobs, bool dry_run, bool show_progress)
{
unsigned total = build_graph.count_rebuild_targets();
+ Time::TimeStamp start_time = Time::now();
if(!total)
{
vector<Task *> tasks;
unsigned count = 0;
+ Time::TimeDelta sum_time;
bool fail = false;
bool finish = false;
{
++count;
+ const vector<const FileTarget *> &targets = tasks[i]->get_targets();
+ if(!targets.empty())
+ {
+ sum_time += tasks[i]->get_duration();
+ get_logger().log("timings", "%s built in %s", targets.front()->get_name(), tasks[i]->get_duration());
+ }
+
delete tasks[i];
tasks.erase(tasks.begin()+i);
if(status==Task::ERROR)
else if(show_progress)
get_logger().log("summary", "Build complete");
+ Time::TimeStamp end_time = Time::now();
+ get_logger().log("timings", "Build took %s, with a total %s spent on tasks", end_time-start_time, sum_time);
+
return fail;
}
return RUNNING;
}
else
- signal_finished.emit(!exit_code);
+ finished(!exit_code);
}
return exit_code ? ERROR : SUCCESS;
{
Status result = worker.get_status();
if(result!=RUNNING)
- signal_finished.emit(result==SUCCESS);
+ finished(result==SUCCESS);
return result;
}
#include <msp/fs/dir.h>
#include <msp/fs/stat.h>
#include <msp/fs/utils.h>
+#include <msp/time/utils.h>
#include "filetarget.h"
#include "task.h"
void Task::prepare()
{
+ start_time = Time::now();
+
for(const FileTarget *t: targets)
{
const FS::Path &f = t->get_path();
}
}
}
+
+void Task::finished(bool success)
+{
+ if(!duration && start_time)
+ duration = Time::now()-start_time;
+ signal_finished.emit(success);
+}
#include <string>
#include <vector>
#include <sigc++/signal.h>
+#include <msp/time/timedelta.h>
+#include <msp/time/timestamp.h>
#include "libbuilder_api.h"
class FileTarget;
protected:
std::vector<const FileTarget *> targets;
bool unlink = false;
+ Msp::Time::TimeStamp start_time;
+ Msp::Time::TimeDelta duration;
Task() = default;
public:
started. */
void set_unlink(bool = true);
+ const std::vector<const FileTarget *> &get_targets() const { return targets; }
+
/** Returns the command being executed for this task. Only makes sense if
an external command is involved. */
virtual std::string get_command() const = 0;
/// Ensures that the output directory exists and removes files if necessary.
void prepare();
+ void finished(bool);
+
public:
/// Checks the status of the task and immediately returns.
virtual Status check() = 0;
/// Waits for the task to finish and returns its final status.
virtual Status wait() = 0;
+
+ /** Returns the amount of time completing the task took. Only available
+ after the task has finished. */
+ const Msp::Time::TimeDelta &get_duration() const { return duration; }
};
#endif