-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
326 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
/* | ||
* This file is part of the lo2s software. | ||
* Linux OTF2 sampling | ||
* | ||
* Copyright (c) 2016, | ||
* Technische Universitaet Dresden, Germany | ||
* | ||
* lo2s is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* lo2s is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with lo2s. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "otf2xx/common.hpp" | ||
#include "otf2xx/event/io_create_handle.hpp" | ||
#include "otf2xx/event/io_delete_file.hpp" | ||
#include "otf2xx/event/io_destroy_handle.hpp" | ||
#include <lo2s/monitor/threaded_monitor.hpp> | ||
#include <lo2s/perf/time/converter.hpp> | ||
|
||
extern "C" | ||
{ | ||
#include <bpf/libbpf.h> | ||
#include <lo2s/block_io.skel.h> | ||
#include <lo2s/perf/bio/common.h> | ||
#include <sys/resource.h> | ||
} | ||
namespace lo2s | ||
{ | ||
namespace monitor | ||
{ | ||
class BioMonitor : public ThreadedMonitor | ||
{ | ||
public: | ||
struct RingBufferDeleter | ||
{ | ||
void operator()(struct ring_buffer* rb) | ||
{ | ||
ring_buffer__free(rb); | ||
} | ||
}; | ||
|
||
struct SkelDeleter | ||
{ | ||
void operator()(struct block_io_bpf* skel) | ||
{ | ||
block_io_bpf__destroy(skel); | ||
} | ||
}; | ||
|
||
BioMonitor(trace::Trace& trace) | ||
: ThreadedMonitor(trace, "open() monitor"), trace_(trace), | ||
time_converter_(perf::time::Converter::instance()) | ||
{ | ||
// Need to bump memlock rlimit to run anything but the most trivial BPF programs | ||
|
||
struct rlimit rlim_new; | ||
rlim_new.rlim_cur = RLIM_INFINITY; | ||
rlim_new.rlim_max = RLIM_INFINITY; | ||
|
||
if (setrlimit(RLIMIT_MEMLOCK, &rlim_new)) | ||
{ | ||
throw_errno(); | ||
} | ||
|
||
skel_ = std::unique_ptr<struct block_io_bpf, SkelDeleter>(block_io_bpf__block_io_and_load()); | ||
Check failure on line 76 in include/lo2s/monitor/bio_monitor.hpp Code Style Turtle / Code Formatting Testinclude/lo2s/monitor/bio_monitor.hpp#L76
|
||
if (!skel_) | ||
{ | ||
return; | ||
} | ||
|
||
block_io_bpf__attach(skel_.get()); | ||
|
||
rb_ = std::unique_ptr<struct ring_buffer, RingBufferDeleter>( | ||
ring_buffer__new(bpf_map__fd(skel_.get()->maps.rb), event_cb, this, NULL)); | ||
|
||
if (!rb_) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
static int libbpf_print_fn(enum libbpf_print_level level, const char* format, va_list args) | ||
{ | ||
if (level > LIBBPF_INFO) | ||
return 0; | ||
return vfprintf(stderr, format, args); | ||
} | ||
|
||
void insert_thread(Thread thread [[maybe_unused]]) | ||
{ | ||
char insert = 1; | ||
pid_t pid = thread.as_pid_t(); | ||
bpf_map__update_elem(skel_->maps.pids, &pid, sizeof(pid), &insert, sizeof(char), BPF_ANY); | ||
|
||
last_fd_[thread] = -1; | ||
} | ||
void exit_thread(Thread thread [[maybe_unused]]) | ||
{ | ||
pid_t pid = thread.as_pid_t(); | ||
bpf_map__delete_elem(skel_->maps.pids, &pid, sizeof(pid), BPF_ANY); | ||
} | ||
|
||
void initialize_thread() override | ||
{ | ||
} | ||
|
||
void handle_event(void* data, size_t datasz [[maybe_unused]]) | ||
{ | ||
|
||
struct block_event_header* e = (struct posix_event_header*)data; | ||
otf2::writer::local& writer = trace_.block_counter_writer(e->dev); | ||
|
||
} | ||
|
||
void run() override | ||
{ | ||
while (!stop_) | ||
{ | ||
ring_buffer__poll(rb_.get(), 100); | ||
} | ||
} | ||
|
||
void finalize_thread() override | ||
{ | ||
} | ||
|
||
void stop() override | ||
{ | ||
stop_ = true; | ||
thread_.join(); | ||
} | ||
static int event_cb(void* ctx, void* data, size_t data_sz) | ||
{ | ||
((BioMonitor*)ctx)->handle_event(data, data_sz); | ||
return 0; | ||
} | ||
|
||
void monitor() | ||
{ | ||
} | ||
|
||
std::string group() const override | ||
{ | ||
return "BioMonitor"; | ||
} | ||
|
||
private: | ||
struct ThreadFd | ||
{ | ||
ThreadFd() : fd(-1), thread(Thread::invalid()) | ||
{ | ||
} | ||
|
||
ThreadFd(int fd, pid_t thread) : fd(fd), thread(Thread(thread)) | ||
{ | ||
} | ||
friend bool operator<(const ThreadFd& lhs, const ThreadFd& rhs) | ||
{ | ||
if (lhs.fd == rhs.fd) | ||
{ | ||
return lhs.thread < rhs.thread; | ||
} | ||
|
||
return lhs.fd < rhs.fd; | ||
} | ||
|
||
friend bool operator==(const ThreadFd& lhs, const ThreadFd& rhs) | ||
{ | ||
return lhs.fd == rhs.fd && lhs.thread == rhs.thread; | ||
} | ||
|
||
private: | ||
int fd; | ||
Thread thread; | ||
}; | ||
|
||
trace::Trace& trace_; | ||
perf::time::Converter& time_converter_; | ||
|
||
std::map<Thread, int> last_fd_; | ||
std::map<Thread, uint64_t> last_count_; | ||
std::map<Thread, uint64_t> last_buf_; | ||
std::map<ThreadFd, int> instance_; | ||
std::unique_ptr<struct ring_buffer, RingBufferDeleter> rb_; | ||
std::unique_ptr<struct block_io_bpf, SkelDeleter> skel_; | ||
bool stop_ = false; | ||
}; | ||
|
||
} // namespace monitor | ||
} // namespace lo2s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* This file is part of the lo2s software. | ||
* Linux OTF2 sampling | ||
* | ||
* Copyright (c) 2016, | ||
* Technische Universitaet Dresden, Germany | ||
* | ||
* lo2s is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* lo2s is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with lo2s. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
struct trace_entry { | ||
short unsigned int type; | ||
unsigned char flags; | ||
unsigned char preempt_count; | ||
int pid; | ||
}; | ||
Check failure on line 29 in include/lo2s/perf/bio/common.h Code Style Turtle / Code Formatting Testinclude/lo2s/perf/bio/common.h#L24-L29
|
||
struct trace_event_raw_sched_process_exec | ||
{ | ||
struct trace_entry ent; | ||
unsigned int dev; | ||
unsigned long long int sector; | ||
unsigned int nr_sector; | ||
unsigned int bytes; | ||
}; | ||
|
||
struct block_io_event { | ||
unsigned long long int sector; | ||
unsigned int dev; | ||
unsigned int bytes; | ||
Check failure on line 42 in include/lo2s/perf/bio/common.h Code Style Turtle / Code Formatting Testinclude/lo2s/perf/bio/common.h#L39-L42
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.