Skip to content

Commit

Permalink
Fixed memcpy attribution (now on specific lines, just like allocations).
Browse files Browse the repository at this point in the history
  • Loading branch information
emeryberger committed Feb 5, 2022
1 parent dea3edf commit 86bbd14
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
28 changes: 9 additions & 19 deletions scalene/scalene_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,29 +1219,19 @@ def memcpy_sigqueue_processor(
with contextlib.suppress(ValueError):
while Scalene.__memcpy_mapfile.read():
count_str = Scalene.__memcpy_mapfile.get_str()
(memcpy_time_str, count_str2, pid) = count_str.split(",")
(memcpy_time_str, count_str2, pid, filename, lineno, bytei) = count_str.split(",")
if int(curr_pid) == int(pid):
arr.append((int(memcpy_time_str), int(count_str2)))
arr.append((filename, lineno, bytei, int(memcpy_time_str), int(count_str2)))
arr.sort()

stats = Scalene.__stats
new_frames = Scalene.compute_frames_to_record(frame)
if not new_frames:
del frame
return

for item in arr:
_memcpy_time, count = item
for (the_frame, _tident, _orig_frame) in new_frames:
fname = Filename(the_frame.f_code.co_filename)
line_no = LineNumber(the_frame.f_lineno)
bytei = ByteCodeIndex(the_frame.f_lasti)
# Add the byte index to the set for this line.
stats.bytei_map[fname][line_no].add(bytei)
stats.memcpy_samples[fname][line_no] += count
del new_frames[:]
del new_frames
del frame
filename, lineno, byteindex, _memcpy_time, count = item
fname = Filename(filename)
line_no = int(LineNumber(lineno))
bytei = ByteCodeIndex(byteindex)
# Add the byte index to the set for this line.
Scalene.__stats.bytei_map[fname][line_no].add(bytei)
Scalene.__stats.memcpy_samples[fname][line_no] += int(count)

@staticmethod
@lru_cache(None)
Expand Down
26 changes: 20 additions & 6 deletions src/include/memcpysampler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class MemcpySampler {
if (old_sig != SIG_DFL) signal(MemcpySignal, old_sig);
init_lock.unlock();
auto pid = getpid();
snprintf((char *)scalene_memcpy_signal_filename, FILENAME_LENGTH, fname,
snprintf_((char *)scalene_memcpy_signal_filename, BUFFER_LENGTH, fname,
pid);
// printf("initialized (%s)\n", scalene_memcpy_signal_filename);
}
Expand Down Expand Up @@ -279,13 +279,27 @@ class MemcpySampler {
uint64_t _interval;
uint64_t _memcpyOps;
unsigned long long _memcpyTriggered;
static constexpr int FILENAME_LENGTH = 255;
char scalene_memcpy_signal_filename[FILENAME_LENGTH];
static constexpr int BUFFER_LENGTH = 1024;
char scalene_memcpy_signal_filename[BUFFER_LENGTH];

void writeCount() {
char buf[FILENAME_LENGTH];
snprintf(buf, FILENAME_LENGTH, "%d,%d,%d\n\n", _memcpyTriggered, _memcpyOps,
getpid());
#if 1
std::string filename;
int lineno = 1;
int bytei = 0;
decltype(whereInPython)* where = p_whereInPython;
if (where != nullptr && where(filename, lineno, bytei)) {
;
}
#endif
char buf[BUFFER_LENGTH];
snprintf_(buf, BUFFER_LENGTH, "%d,%d,%d,%s,%d,%d\n\n",
_memcpyTriggered,
_memcpyOps,
getpid(),
filename.c_str(),
lineno,
bytei);
_samplefile.writeToFile(buf);
}
};
Expand Down

0 comments on commit 86bbd14

Please sign in to comment.