Skip to content

Commit dfed0cc

Browse files
committed
Track types of queries
1 parent a5a9b13 commit dfed0cc

File tree

8 files changed

+91
-64
lines changed

8 files changed

+91
-64
lines changed

lib/runtime/AccessCountPrinter.h

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,29 @@ void serialize(const Recorder& r, std::ostringstream& buf) {
5454
if constexpr (std::is_same_v<Recorder, NoneRecorder>) {
5555
return;
5656
} else {
57-
const auto memory_use = memory::estimate(r.getMaxStackAllocs(), r.getMaxHeapAllocs(), r.getGlobalAllocs());
57+
// const auto memory_use = memory::estimate(r.getMaxStackAllocs(), r.getMaxHeapAllocs(), r.getGlobalAllocs());
5858

5959
Table t("Alloc Stats from softcounters");
6060
t.wrap_length_ = true;
6161
t.put(Row::make("Total heap", r.getHeapAllocs(), r.getHeapArray()));
6262
t.put(Row::make("Total stack", r.getStackAllocs(), r.getStackArray()));
6363
t.put(Row::make("Total global", r.getGlobalAllocs(), r.getGlobalArray()));
64-
t.put(Row::make("Max. Heap Allocs", r.getMaxHeapAllocs()));
65-
t.put(Row::make("Max. Stack Allocs", r.getMaxStackAllocs()));
64+
t.put(Row::make("Max. heap", r.getMaxHeapAllocs()));
65+
t.put(Row::make("Max. stack", r.getMaxStackAllocs()));
6666
t.put(Row::make("Addresses checked", r.getAddrChecked()));
67-
t.put(Row::make("Distinct Addresses checked", r.getSeen().size()));
67+
t.put(Row::make("Distinct addresses checked", r.getSeen().size()));
6868
t.put(Row::make("Addresses re-used", r.getAddrReuses()));
6969
t.put(Row::make("Addresses missed", r.getAddrMissing()));
70-
t.put(Row::make("Distinct Addresses missed", r.getMissing().size()));
70+
t.put(Row::make("Distinct addresses missed", r.getMissing().size()));
7171
t.put(Row::make("Total free heap", r.getHeapAllocsFree(), r.getHeapArrayFree()));
7272
t.put(Row::make("Total free stack", r.getStackAllocsFree(), r.getStackArrayFree()));
73-
t.put(Row::make("OMP Stack/Heap/Free", r.getOmpStackCalls(), r.getOmpHeapCalls(), r.getOmpFreeCalls()));
74-
t.put(Row::make("Null/Zero/NullZero Addr", r.getNullAlloc(), r.getZeroAlloc(), r.getNullAndZeroAlloc()));
73+
t.put(Row::make("OMP stack/heap/free", r.getOmpStackCalls(), r.getOmpHeapCalls(), r.getOmpFreeCalls()));
74+
t.put(Row::make("Null/Zero/NullZero addr", r.getNullAlloc(), r.getZeroAlloc(), r.getNullAndZeroAlloc()));
7575
t.put(Row::make("User-def. types", r.getNumUDefTypes()));
76-
t.put(Row::make("Estimated memory use (KiB)", size_t(std::round(memory_use.map + memory_use.stack))));
77-
t.put(Row::make("Bytes per node map/stack", memory::MemOverhead::perNodeSizeMap,
78-
memory::MemOverhead::perNodeSizeStack));
76+
t.put(Row::make("Distinct query types", r.getTypeQuery().size()));
77+
// t.put(Row::make("Estimated memory use (KiB)", size_t(std::round(memory_use.map + memory_use.stack))));
78+
// t.put(Row::make("Bytes per node map/stack", memory::MemOverhead::perNodeSizeMap,
79+
// memory::MemOverhead::perNodeSizeStack));
7980

8081
t.print(buf);
8182

@@ -108,17 +109,31 @@ void serialize(const Recorder& r, std::ostringstream& buf) {
108109
}
109110

110111
type_table.print(buf);
112+
{
113+
Table type_table_free("Free allocation type detail (heap, stack)");
114+
type_table_free.table_header_ = '#';
115+
for (auto type_id : type_id_set) {
116+
type_table_free.put(Row::make(std::to_string(type_id), count(r.getHeapFree(), type_id),
117+
count(r.getStackFree(), type_id), typeart_get_type_name(type_id)));
118+
}
111119

112-
Table type_table_free("Free allocation type detail (heap, stack)");
113-
type_table_free.table_header_ = '#';
114-
for (auto type_id : type_id_set) {
115-
type_table_free.put(Row::make(std::to_string(type_id), count(r.getHeapFree(), type_id),
116-
count(r.getStackFree(), type_id), typeart_get_type_name(type_id)));
120+
type_table_free.print(buf);
117121
}
122+
{
123+
Table type_table_query("Query type detail");
124+
type_table_query.table_header_ = '#';
125+
const auto& query_map = r.getTypeQuery();
126+
for (const auto& [query_type_id, query_count] : query_map) {
127+
type_table_query.put(Row::make(std::to_string(query_type_id), query_count, typeart_get_type_name(query_type_id)));
128+
}
118129

119-
type_table_free.print(buf);
130+
type_table_query.print(buf);
131+
}
120132

121133
const auto numThreads = r.getNumThreads();
134+
if (numThreads < 2) {
135+
return;
136+
}
122137
std::stringstream ss;
123138
ss << "Per-thread counter values (" << numThreads << " threads)";
124139
Table thread_table(ss.str());

lib/runtime/AccessCounter.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ class AccessRecorder {
193193

194194
~AccessRecorder() = default;
195195

196+
inline void incTypeQuery(int type_id) {
197+
std::lock_guard lock(typeQueryMutex);
198+
++typeQuery[type_id];
199+
}
200+
196201
inline void incHeapAlloc(int typeId, size_t count) {
197202
++curHeapAllocs;
198203

@@ -446,6 +451,10 @@ class AccessRecorder {
446451
std::shared_lock slock(seenMutex);
447452
return seen;
448453
}
454+
TypeCountMap getTypeQuery() const {
455+
std::shared_lock slock(typeQueryMutex);
456+
return typeQuery;
457+
}
449458
TypeCountMap getStackAlloc() const {
450459
std::shared_lock slock(stackAllocMutex);
451460
return stackAlloc;
@@ -524,13 +533,18 @@ class AccessRecorder {
524533

525534
TypeCountMap heapFree;
526535
mutable MutexT heapFreeMutex;
536+
537+
TypeCountMap typeQuery;
538+
mutable MutexT typeQueryMutex;
527539
};
528540

529541
/**
530542
* Used for no-operations in counter methods when not using softcounters.
531543
*/
532544
class NoneRecorder {
533545
public:
546+
[[maybe_unused]] inline void incTypeQuery(int) {
547+
}
534548
[[maybe_unused]] inline void incHeapAlloc(int, size_t) {
535549
}
536550
[[maybe_unused]] inline void incStackAlloc(int, size_t) {

lib/runtime/TypeResolution.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ const TypeDB& TypeResolution::db() const {
278278
}
279279

280280
namespace detail {
281-
inline typeart_status query_type(const void* addr, int* type, size_t* count) {
282-
auto alloc = typeart::RuntimeSystem::get().allocTracker.findBaseAlloc(addr);
283-
typeart::RuntimeSystem::get().recorder.incUsedInRequest(addr);
284-
if (alloc) {
285-
return typeart::RuntimeSystem::get().typeResolution.getTypeInfo(addr, alloc->first, alloc->second, type, count);
286-
}
287-
return TYPEART_UNKNOWN_ADDRESS;
288-
}
281+
// inline typeart_status query_type(const void* addr, int* type, size_t* count) {
282+
// auto alloc = typeart::RuntimeSystem::get().allocTracker.findBaseAlloc(addr);
283+
// typeart::RuntimeSystem::get().recorder.incUsedInRequest(addr);
284+
// if (alloc) {
285+
// return typeart::RuntimeSystem::get().typeResolution.getTypeInfo(addr, alloc->first, alloc->second, type, count);
286+
// }
287+
// return TYPEART_UNKNOWN_ADDRESS;
288+
// }
289289

290290
inline typeart_status query_type(const void* addr, typeart_type_info& info) {
291291
auto alloc = typeart::RuntimeSystem::get().allocTracker.findBaseAlloc(addr);
@@ -297,6 +297,9 @@ inline typeart_status query_type(const void* addr, typeart_type_info& info) {
297297
base.count = alloc->second.count;
298298
info.base_type_info = base;
299299
info.address = addr;
300+
301+
typeart::RuntimeSystem::get().recorder.incTypeQuery(base.type_id);
302+
300303
const auto result = typeart::RuntimeSystem::get().typeResolution.getTypeInfo(addr, alloc->first, alloc->second,
301304
&info.type_id, &info.count);
302305
return result;

test/runtime/18_softcounter_empty.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@ int main(void) {
1212
// CHECK-NEXT: Total heap : 0 , 0 , -
1313
// CHECK-NEXT: Total stack : 0 , 0 , -
1414
// CHECK-NEXT: Total global : 0 , 0 , -
15-
// CHECK-NEXT: Max. Heap Allocs : 0 , - , -
16-
// CHECK-NEXT: Max. Stack Allocs : 0 , - , -
15+
// CHECK-NEXT: Max. heap : 0 , - , -
16+
// CHECK-NEXT: Max. stack : 0 , - , -
1717
// CHECK-NEXT: Addresses checked : 0 , - , -
18-
// CHECK-NEXT: Distinct Addresses checked : 0 , - , -
18+
// CHECK-NEXT: Distinct addresses checked : 0 , - , -
1919
// CHECK-NEXT: Addresses re-used : 0 , - , -
2020
// CHECK-NEXT: Addresses missed : 0 , - , -
21-
// CHECK-NEXT: Distinct Addresses missed : 0 , - , -
21+
// CHECK-NEXT: Distinct addresses missed : 0 , - , -
2222
// CHECK-NEXT: Total free heap : 0 , 0 , -
2323
// CHECK-NEXT: Total free stack : 0 , 0 , -
24-
// CHECK-NEXT: OMP Stack/Heap/Free : 0 , 0 , 0
25-
// CHECK-NEXT: Null/Zero/NullZero Addr : 0 , 0 , 0
24+
// CHECK-NEXT: OMP stack/heap/free : 0 , 0 , 0
25+
// CHECK-NEXT: Null/Zero/NullZero addr : 0 , 0 , 0
2626
// CHECK-NEXT: User-def. types : 0 , - , -
27-
// CHECK-NEXT: Estimated memory use (KiB) : 4 , - , -
28-
// CHECK-NEXT: Bytes per node map/stack : 96 , 8 , -
27+
// CHECK-NEXT: Distinct query types : 0 , - , -
2928
// CHECK-NEXT: {{(#|-)+}}
3029
// CHECK-NEXT: Allocation type detail (heap, stack, global)
3130
// CHECK-NEXT: {{(#|-)+}}

test/runtime/19_softcounter.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@ int main(void) {
1717
// CHECK-NEXT: Total heap : 5 , 4 , -
1818
// CHECK-NEXT: Total stack : 0 , 0 , -
1919
// CHECK-NEXT: Total global : 0 , 0 , -
20-
// CHECK-NEXT: Max. Heap Allocs : 1 , - , -
21-
// CHECK-NEXT: Max. Stack Allocs : 0 , - , -
20+
// CHECK-NEXT: Max. heap : 1 , - , -
21+
// CHECK-NEXT: Max. stack : 0 , - , -
2222
// CHECK-NEXT: Addresses checked : 0 , - , -
23-
// CHECK-NEXT: Distinct Addresses checked : 0 , - , -
23+
// CHECK-NEXT: Distinct addresses checked : 0 , - , -
2424
// CHECK-NEXT: Addresses re-used : 0 , - , -
2525
// CHECK-NEXT: Addresses missed : 0 , - , -
26-
// CHECK-NEXT: Distinct Addresses missed : 0 , - , -
26+
// CHECK-NEXT: Distinct addresses missed : 0 , - , -
2727
// CHECK-NEXT: Total free heap : 5 , 4 , -
2828
// CHECK-NEXT: Total free stack : 0 , 0 , -
29-
// CHECK-NEXT: OMP Stack/Heap/Free : 0 , 0 , 0
30-
// CHECK-NEXT: Null/Zero/NullZero Addr : 0 , 0 , 0
29+
// CHECK-NEXT: OMP stack/heap/free : 0 , 0 , 0
30+
// CHECK-NEXT: Null/Zero/NullZero addr : 0 , 0 , 0
3131
// CHECK-NEXT: User-def. types : 0 , - , -
32-
// CHECK-NEXT: Estimated memory use (KiB) : 4 , - , -
33-
// CHECK-NEXT: Bytes per node map/stack : 96 , 8 , -
32+
// CHECK-NEXT: Distinct query types : 0 , - , -
3433
// CHECK-NEXT: {{(#|-)+}}
3534
// CHECK-NEXT: Allocation type detail (heap, stack, global)
3635
// CHECK-NEXT: 24 : 5 , 0 , 0 , double

test/runtime/20_softcounter_max.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@ int main(void) {
1717
// CHECK-NEXT: Total heap : 6 , 0 , -
1818
// CHECK-NEXT: Total stack : 0 , 0 , -
1919
// CHECK-NEXT: Total global : 0 , 0 , -
20-
// CHECK-NEXT: Max. Heap Allocs : 6 , - , -
21-
// CHECK-NEXT: Max. Stack Allocs : 0 , - , -
20+
// CHECK-NEXT: Max. heap : 6 , - , -
21+
// CHECK-NEXT: Max. stack : 0 , - , -
2222
// CHECK-NEXT: Addresses checked : 0 , - , -
23-
// CHECK-NEXT: Distinct Addresses checked : 0 , - , -
23+
// CHECK-NEXT: Distinct addresses checked : 0 , - , -
2424
// CHECK-NEXT: Addresses re-used : 0 , - , -
2525
// CHECK-NEXT: Addresses missed : 0 , - , -
26-
// CHECK-NEXT: Distinct Addresses missed : 0 , - , -
26+
// CHECK-NEXT: Distinct addresses missed : 0 , - , -
2727
// CHECK-NEXT: Total free heap : 0 , 0 , -
2828
// CHECK-NEXT: Total free stack : 0 , 0 , -
29-
// CHECK-NEXT: OMP Stack/Heap/Free : 0 , 0 , 0
30-
// CHECK-NEXT: Null/Zero/NullZero Addr : 0 , 0 , 0
29+
// CHECK-NEXT: OMP stack/heap/free : 0 , 0 , 0
30+
// CHECK-NEXT: Null/Zero/NullZero addr : 0 , 0 , 0
3131
// CHECK-NEXT: User-def. types : 0 , - , -
32-
// CHECK-NEXT: Estimated memory use (KiB) : {{[4-9]}} , - , -
33-
// CHECK-NEXT: Bytes per node map/stack : 96 , 8 , -
32+
// CHECK-NEXT: Distinct query types : 0 , - , -
3433
// CHECK-NEXT: {{(#|-)+}}
3534
// CHECK-NEXT: Allocation type detail (heap, stack, global)
3635
// CHECK-NEXT: 24 : 6 , 0 , 0 , double

test/runtime/27_omp_softcounter.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,19 @@ int main(int argc, char** argv) {
4040
// CHECK-NEXT: Total heap : 200 , 200 , -
4141
// CHECK-NEXT: Total stack : 0 , 0 , -
4242
// CHECK-NEXT: Total global : 0 , 0 , -
43-
// CHECK-NEXT: Max. Heap Allocs : {{[1-2]}} , - , -
44-
// CHECK-NEXT: Max. Stack Allocs : 0 , - , -
43+
// CHECK-NEXT: Max. Heap : {{[1-2]}} , - , -
44+
// CHECK-NEXT: Max. Stack : 0 , - , -
4545
// CHECK-NEXT: Addresses checked : 0 , - , -
46-
// CHECK-NEXT: Distinct Addresses checked : 0 , - , -
46+
// CHECK-NEXT: Distinct addresses checked : 0 , - , -
4747
// CHECK-NEXT: Addresses re-used : 0 , - , -
4848
// CHECK-NEXT: Addresses missed : 0 , - , -
49-
// CHECK-NEXT: Distinct Addresses missed : 0 , - , -
49+
// CHECK-NEXT: Distinct addresses missed : 0 , - , -
5050
// CHECK-NEXT: Total free heap : 200 , 200 , -
5151
// CHECK-NEXT: Total free stack : 0 , 0 , -
52-
// CHECK-NEXT: OMP Stack/Heap/Free : 0 , 200 , 200
53-
// CHECK-NEXT: Null/Zero/NullZero Addr : 0 , 0 , 0
52+
// CHECK-NEXT: OMP stack/heap/free : 0 , 200 , 200
53+
// CHECK-NEXT: Null/Zero/NullZero addr : 0 , 0 , 0
5454
// CHECK-NEXT: User-def. types : 0 , - , -
55-
// CHECK-NEXT: Estimated memory use (KiB) : {{[0-9]+}} , - , -
56-
// CHECK-NEXT: Bytes per node map/stack : 96 , 8 , -
55+
// CHECK-NEXT: Distinct query types : 0 , - , -
5756
// CHECK-NEXT: {{(#|-)+}}
5857
// CHECK-NEXT: Allocation type detail (heap, stack, global)
5958
// CHECK: {{(#|-)+}}

test/runtime/28_omp_softcounter_stack.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,19 @@ int main(int argc, char** argv) {
3737
// CHECK-NEXT: Total heap : 0 , 0 , -
3838
// CHECK: Total stack : {{[0-9]+}} , 400 , -
3939
// CHECK-NEXT: Total global : {{[0-9]+}} , {{[0-9]+}} , -
40-
// CHECK-NEXT: Max. Heap Allocs : 0 , - , -
41-
// CHECK-NEXT: Max. Stack Allocs : {{[0-9]+}} , - , -
40+
// CHECK-NEXT: Max. heap : 0 , - , -
41+
// CHECK-NEXT: Max. stack : {{[0-9]+}} , - , -
4242
// CHECK-NEXT: Addresses checked : 0 , - , -
43-
// CHECK-NEXT: Distinct Addresses checked : 0 , - , -
43+
// CHECK-NEXT: Distinct addresses checked : 0 , - , -
4444
// CHECK-NEXT: Addresses re-used : 0 , - , -
4545
// CHECK-NEXT: Addresses missed : 0 , - , -
46-
// CHECK-NEXT: Distinct Addresses missed : 0 , - , -
46+
// CHECK-NEXT: Distinct addresses missed : 0 , - , -
4747
// CHECK-NEXT: Total free heap : 0 , 0 , -
4848
// CHECK-NEXT: Total free stack : 4{{[0-9]+}} , 400 , -
49-
// CHECK-NEXT: OMP Stack/Heap/Free : {{[0-9]+}} , 0 , 0
50-
// CHECK-NEXT: Null/Zero/NullZero Addr : 0 , 0 , 0
49+
// CHECK-NEXT: OMP stack/heap/free : {{[0-9]+}} , 0 , 0
50+
// CHECK-NEXT: Null/Zero/NullZero addr : 0 , 0 , 0
5151
// CHECK-NEXT: User-def. types : 0 , - , -
52-
// CHECK-NEXT: Estimated memory use (KiB) : {{[0-9]+}} , - , -
53-
// CHECK-NEXT: Bytes per node map/stack : 96 , 8 , -
52+
// CHECK-NEXT: Distinct query types : 0 , - , -
5453
// CHECK-NEXT: {{(#|-)+}}
5554
// CHECK-NEXT: Allocation type detail (heap, stack, global)
5655
// CHECK: {{(#|-)+}}

0 commit comments

Comments
 (0)