install(TARGETS bcc-shared LIBRARY COMPONENT libbcc
DESTINATION ${CMAKE_INSTALL_LIBDIR})
-install(FILES bpf_common.h bpf_module.h bcc_syms.h bcc_exception.h libbpf.h perf_reader.h BPF.h BPFTable.h shared_table.h table_desc.h table_storage.h COMPONENT libbcc
+install(FILES bpf_common.h bpf_module.h bcc_syms.h bcc_exception.h file_desc.h
+ libbpf.h perf_reader.h BPF.h BPFTable.h shared_table.h
+ table_desc.h table_storage.h COMPONENT libbcc
DESTINATION include/bcc)
install(DIRECTORY compat/linux/ COMPONENT libbcc
DESTINATION include/bcc/compat/linux
*/
#include <fstream>
#include <sstream>
-#include <unistd.h>
#include "common.h"
return read_cpu_range("/sys/devices/system/cpu/possible");
}
-FileDesc::FileDesc(int fd) : fd_(fd) {}
-
-FileDesc::FileDesc(FileDesc &&that) : fd_(-1) { *this = std::move(that); }
-
-FileDesc::~FileDesc() {
- if (fd_ >= 0)
- ::close(fd_);
-}
-
-FileDesc &FileDesc::operator=(int fd) {
- if (fd_ >= 0)
- ::close(fd_);
- fd_ = fd;
- return *this;
-}
-
-FileDesc &FileDesc::operator=(FileDesc &&that) {
- if (fd_ >= 0)
- ::close(fd_);
- fd_ = that.fd_;
- that.fd_ = -1;
- return *this;
-}
-
-FileDesc FileDesc::dup() const {
- int dup_fd = ::dup(fd_);
- return FileDesc(dup_fd);
-}
-
-FileDesc::operator int() { return fd_; }
-
-FileDesc::operator int() const { return fd_; }
-
} // namespace ebpf
#pragma once
#include <memory>
-#include <string>
-#include <tuple>
#include <vector>
namespace ebpf {
std::vector<int> get_possible_cpus();
-/// FileDesc is a helper class for managing open file descriptors. Copy is
-/// disallowed (call dup instead), and cleanup happens automatically.
-class FileDesc {
- public:
- explicit FileDesc(int fd = -1);
- FileDesc(FileDesc &&that);
- FileDesc(const FileDesc &that) = delete;
-
- ~FileDesc();
-
- FileDesc &operator=(int fd);
- FileDesc &operator=(FileDesc &&that);
- FileDesc &operator=(const FileDesc &that) = delete;
-
- operator int();
- operator int() const;
-
- FileDesc dup() const;
-
- private:
- int fd_;
-};
-
} // namespace ebpf
--- /dev/null
+/*
+ * Copyright (c) 2017 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <unistd.h>
+
+namespace ebpf {
+
+/// FileDesc is a helper class for managing open file descriptors. Copy is
+/// disallowed (call dup instead), and cleanup happens automatically.
+class FileDesc {
+ public:
+ explicit FileDesc(int fd = -1) : fd_(fd) {}
+ FileDesc(FileDesc &&that) : fd_(-1) { *this = std::move(that); }
+ FileDesc(const FileDesc &that) = delete;
+
+ ~FileDesc() {
+ if (fd_ >= 0)
+ ::close(fd_);
+ }
+
+ FileDesc &operator=(int fd) {
+ if (fd_ >= 0)
+ ::close(fd_);
+ fd_ = fd;
+ return *this;
+ }
+ FileDesc &operator=(FileDesc &&that) {
+ if (fd_ >= 0)
+ ::close(fd_);
+ fd_ = that.fd_;
+ that.fd_ = -1;
+ return *this;
+ }
+ FileDesc &operator=(const FileDesc &that) = delete;
+
+ FileDesc dup() const {
+ int dup_fd = ::dup(fd_);
+ return FileDesc(dup_fd);
+ }
+
+ operator int() { return fd_; }
+ operator int() const { return fd_; }
+
+ private:
+ int fd_;
+};
+
+} // namespace ebpf
#include <llvm/IR/Module.h>
#include "bcc_exception.h"
-#include "common.h"
#include "codegen_llvm.h"
+#include "file_desc.h"
#include "lexer.h"
#include "libbpf.h"
#include "linux/bpf.h"
#include <unordered_set>
#include <vector>
-#include "common.h"
+#include "file_desc.h"
class ProcStat {
std::string procfs_;
#include <string>
#include "bcc_exception.h"
-#include "common.h"
+#include "file_desc.h"
namespace clang {
class ASTContext;