-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1506 from Expensify/main
Update expensify_prod branch
- Loading branch information
Showing
13 changed files
with
187 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <BedrockBlockingCommandQueue.h> | ||
|
||
void BedrockBlockingCommandQueue::startTiming(unique_ptr<BedrockCommand>& command) { | ||
command->startTiming(BedrockCommand::QUEUE_BLOCKING); | ||
} | ||
|
||
void BedrockBlockingCommandQueue::stopTiming(unique_ptr<BedrockCommand>& command) { | ||
command->stopTiming(BedrockCommand::QUEUE_BLOCKING); | ||
} | ||
|
||
BedrockBlockingCommandQueue::BedrockBlockingCommandQueue() : | ||
BedrockCommandQueue(function<void(unique_ptr<BedrockCommand>&)>(startTiming), function<void(unique_ptr<BedrockCommand>&)>(stopTiming)) | ||
{ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
#include "BedrockCommandQueue.h" | ||
|
||
class BedrockCommand; | ||
|
||
class BedrockBlockingCommandQueue : public BedrockCommandQueue { | ||
public: | ||
BedrockBlockingCommandQueue(); | ||
|
||
// Functions to start and stop timing on the commands when they're inserted/removed from the queue. | ||
static void startTiming(unique_ptr<BedrockCommand>& command); | ||
static void stopTiming(unique_ptr<BedrockCommand>& command); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "BedrockConflictManager.h" | ||
#include <libstuff/libstuff.h> | ||
|
||
BedrockConflictManager::BedrockConflictManager() { | ||
} | ||
|
||
void BedrockConflictManager::recordTables(const string& commandName, const set<string>& tables) { | ||
{ | ||
lock_guard<mutex> lock(m); | ||
auto commandInfoIt = _commandInfo.find(commandName); | ||
if (commandInfoIt == _commandInfo.end()) { | ||
commandInfoIt = _commandInfo.emplace(make_pair(commandName, BedrockConflictManagerCommandInfo())).first; | ||
} | ||
BedrockConflictManagerCommandInfo& commandInfo = commandInfoIt->second; | ||
|
||
// Increase the count of the command in general. | ||
commandInfo.count++; | ||
|
||
// And for each table (that's not a journal). | ||
for (auto& table : tables) { | ||
// Skip journals, they change on every instance of a command running and thus aren't useful for profiling which commands access which tables most frequently. | ||
if (SStartsWith(table, "journal")) { | ||
continue; | ||
} | ||
|
||
if (table == "json_each") { | ||
continue; | ||
} | ||
|
||
// Does this command already have this table? | ||
auto tableInfoIt = commandInfo.tableUseCounts.find(table); | ||
if (tableInfoIt == commandInfo.tableUseCounts.end()) { | ||
tableInfoIt = commandInfo.tableUseCounts.emplace(make_pair(table, 1)).first; | ||
} else { | ||
// tableInfoIt is an iterator into a map<string, size_t> (tableUseCounts), where the key is the table name and the value is the count of uses for this command. | ||
// Incrementing `second` increases the count. | ||
tableInfoIt->second++; | ||
} | ||
} | ||
} | ||
|
||
// And increase the count for each used table. | ||
SINFO("Command " << commandName << " used tables: " << SComposeList(tables)); | ||
} | ||
|
||
string BedrockConflictManager::generateReport() { | ||
stringstream out; | ||
{ | ||
lock_guard<mutex> lock(m); | ||
for (auto& p : _commandInfo) { | ||
const string& commandName = p.first; | ||
const BedrockConflictManagerCommandInfo& commandInfo = p.second; | ||
|
||
out << "Command: " << commandName << endl; | ||
out << "Total Count: " << commandInfo.count << endl; | ||
out << "Table usage" << endl; | ||
for (const auto& table : commandInfo.tableUseCounts) { | ||
const string& tableName = table.first; | ||
const size_t& count = table.second; | ||
out << " " << tableName << ": " << count << endl; | ||
} | ||
out << endl; | ||
} | ||
} | ||
return out.str(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
#include <map> | ||
#include <mutex> | ||
#include <set> | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
class BedrockConflictManagerCommandInfo { | ||
public: | ||
size_t count = 0; | ||
map<string, size_t> tableUseCounts; | ||
}; | ||
|
||
class BedrockConflictManager { | ||
public: | ||
BedrockConflictManager(); | ||
void recordTables(const string& commandName, const set<string>& tables); | ||
string generateReport(); | ||
|
||
private: | ||
mutex m; | ||
map<string, BedrockConflictManagerCommandInfo> _commandInfo; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters