加载文件时发生错误。请再试一次。
加载文件时发生错误。请再试一次。
加载文件时发生错误。请再试一次。
-
由 Alexei Starovoitov 创作于
during debug of production systems it's difficult to trace back the kernel reported 'bpf_prog_4985bb0bd6c69631' symbols to the source code of the program, hence teach bcc to store the main function source in the /var/tmp/bcc/bpf_prog_4985bb0bd6c69631/ directory. This program tag is stable. Every time the script is called the tag will be the same unless source code of the program changes. During active development of bcc scripts the /var/tmp/bcc/ dir can get a bunch of stale tags. The users have to trim that dir manually. Python scripts can be modified to use this feature too, but probably need to be gated by the flag. For c++ api I think it makes sense to store the source code always, since the cost is minimal and c++ api is used by long running services. Example: $ ./examples/cpp/LLCStat $ ls -l /var/tmp/bcc/bpf_prog_4985bb0bd6c69631/ total 16 -rw-r--r--. 1 root root 226 Sep 1 17:30 on_cache_miss.c -rw-r--r--. 1 root root 487 Sep 1 17:30 on_cache_miss.rewritten.c -rw-r--r--. 1 root root 224 Sep 1 17:30 on_cache_ref.c -rw-r--r--. 1 root root 484 Sep 1 17:30 on_cache_ref.rewritten.c Note that there are two .c files there, since two different bpf programs have exactly the same bytecode hence same prog_tag. $ cat /var/tmp/bcc/bpf_prog_4985bb0bd6c69631/on_cache_miss.c int on_cache_miss(struct bpf_perf_event_data *ctx) { struct event_t key = {}; get_key(&key); u64 zero = 0, *val; val = miss_count.lookup_or_init(&key, &zero); ... Signed-off-by:
Alexei Starovoitov <ast@fb.com>
4f47e3b5
/*
* Copyright (c) 2015 PLUMgrid, 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.
*/
#include <algorithm>
#include <fcntl.h>
#include <ftw.h>
#include <map>
#include <stdio.h>
#include <string>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <unistd.h>
#include <vector>
#include <linux/bpf.h>
#include <llvm/ADT/STLExtras.h>
#include <llvm/ExecutionEngine/MCJIT.h>
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
#include <llvm/IRReader/IRReader.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/IRPrintingPasses.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Object/ObjectFile.h>
#include <llvm/Support/FormattedStream.h>
#include <llvm/Support/Host.h>
#include <llvm/Support/SourceMgr.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
#include <llvm-c/Transforms/IPO.h>
#include "bcc_exception.h"
#include "frontends/b/loader.h"
#include "frontends/clang/loader.h"
#include "frontends/clang/b_frontend_action.h"
#include "bpf_module.h"
#include "exported_files.h"
#include "kbuild_helper.h"
#include "libbpf.h"
namespace ebpf {
using std::get;
using std::make_tuple;
using std::map;
using std::move;
using std::string;
using std::tuple;
using std::unique_ptr;
using std::vector;
using namespace llvm;
const string BPFModule::FN_PREFIX = BPF_FN_PREFIX;
// Snooping class to remember the sections as the JIT creates them