Skip to content

Commit aaa9047

Browse files
authored
misc format cleanup (#167)
* Formats CMakeLists.txt * Format all of the profiler lib
1 parent 6bee76e commit aaa9047

29 files changed

Lines changed: 642 additions & 606 deletions

.clang-format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ SpaceAfterCStyleCast: false
1919
SpacesInParentheses: false
2020
SpacesInContainerLiterals: false
2121
BreakBeforeBinaryOperators: NonAssignment
22+
AlignConsecutiveMacros:
23+
Enabled: true
24+
AcrossEmptyLines: false
25+
AcrossComments: false

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,22 @@ else()
9292
endif()
9393

9494
if ( MSVC )
95-
MESSAGE ( STATUS "Setting MSVC MT switches")
96-
string (REPLACE
95+
MESSAGE ( STATUS "Setting MSVC MT switches")
96+
string (REPLACE
9797
"/MDd"
9898
"/MTd"
9999
CMAKE_C_FLAGS_DEBUG
100100
${CMAKE_C_FLAGS_DEBUG}
101-
)
102-
string (REPLACE
101+
)
102+
string (REPLACE
103103
"/MDd"
104104
"/MTd"
105105
CMAKE_C_FLAGS_RELEASE
106106
${CMAKE_C_FLAGS_RELEASE}
107-
)
107+
)
108108
elseif ( WIN32 )
109-
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mconsole")
110-
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mwindows")
109+
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mconsole")
110+
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mwindows")
111111
elseif ( GCC AND NOT MINGW )
112112
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer")
113113
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")

lib/profiler/.clang-format

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
BasedOnStyle: LLVM
3+
IndentWidth: 8
4+
TabWidth: 8
5+
UseTab: ForIndentation
6+
BreakBeforeBraces: Linux
7+
ColumnLimit: 120
8+
PointerAlignment: Right
9+
IndentCaseLabels: true
10+
SpaceBeforeParens: ControlStatements
11+
AlignAfterOpenBracket: Align
12+
AllowShortFunctionsOnASingleLine: None
13+
AllowShortIfStatementsOnASingleLine: Never
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterReturnType: AllDefinitions
16+
SortIncludes: Never
17+
IndentPPDirectives: None
18+
SpaceAfterCStyleCast: false
19+
SpacesInParentheses: false
20+
SpacesInContainerLiterals: false
21+
BreakBeforeBinaryOperators: NonAssignment
22+
AlignConsecutiveMacros:
23+
Enabled: true
24+
AcrossEmptyLines: false
25+
AcrossComments: false
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#ifndef COMMON_H_
22
#define COMMON_H_
33

4-
#define C_RED "\x1b[31m"
5-
#define C_GREEN "\x1b[32m"
6-
#define C_YELLOW "\x1b[33m"
7-
#define C_BLUE "\x1b[34m"
8-
#define C_MAGENTA "\x1b[35m"
9-
#define C_CYAN "\x1b[36m"
10-
#define C_WHITE "\x1b[37m"
11-
#define C_RESET "\x1b[0m"
12-
13-
#endif // COMMON_H_
4+
#define C_RED "\x1b[31m"
5+
#define C_GREEN "\x1b[32m"
6+
#define C_YELLOW "\x1b[33m"
7+
#define C_BLUE "\x1b[34m"
8+
#define C_MAGENTA "\x1b[35m"
9+
#define C_CYAN "\x1b[36m"
10+
#define C_WHITE "\x1b[37m"
11+
#define C_RESET "\x1b[0m"
1412

13+
#endif // COMMON_H_

lib/profiler/include/internal/profiler_c.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
#define ANCHOR_CAPACITY 4096
99

1010
typedef struct ProfileAnchor {
11-
const char *label;
12-
size_t hits;
13-
uint64_t elapsed_exclusive;
14-
uint64_t elapsed_inclusive;
15-
size_t processed_byte_count;
11+
const char *label;
12+
size_t hits;
13+
uint64_t elapsed_exclusive;
14+
uint64_t elapsed_inclusive;
15+
size_t processed_byte_count;
1616
} ProfileAnchor;
1717

1818
typedef struct Profiler {
19-
uint64_t start, stop;
20-
size_t len;
21-
ProfileAnchor anchors[ANCHOR_CAPACITY];
19+
uint64_t start, stop;
20+
size_t len;
21+
ProfileAnchor anchors[ANCHOR_CAPACITY];
2222
} Profiler;
2323

2424
typedef struct AnchorBlock {
25-
const char *label;
26-
uint64_t start;
27-
uint64_t old_elapsed_inclusive;
28-
size_t processed_byte_count;
29-
char *parent_anchor;
25+
const char *label;
26+
uint64_t start;
27+
uint64_t old_elapsed_inclusive;
28+
size_t processed_byte_count;
29+
char *parent_anchor;
3030
} AnchorBlock;
3131

3232
void prof_init(void);
@@ -43,4 +43,3 @@ AnchorBlock make_anchor_block(const char *label, size_t used_bytes);
4343
void read_anchor_block(const AnchorBlock *anchor);
4444

4545
#endif // _STOP_CLOCK_H_
46-

lib/profiler/include/macros.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313
prof_print(fp);
1414

1515
#define _NameConcat(A, B) A##B
16-
#define NameConcat(A, B) _NameConcat(A, B)
16+
#define NameConcat(A, B) _NameConcat(A, B)
1717

1818
#define TIME_BANDWIDTH_BEGIN(label, bytes) AnchorBlock NameConcat(Block, label) = make_anchor_block(#label, bytes)
19-
#define TIME_BANDWIDTH_END(label) read_anchor_block(&Block##label)
19+
#define TIME_BANDWIDTH_END(label) read_anchor_block(&Block##label)
2020
#define TIME_BANDWIDTH(label, bytes) \
2121
AnchorBlock NameConcat(Block, label) __attribute__((cleanup(read_anchor_block))); \
2222
NameConcat(Block, label) = make_anchor_block(#label, bytes)
2323

2424
#define TIME_BLOCK_BEGIN(label) TIME_BANDWIDTH_BEGIN(label, 0)
25-
#define TIME_BLOCK_END(label) TIME_BANDWIDTH_END(label)
25+
#define TIME_BLOCK_END(label) TIME_BANDWIDTH_END(label)
2626
#define TIME_BLOCK(label) \
2727
AnchorBlock NameConcat(Block, label) __attribute__((cleanup(read_anchor_block))); \
2828
NameConcat(Block, label) = make_anchor_block(#label, 0)
2929

3030
#define TIME_FUNC_BEGIN() AnchorBlock NameConcat(Block, __func__) = make_anchor_block(__func__, 0)
31-
#define TIME_FUNC_END() read_anchor_block(&Block##__func__)
31+
#define TIME_FUNC_END() read_anchor_block(&Block##__func__)
3232
#define TIME_FUNC() \
3333
AnchorBlock NameConcat(Block, __func__) __attribute__((cleanup(read_anchor_block))); \
3434
NameConcat(Block, __func__) = make_anchor_block(__func__, 0)

lib/profiler/include/perf.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ uint64_t perf_read_page_fault_count(void);
1111

1212
void perf_close(void);
1313

14-
#endif // _PERF_H_
15-
14+
#endif // _PERF_H_

lib/profiler/include/profiler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ extern "C" {
1919
#endif
2020

2121
#endif // _PROFILER_H_
22-

lib/profiler/include/rdtsc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ uint64_t estimate_cpu_freq(uint64_t test_time);
1717
#endif
1818

1919
#endif // _RDTSC_H_
20-

lib/profiler/include/repetition_tester.h

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,48 @@
55
#include <stdbool.h>
66
#include <stdio.h>
77

8-
#define rept_error(tester, msg) \
9-
do { \
10-
fprintf(stderr, "%s()[%d] %s\n", __func__, __LINE__, msg); \
11-
tester->mode = TestMode_Error; \
12-
} while (0)
13-
14-
typedef enum TestMode {
15-
TestMode_Uninitialized,
16-
TestMode_Testing,
17-
TestMode_Completed,
18-
TestMode_Error
19-
} TestMode;
8+
#define rept_error(tester, msg) \
9+
do { \
10+
fprintf(stderr, "%s()[%d] %s\n", __func__, __LINE__, msg); \
11+
tester->mode = TestMode_Error; \
12+
} while (0)
13+
14+
typedef enum TestMode { TestMode_Uninitialized, TestMode_Testing, TestMode_Completed, TestMode_Error } TestMode;
2015

2116
typedef enum RepetitionValueType {
22-
RepVal_test_count,
23-
RepVal_page_faults,
24-
RepVal_byte_count,
25-
RepVal_cpu_time,
26-
RepVal_count
17+
RepVal_test_count,
18+
RepVal_page_faults,
19+
RepVal_byte_count,
20+
RepVal_cpu_time,
21+
RepVal_count
2722
} RepetitionValueType;
2823

2924
typedef struct RepetitionValue {
30-
uint64_t E[RepVal_count];
25+
uint64_t E[RepVal_count];
3126
} RepetitionValue;
3227

3328
typedef struct RepetitionTestResult {
34-
RepetitionValue total;
35-
RepetitionValue min;
36-
RepetitionValue max;
29+
RepetitionValue total;
30+
RepetitionValue min;
31+
RepetitionValue max;
3732
} RepetitionTestResult;
3833

3934
typedef struct RepetitionTester {
40-
uint64_t target_processed_byte_count;
41-
uint64_t cpu_timer_freq;
42-
uint64_t test_time;
43-
uint64_t start_time;
44-
45-
TestMode mode;
46-
bool print_new_mins;
47-
uint32_t open_block_count;
48-
uint32_t close_block_count;
49-
50-
RepetitionValue current;
51-
RepetitionTestResult results;
35+
uint64_t target_processed_byte_count;
36+
uint64_t cpu_timer_freq;
37+
uint64_t test_time;
38+
uint64_t start_time;
39+
40+
TestMode mode;
41+
bool print_new_mins;
42+
uint32_t open_block_count;
43+
uint32_t close_block_count;
44+
45+
RepetitionValue current;
46+
RepetitionTestResult results;
5247
} RepetitionTester;
5348

54-
void rept_setup(RepetitionTester *tester, uint64_t target_bytes,
55-
uint64_t cpu_timer_freq, uint32_t test_time);
49+
void rept_setup(RepetitionTester *tester, uint64_t target_bytes, uint64_t cpu_timer_freq, uint32_t test_time);
5650

5751
void rept_begin(RepetitionTester *tester);
5852

@@ -64,5 +58,4 @@ bool rept_is_testing(RepetitionTester *tester);
6458

6559
void rept_print_results(RepetitionTester *tester, FILE *fp);
6660

67-
#endif // REPETITION_TESTER_H_
68-
61+
#endif // REPETITION_TESTER_H_

0 commit comments

Comments
 (0)