diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-08-25T15·49+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-08-25T15·49+0200 |
commit | c137c0a5ebc0d58c53f86986ab66967ac8629cbe (patch) | |
tree | 38e01bef5549985449a4c911c1444758d585335f /src/libutil | |
parent | f194629f96d4bdbded897e7e88ac0d03211c959d (diff) |
Allow activities to be nested
In particular, this allows more relevant activities ("substituting X") to supersede inferior ones ("downloading X").
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/logging.cc | 6 | ||||
-rw-r--r-- | src/libutil/logging.hh | 14 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index 87f20664ef08..b103b902eab0 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -5,6 +5,8 @@ namespace nix { +thread_local ActivityId curActivity = 0; + Logger * logger = makeDefaultLogger(); void Logger::warn(const std::string & msg) @@ -75,10 +77,10 @@ Logger * makeDefaultLogger() std::atomic<uint64_t> nextId{(uint64_t) getpid() << 32}; Activity::Activity(Logger & logger, ActivityType type, - const std::string & s, const Logger::Fields & fields) + const std::string & s, const Logger::Fields & fields, ActivityId parent) : logger(logger), id(nextId++) { - logger.startActivity(id, type, s, fields); + logger.startActivity(id, type, s, fields, parent); } } diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index 567af361e8e9..9427f268267a 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -23,6 +23,7 @@ typedef enum { actBuild = 105, actOptimiseStore = 106, actVerifyPaths = 107, + actSubstitute = 108, } ActivityType; typedef enum { @@ -65,7 +66,7 @@ public: virtual void warn(const std::string & msg); virtual void startActivity(ActivityId act, ActivityType type, - const std::string & s, const Fields & fields) { }; + const std::string & s, const Fields & fields, ActivityId parent) { }; virtual void stopActivity(ActivityId act) { }; @@ -76,6 +77,8 @@ public: virtual void result(ActivityId act, ResultType type, const Fields & fields) { }; }; +extern thread_local ActivityId curActivity; + struct Activity { Logger & logger; @@ -83,7 +86,7 @@ struct Activity const ActivityId id; Activity(Logger & logger, ActivityType type, const std::string & s = "", - const Logger::Fields & fields = {}); + const Logger::Fields & fields = {}, ActivityId parent = curActivity); Activity(const Activity & act) = delete; @@ -107,6 +110,13 @@ struct Activity friend class Logger; }; +struct PushActivity +{ + const ActivityId prevAct; + PushActivity(ActivityId act) : prevAct(curActivity) { curActivity = act; } + ~PushActivity() { curActivity = prevAct; } +}; + extern Logger * logger; Logger * makeDefaultLogger(); |