Commit 2ee7b564 authored by Alastair Robertson's avatar Alastair Robertson

Stop running and print out maps on ctrl-c

parent 9bedb630
#include <iostream>
#include <tuple>
#include <sys/utsname.h>
#include <unistd.h>
......
#pragma once
#include "bpftrace.h"
#include "types.h"
namespace bpftrace {
......
......@@ -22,9 +22,8 @@ int BPFtrace::add_probe(ast::Probe &p)
return 0;
}
int BPFtrace::run()
int BPFtrace::start()
{
std::vector<std::unique_ptr<AttachedProbe>> attached_probes;
for (Probe &probe : probes_)
{
auto func = sections_.find(probe.name);
......@@ -35,7 +34,7 @@ int BPFtrace::run()
}
try
{
attached_probes.push_back(std::make_unique<AttachedProbe>(probe, func->second));
attached_probes_.push_back(std::make_unique<AttachedProbe>(probe, func->second));
}
catch (std::runtime_error e)
{
......@@ -43,13 +42,14 @@ int BPFtrace::run()
return -1;
}
}
// TODO wait here while script is running
getchar();
return 0;
}
void BPFtrace::stop()
{
attached_probes_.clear();
}
int BPFtrace::print_maps()
{
for(auto &mapmap : maps_)
......
......@@ -5,6 +5,7 @@
#include <vector>
#include "ast.h"
#include "attached_probe.h"
#include "map.h"
#include "types.h"
......@@ -15,7 +16,8 @@ class BPFtrace
public:
virtual ~BPFtrace() { }
virtual int add_probe(ast::Probe &p);
int run();
int start();
void stop();
int print_maps();
std::map<std::string, std::unique_ptr<Map>> maps_;
......@@ -23,6 +25,8 @@ public:
private:
std::vector<Probe> probes_;
std::vector<std::unique_ptr<AttachedProbe>> attached_probes_;
int print_map(Map &map);
int print_map_quantize(Map &map);
int print_quantize(std::vector<uint64_t> values);
......
#include <iostream>
#include <signal.h>
#include <unistd.h>
#include "bpftrace.h"
#include "codegen_llvm.h"
#include "driver.h"
......@@ -89,10 +91,23 @@ int main(int argc, char *argv[])
if (debug)
return 0;
err = bpftrace.run();
// Empty signal handler just to break out of the sleep below
struct sigaction act;
act.sa_handler = [](int) { };
sigaction(SIGINT, &act, NULL);
std::cout << "Running... press Ctrl-C to stop" << std::endl;
err = bpftrace.start();
if (err)
return err;
sleep(99999999);
bpftrace.stop();
std::cout << "\n\n";
err = bpftrace.print_maps();
if (err)
return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment