diff --git a/CMakeLists.txt b/CMakeLists.txt index a6977411..57a050bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,9 +139,9 @@ endif() check_function_exists(clock_gettime CLOCK_GETTIME_FOUND) if(NOT CLOCK_GETTIME_FOUND) - set(CMAKE_REQUIRED_LIBRARIES "rt") - check_function_exists(clock_gettime CLOCK_GETTIME_FOUND_WITH_RT) - unset(CMAKE_REQUIRED_LIBRARIES) + set(CMAKE_REQUIRED_LIBRARIES "rt") + check_function_exists(clock_gettime CLOCK_GETTIME_FOUND_WITH_RT) + unset(CMAKE_REQUIRED_LIBRARIES) endif() CHECK_STRUCT_HAS_BITFIELD("struct perf_event_attr" context_switch linux/perf_event.h HAVE_PERF_RECORD_SWITCH) diff --git a/include/lo2s/cupti/events.hpp b/include/lo2s/cupti/events.hpp index 6ae38878..ba994458 100644 --- a/include/lo2s/cupti/events.hpp +++ b/include/lo2s/cupti/events.hpp @@ -29,7 +29,7 @@ namespace cupti { enum class EventType : uint64_t { - CUPTI_KERNEL = 0, + CUPTI_KERNEL = 1, }; struct event_header diff --git a/include/lo2s/cupti/reader.hpp b/include/lo2s/cupti/reader.hpp index 6ef1bf01..5c474b67 100644 --- a/include/lo2s/cupti/reader.hpp +++ b/include/lo2s/cupti/reader.hpp @@ -49,8 +49,9 @@ class Reader public: Reader(trace::Trace& trace, Process process) : process_(process), trace_(trace), time_converter_(perf::time::Converter::instance()), - ringbuf_reader_(std::to_string(process.as_pid_t()), true, config().nvidia_ringbuf_size), - timer_fd_(timerfd_from_ns(config().userspace_read_interval)), exe(get_process_exe(process)) + ringbuf_reader_("cupti", process.as_pid_t(), true, config().nvidia_ringbuf_size), + timer_fd_(timerfd_from_ns(config().userspace_read_interval)), + executable_name_(get_process_exe(process)) { } @@ -69,11 +70,11 @@ class Reader auto& writer = trace_.cuda_writer(Thread(process_.as_thread())); std::string kernel_name = kernel->name; - auto& cu_cctx = trace_.cuda_calling_context(exe, kernel_name); + auto& cu_cctx = trace_.cuda_calling_context(executable_name_, kernel_name); - writer << otf2::event::calling_context_enter(time_converter_(kernel->start), - cu_cctx, 2); - writer << otf2::event::calling_context_leave(time_converter_(kernel->end), cu_cctx); + writer.write_calling_context_enter(time_converter_(kernel->start), cu_cctx.ref(), + 2); + writer.write_calling_context_leave(time_converter_(kernel->end), cu_cctx.ref()); } ringbuf_reader_.pop(header->size); @@ -91,7 +92,7 @@ class Reader perf::time::Converter& time_converter_; RingBufReader ringbuf_reader_; int timer_fd_; - std::string exe; + std::string executable_name_; }; } // namespace cupti } // namespace lo2s diff --git a/include/lo2s/pipe.hpp b/include/lo2s/pipe.hpp index fbde33ae..f53bb035 100644 --- a/include/lo2s/pipe.hpp +++ b/include/lo2s/pipe.hpp @@ -59,7 +59,7 @@ class Pipe void fd_flags(std::size_t fd, int flags); void close_fd(std::size_t fd); - int fds_[2]; - bool fd_open_[2]; + int fds_[2] = { 0, 0 }; + bool fd_open_[2] = { false, false }; }; } // namespace lo2s diff --git a/include/lo2s/ringbuf.hpp b/include/lo2s/ringbuf.hpp index facc637a..f1e2ba3b 100644 --- a/include/lo2s/ringbuf.hpp +++ b/include/lo2s/ringbuf.hpp @@ -107,8 +107,10 @@ class Mmap class ShmRingbuf { public: - ShmRingbuf(std::string filename, bool create, size_t pages) + ShmRingbuf(std::string component, pid_t pid, bool create, size_t pages) { + std::string filename = "/lo2s-" + component + "-" + std::to_string(pid); + fd_ = shm_open(filename.c_str(), create ? O_RDWR | O_CREAT | O_EXCL : O_RDWR, 0600); if (fd_ == -1) { @@ -195,8 +197,8 @@ class ShmRingbuf class RingBufWriter : public ShmRingbuf { public: - RingBufWriter(std::string filename, bool create, size_t pages = 0) - : ShmRingbuf(filename, create, pages) + RingBufWriter(std::string component, pid_t pid, bool create, size_t pages = 0) + : ShmRingbuf(component, pid, create, pages) { } @@ -233,8 +235,8 @@ class RingBufWriter : public ShmRingbuf class RingBufReader : public ShmRingbuf { public: - RingBufReader(std::string filename, bool create, size_t pages = 0) - : ShmRingbuf(filename, create, pages) + RingBufReader(std::string component, pid_t pid, bool create, size_t pages = 0) + : ShmRingbuf(component, pid, create, pages) { } std::byte* get(size_t size) diff --git a/src/cupti/lib.cpp b/src/cupti/lib.cpp index e711be3c..51d23d02 100644 --- a/src/cupti/lib.cpp +++ b/src/cupti/lib.cpp @@ -77,12 +77,13 @@ static void CUPTIAPI bufferCompleted(CUcontext ctx, uint32_t streamId, uint8_t* case CUPTI_ACTIVITY_KIND_KERNEL: case CUPTI_ACTIVITY_KIND_CONCURRENT_KERNEL: { - CUpti_ActivityKernel6* kernel = static_cast(record); + CUpti_ActivityKernel6* kernel = reinterpret_cast(record); uint64_t name_len = strlen(kernel->name); - struct lo2s::cupti::event_kernel* ev = static_cast( - rb_writer->reserve(sizeof(struct lo2s::cupti::event_kernel) + name_len)); + struct lo2s::cupti::event_kernel* ev = + reinterpret_cast( + rb_writer->reserve(sizeof(struct lo2s::cupti::event_kernel) + name_len)); if (ev == nullptr) { @@ -127,7 +128,7 @@ void CUPTIAPI callbackHandler(void* userdata, CUpti_CallbackDomain domain, CUpti { if (cbInfo->callbackSite == CUPTI_API_EXIT) { - cupttiActivityEnableContext(cbInfo->context, CUPTI_ACTIVITY_KIND_CONCURRENT_KERNEL); + cuptiActivityEnableContext(cbInfo->context, CUPTI_ACTIVITY_KIND_CONCURRENT_KERNEL); } } else if (cbid == CUPTI_DRIVER_TRACE_CBID_cuProfilerStop) @@ -168,7 +169,7 @@ extern "C" int InitializeInjection(void) { std::string rb_size_str; - rb_writer = std::make_unique(std::to_string(getpid()), false); + rb_writer = std::make_unique("cupti", getpid(), false); char* clockid_str = getenv("LO2S_CLOCKID"); if (clockid_str != nullptr) diff --git a/src/monitor/process_monitor.cpp b/src/monitor/process_monitor.cpp index bb8cdd6a..f4d66047 100644 --- a/src/monitor/process_monitor.cpp +++ b/src/monitor/process_monitor.cpp @@ -57,9 +57,9 @@ void ProcessMonitor::insert_thread(Process process, Thread thread, std::string n { try { - auto inserted = - threads_.emplace(std::piecewise_construct, std::forward_as_tuple(thread), - std::forward_as_tuple(ExecutionScope(thread), *this, spawn, is_process)); + auto inserted = threads_.emplace( + std::piecewise_construct, std::forward_as_tuple(thread), + std::forward_as_tuple(ExecutionScope(thread), *this, spawn, is_process)); assert(inserted.second); // actually start thread inserted.first->second.start(); diff --git a/src/monitor/process_monitor_main.cpp b/src/monitor/process_monitor_main.cpp index dddd7c41..8fb7ed3e 100644 --- a/src/monitor/process_monitor_main.cpp +++ b/src/monitor/process_monitor_main.cpp @@ -94,7 +94,7 @@ std::vector to_vector_of_c_str(std::vector vec) if (config().use_nvidia) { env = { "CUDA_INJECTION64_PATH=" + config().cuda_path }; - Log::error() << config().cuda_path; + if (config().use_clockid) { env.push_back("LO2S_CLOCKID=" + std::to_string(config().clockid));