Skip to content
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

Update SPerformanceTimer to log immediate #1823

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions libstuff/SPerformanceTimer.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <libstuff/libstuff.h>
#include "SPerformanceTimer.h"

SPerformanceTimer::SPerformanceTimer(string description, map<string, chrono::steady_clock::duration> defaults)
SPerformanceTimer::SPerformanceTimer(string description, bool logImmediate, map<string, chrono::steady_clock::duration> defaults)
: _description(description),
_lastLogStart(chrono::steady_clock::now()),
_defaults(defaults),
_totals(_defaults)
_totals(_defaults),
_logImmediate(logImmediate)
{}

void SPerformanceTimer::start(const string& type) {
Expand All @@ -18,6 +19,12 @@ void SPerformanceTimer::stop() {
auto now = chrono::steady_clock::now();
auto duration = now - _lastStart;

if (_logImmediate) {
double durationMS = chrono::duration_cast<chrono::duration<double, std::milli>>(duration).count();
SINFO(_description << " " << _lastType << " in " << durationMS << " ms.");
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to break the purpose of this class, as we no longer record the totals. Either that or it makes this into a fairly complex way to do a simpler job.

I am confused what the purpose of this change is. I'm guessing you want to use this class somewhere new, but for a simpler task.

It seems we could do that with a class that looks like:

class NewClass {
    chrono::steady_clock::time_point _lastStart = 0;
    void start() {
        _lastStart = 0;
    }
    void stop() {
        SINFO("Message about" << now - _lastStart);
    }
};

I wonder if we can collapse SAutoTimer and SPerformanceTimer into one thing, since they seem to do basically the same task, and then make a simpler timer class oif that's what we need.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I don't have super strong feelings on this so let me know whatever you'd prefer. I am mainly looking for something to time some parts of the Auth code. I originally proposed to add a Bench class to Auth, but @coleaeason thought maybe we should use something that already exists.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add the Bench class in auth and create an issue to collapse these two Bedrock classes? It sounds like bench needs less functionality than we have here, and we can probably use only one of the two existing classes in bedrock.

}

// Record this time.
auto it = _totals.find(_lastType);
if (it != _totals.end()) {
Expand Down
3 changes: 2 additions & 1 deletion libstuff/SPerformanceTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class SPerformanceTimer {
public:
SPerformanceTimer(string description, map<string, chrono::steady_clock::duration> defaults = {});
SPerformanceTimer(string description, bool logImmediate = true, map<string, chrono::steady_clock::duration> defaults = {});
void start(const string& type);
void stop();
void log(chrono::steady_clock::duration elapsed);
Expand All @@ -15,4 +15,5 @@ class SPerformanceTimer {
string _lastType;
map <string, chrono::steady_clock::duration> _defaults;
map <string, chrono::steady_clock::duration> _totals;
bool _logImmediate;
};
2 changes: 1 addition & 1 deletion sqlitecluster/SQLite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ int64_t SQLite::getLastConflictPage() const {
SQLite::SharedData::SharedData() :
nextJournalCount(0),
_commitEnabled(true),
_commitLockTimer("commit lock timer", {
_commitLockTimer("commit lock timer", false, {
{"EXCLUSIVE", chrono::steady_clock::duration::zero()},
{"SHARED", chrono::steady_clock::duration::zero()},
})
Expand Down