Google format
This commit is contained in:
151
.clang-format
Normal file
151
.clang-format
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
# BasedOnStyle: Google
|
||||||
|
AccessModifierOffset: -1
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BraceWrapping:
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: false
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeInheritanceComma: false
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 80
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DerivePointerAlignment: true
|
||||||
|
DisableFormat: false
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^<ext/.*\.h>'
|
||||||
|
Priority: 2
|
||||||
|
- Regex: '^<.*\.h>'
|
||||||
|
Priority: 1
|
||||||
|
- Regex: '^<.*'
|
||||||
|
Priority: 2
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 3
|
||||||
|
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||||
|
IndentCaseLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentWidth: 2
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Never
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 1
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 200
|
||||||
|
PointerAlignment: Left
|
||||||
|
RawStringFormats:
|
||||||
|
- Language: Cpp
|
||||||
|
Delimiters:
|
||||||
|
- cc
|
||||||
|
- CC
|
||||||
|
- cpp
|
||||||
|
- Cpp
|
||||||
|
- CPP
|
||||||
|
- 'c++'
|
||||||
|
- 'C++'
|
||||||
|
CanonicalDelimiter: ''
|
||||||
|
BasedOnStyle: google
|
||||||
|
- Language: TextProto
|
||||||
|
Delimiters:
|
||||||
|
- pb
|
||||||
|
- PB
|
||||||
|
- proto
|
||||||
|
- PROTO
|
||||||
|
EnclosingFunctions:
|
||||||
|
- EqualsProto
|
||||||
|
- EquivToProto
|
||||||
|
- PARSE_PARTIAL_TEXT_PROTO
|
||||||
|
- PARSE_TEST_PROTO
|
||||||
|
- PARSE_TEXT_PROTO
|
||||||
|
- ParseTextOrDie
|
||||||
|
- ParseTextProtoOrDie
|
||||||
|
CanonicalDelimiter: ''
|
||||||
|
BasedOnStyle: google
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: true
|
||||||
|
SortUsingDeclarations: true
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 2
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Auto
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
TabWidth: 8
|
||||||
|
UseTab: Never
|
||||||
|
...
|
||||||
|
|
||||||
@@ -4,19 +4,19 @@
|
|||||||
#include "usage.h"
|
#include "usage.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
google::InitGoogleLogging(argv[0]);
|
google::InitGoogleLogging(argv[0]);
|
||||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||||
|
|
||||||
fireusage::UsageTracker tracker;
|
fireusage::UsageTracker tracker;
|
||||||
tracker.Start();
|
tracker.Start();
|
||||||
for (int i = 0; i < 100000000; ++i) {
|
for (int i = 0; i < 100000000; ++i) {
|
||||||
tracker.AddEvent();
|
tracker.AddEvent();
|
||||||
for (int _ = 0; _ < 100000; ++_) {
|
for (int _ = 0; _ < 100000; ++_) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tracker.Stop();
|
tracker.Stop();
|
||||||
tracker.Log();
|
tracker.Log();
|
||||||
|
|
||||||
gflags::ShutDownCommandLineFlags();
|
gflags::ShutDownCommandLineFlags();
|
||||||
google::ShutdownGoogleLogging();
|
google::ShutdownGoogleLogging();
|
||||||
}
|
}
|
||||||
|
|||||||
91
usage.cc
91
usage.cc
@@ -8,63 +8,72 @@ namespace fireusage {
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::chrono::nanoseconds TvToNs(const timeval& tv) {
|
std::chrono::nanoseconds TvToNs(const timeval& tv) {
|
||||||
return std::chrono::seconds(tv.tv_sec) + std::chrono::microseconds(tv.tv_usec);
|
return std::chrono::seconds(tv.tv_sec) +
|
||||||
|
std::chrono::microseconds(tv.tv_usec);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void UsageTracker::AddEvents(uint64_t num) {
|
void UsageTracker::AddEvents(uint64_t num) { events_ += num; }
|
||||||
events_ += num;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UsageTracker::AddEvent() {
|
void UsageTracker::AddEvent() { events_ += 1; }
|
||||||
events_ += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UsageTracker::Start() {
|
void UsageTracker::Start() {
|
||||||
CHECK(!running_);
|
CHECK(!running_);
|
||||||
running_ = true;
|
running_ = true;
|
||||||
|
|
||||||
PCHECK(getrusage(RUSAGE_THREAD, &start_usage_) == 0);
|
PCHECK(getrusage(RUSAGE_THREAD, &start_usage_) == 0);
|
||||||
start_time_ = std::chrono::steady_clock::now();
|
start_time_ = std::chrono::steady_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsageTracker::Stop() {
|
void UsageTracker::Stop() {
|
||||||
CHECK(running_);
|
CHECK(running_);
|
||||||
running_ = false;
|
running_ = false;
|
||||||
|
|
||||||
const auto end_time = std::chrono::steady_clock::now();
|
const auto end_time = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
rusage end_usage;
|
rusage end_usage;
|
||||||
PCHECK(getrusage(RUSAGE_THREAD, &end_usage) == 0);
|
PCHECK(getrusage(RUSAGE_THREAD, &end_usage) == 0);
|
||||||
|
|
||||||
wall_time_ += end_time - start_time_;
|
wall_time_ += end_time - start_time_;
|
||||||
user_time_ += TvToNs(end_usage.ru_utime) - TvToNs(start_usage_.ru_utime);
|
user_time_ += TvToNs(end_usage.ru_utime) - TvToNs(start_usage_.ru_utime);
|
||||||
sys_time_ += TvToNs(end_usage.ru_stime) - TvToNs(start_usage_.ru_stime);
|
sys_time_ += TvToNs(end_usage.ru_stime) - TvToNs(start_usage_.ru_stime);
|
||||||
vol_ctxt_sw_ += end_usage.ru_nvcsw - start_usage_.ru_nvcsw;
|
vol_ctxt_sw_ += end_usage.ru_nvcsw - start_usage_.ru_nvcsw;
|
||||||
invol_ctxt_sw_ += end_usage.ru_nivcsw - start_usage_.ru_nivcsw;
|
invol_ctxt_sw_ += end_usage.ru_nivcsw - start_usage_.ru_nivcsw;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsageTracker::Log(const std::string_view& title) {
|
void UsageTracker::Log(const std::string_view& title) {
|
||||||
if (!title.empty()) {
|
if (!title.empty()) {
|
||||||
// Need to do this here so --vmodule works properly
|
// Need to do this here so --vmodule works properly
|
||||||
VLOG(1) << title << ":";
|
VLOG(1) << title << ":";
|
||||||
}
|
}
|
||||||
|
|
||||||
VLOG(1) << "\t events: " << std::setw(19) << std::setfill(' ') << events_;
|
VLOG(1) << "\t events: " << std::setw(19) << std::setfill(' ')
|
||||||
VLOG(1) << "\t wall time: " << std::setw(19) << std::setfill(' ') << wall_time_.count() << "ns";
|
<< events_;
|
||||||
VLOG(1) << "\t user time: " << std::setw(19) << std::setfill(' ') << user_time_.count() << "ns (" << ((user_time_ * 100) / (user_time_ + sys_time_)) << "%)";
|
VLOG(1) << "\t wall time: " << std::setw(19) << std::setfill(' ')
|
||||||
VLOG(1) << "\t sys time: " << std::setw(19) << std::setfill(' ') << sys_time_.count() << "ns (" << ((sys_time_ * 100) / (user_time_ + sys_time_)) << "%)";
|
<< wall_time_.count() << "ns";
|
||||||
VLOG(1) << "\t vol ctxt sw: " << std::setw(19) << std::setfill(' ') << vol_ctxt_sw_;
|
VLOG(1) << "\t user time: " << std::setw(19) << std::setfill(' ')
|
||||||
VLOG(1) << "\t invol ctxt sw: " << std::setw(19) << std::setfill(' ') << invol_ctxt_sw_;
|
<< user_time_.count() << "ns ("
|
||||||
if (events_) {
|
<< ((user_time_ * 100) / (user_time_ + sys_time_)) << "%)";
|
||||||
VLOG(1) << "\t wall time / event: " << std::setw(19) << std::setfill(' ') << (wall_time_ / events_).count() << "ns";
|
VLOG(1) << "\t sys time: " << std::setw(19) << std::setfill(' ')
|
||||||
VLOG(1) << "\t user time / event: " << std::setw(19) << std::setfill(' ') << (user_time_ / events_).count() << "ns";
|
<< sys_time_.count() << "ns ("
|
||||||
VLOG(1) << "\t sys time / event: " << std::setw(19) << std::setfill(' ') << (sys_time_ / events_).count() << "ns";
|
<< ((sys_time_ * 100) / (user_time_ + sys_time_)) << "%)";
|
||||||
VLOG(1) << "\t vol ctxt sw / event: " << std::setw(19) << std::setfill(' ') << (vol_ctxt_sw_ / events_);
|
VLOG(1) << "\t vol ctxt sw: " << std::setw(19) << std::setfill(' ')
|
||||||
VLOG(1) << "\tinvol ctxt sw / event: " << std::setw(19) << std::setfill(' ') << (invol_ctxt_sw_ / events_);
|
<< vol_ctxt_sw_;
|
||||||
}
|
VLOG(1) << "\t invol ctxt sw: " << std::setw(19) << std::setfill(' ')
|
||||||
|
<< invol_ctxt_sw_;
|
||||||
|
if (events_) {
|
||||||
|
VLOG(1) << "\t wall time / event: " << std::setw(19) << std::setfill(' ')
|
||||||
|
<< (wall_time_ / events_).count() << "ns";
|
||||||
|
VLOG(1) << "\t user time / event: " << std::setw(19) << std::setfill(' ')
|
||||||
|
<< (user_time_ / events_).count() << "ns";
|
||||||
|
VLOG(1) << "\t sys time / event: " << std::setw(19) << std::setfill(' ')
|
||||||
|
<< (sys_time_ / events_).count() << "ns";
|
||||||
|
VLOG(1) << "\t vol ctxt sw / event: " << std::setw(19) << std::setfill(' ')
|
||||||
|
<< (vol_ctxt_sw_ / events_);
|
||||||
|
VLOG(1) << "\tinvol ctxt sw / event: " << std::setw(19) << std::setfill(' ')
|
||||||
|
<< (invol_ctxt_sw_ / events_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace fireusage
|
} // namespace fireusage
|
||||||
|
|||||||
36
usage.h
36
usage.h
@@ -1,31 +1,31 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <sys/resource.h>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/resource.h>
|
|
||||||
|
|
||||||
namespace fireusage {
|
namespace fireusage {
|
||||||
|
|
||||||
class UsageTracker {
|
class UsageTracker {
|
||||||
public:
|
public:
|
||||||
void AddEvents(uint64_t num);
|
void AddEvents(uint64_t num);
|
||||||
void AddEvent();
|
void AddEvent();
|
||||||
|
|
||||||
void Start();
|
void Start();
|
||||||
void Stop();
|
void Stop();
|
||||||
void Log(const std::string_view& title="");
|
void Log(const std::string_view& title = "");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool running_ = false;
|
bool running_ = false;
|
||||||
uint64_t events_ = 0;
|
uint64_t events_ = 0;
|
||||||
std::chrono::nanoseconds wall_time_;
|
std::chrono::nanoseconds wall_time_;
|
||||||
std::chrono::nanoseconds user_time_;
|
std::chrono::nanoseconds user_time_;
|
||||||
std::chrono::nanoseconds sys_time_;
|
std::chrono::nanoseconds sys_time_;
|
||||||
uint64_t vol_ctxt_sw_ = 0;
|
uint64_t vol_ctxt_sw_ = 0;
|
||||||
uint64_t invol_ctxt_sw_ = 0;
|
uint64_t invol_ctxt_sw_ = 0;
|
||||||
|
|
||||||
std::chrono::steady_clock::time_point start_time_;
|
std::chrono::steady_clock::time_point start_time_;
|
||||||
rusage start_usage_;
|
rusage start_usage_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace fireusage
|
} // namespace fireusage
|
||||||
|
|||||||
Reference in New Issue
Block a user