/**
* Copyright 2010-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "hardware-counter.h"
#ifndef NO_HARDWARE_COUNTERS
#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <assert.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <asm/unistd.h>
#include <sys/prctl.h>
#include <linux/perf_event.h>
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
IMPLEMENT_THREAD_LOCAL_NO_CHECK(HardwareCounter,
HardwareCounter::s_counter);
static bool s_recordSubprocessTimes = false;
static bool s_profileHWEnable;
static std::string s_profileHWEvents;
static inline bool useCounters() {
#ifdef VALGRIND
return false;
#else
return s_profileHWEnable;
#endif
}
class HardwareCounterImpl {
public:
HardwareCounterImpl(int type, unsigned long config,
const char* desc = nullptr)
: m_desc(desc ? desc : ""), m_err(0), m_fd(-1), inited(false) {
memset (&pe, 0, sizeof (struct perf_event_attr));
pe.type = type;
pe.size = sizeof (struct perf_event_attr);
pe.config = config;
pe.inherit = s_recordSubprocessTimes;
pe.disabled = 1;
pe.pinned = 0;
pe.exclude_kernel = 0;
pe.exclude_hv = 1;
pe.read_format =
PERF_FORMAT_TOTAL_TIME_ENABLED|PERF_FORMAT_TOTAL_TIME_RUNNING;
}
~HardwareCounterImpl() {
close();
}
void init_if_not() {
/*
* perf_event_open(struct perf_event_attr *hw_event_uptr, pid_t pid,
* int cpu, int group_fd, unsigned long flags)
*/
if (inited) return;
inited = true;
m_fd = syscall(__NR_perf_event_open, &pe, 0, -1, -1, 0);
if (m_fd < 0) {
// Logger::Verbose("perf_event_open failed with: %s",
// folly::errnoStr(errno).c_str());
m_err = -1;
return;
}
if (ioctl(m_fd, PERF_EVENT_IOC_ENABLE, 0) < 0) {
// Logger::Warning("perf_event failed to enable: %s",
// folly::errnoStr(errno).c_str());
close();
m_err = -1;
return;
}
reset();
}
int64_t read() {
uint64_t values[3];
if (readRaw(values)) {
if (!values[2]) return 0;
int64_t value = (double)values[0] * values[1] / values[2];
return value + extra;
}
return 0;
}
void incCount(int64_t amount) {
extra += amount;
}
bool readRaw(uint64_t* values) {
if (m_err || !useCounters()) return false;
init_if_not();
if (m_fd > 0) {
/*
* read the count + scaling values
*
* It is not necessary to stop an event to read its value
*/
auto ret = ::read(m_fd, values, sizeof(*values) * 3);
if (ret == sizeof(*values) * 3) {
values[0] -= reset_values[0];
values[1] -= reset_values[1];
values[2] -= reset_values[2];
return true;
}
}
return false;
}
void reset() {
if (m_err || !useCounters()) return;
init_if_not();
extra = 0;
if (m_fd > 0) {
if (ioctl (m_fd, PERF_EVENT_IOC_RESET, 0) < 0) {
// Logger::Warning("perf_event failed to reset with: %s",
// folly::errnoStr(errno).c_str());
m_err = -1;
return;
}
auto ret = ::read(m_fd, reset_values, sizeof(reset_values));
if (ret != sizeof(reset_values)) {
// Logger::Warning("perf_event failed to reset with: %s",
// folly::errnoStr(errno).c_str());
m_err = -1;
return;
}
}
}
public:
std::string m_desc;
int m_err;
private:
int m_fd;
struct perf_event_attr pe;
bool inited;
uint64_t reset_values[3];
uint64_t extra{0};
void close() {
if (m_fd > 0) {
::close(m_fd);
m_fd = -1;
}
}
};
class InstructionCounter : public HardwareCounterImpl {
public:
InstructionCounter() :
HardwareCounterImpl(PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS) {}
};
class LoadCounter : public HardwareCounterImpl {
public:
LoadCounter() :
HardwareCounterImpl(PERF_TYPE_HW_CACHE,
(PERF_COUNT_HW_CACHE_L1D | ((PERF_COUNT_HW_CACHE_OP_READ) << 8))) {}
};
class StoreCounter : public HardwareCounterImpl {
public:
StoreCounter() :
HardwareCounterImpl(PERF_TYPE_HW_CACHE,
PERF_COUNT_HW_CACHE_L1D | ((PERF_COUNT_HW_CACHE_OP_WRITE) << 8)) {}
};
HardwareCounter::HardwareCounter()
: m_countersSet(false) {
m_instructionCounter.reset(new InstructionCounter());
if (s_profileHWEvents.empty()) {
m_loadCounter.reset(new LoadCounter());
m_storeCounter.reset(new StoreCounter());
} else {
m_countersSet = true;
setPerfEvents(s_profileHWEvents);
}
}
HardwareCounter::~HardwareCounter() {
}
void HardwareCounter::Init(bool enable, const std::string& events,
bool subProc) {
s_profileHWEnable = enable;
s_profileHWEvents = events;
s_recordSubprocessTimes = subProc;
}
void HardwareCounter::Reset() {
s_counter->reset();
}
void HardwareCounter::reset() {
m_instructionCounter->reset();
if (!m_countersSet) {
m_storeCounter->reset();
m_loadCounter->reset();
}
for (unsigned i = 0; i < m_counters.size(); i++) {
m_counters[i]->reset();
}
}
int64_t HardwareCounter::GetInstructionCount() {
return s_counter->getInstructionCount();
}
int64_t HardwareCounter::getInstructionCount() {
return m_instructionCounter->read();
}
int64_t HardwareCounter::GetLoadCount() {
return s_counter->getLoadCount();
}
int64_t HardwareCounter::getLoadCount() {
return m_loadCounter->read();
}
int64_t HardwareCounter::GetStoreCount() {
return s_counter->getStoreCount();
}
int64_t HardwareCounter::getStoreCount() {
return m_storeCounter->read();
}
void HardwareCounter::IncInstructionCount(int64_t amount) {
s_counter->m_instructionCounter->incCount(amount);
}
void HardwareCounter::IncLoadCount(int64_t amount) {
if (!s_counter->m_countersSet) {
s_counter->m_loadCounter->incCount(amount);
}
}
void HardwareCounter::IncStoreCount(int64_t amount) {
if (!s_counter->m_countersSet) {
s_counter->m_storeCounter->incCount(amount);
}
}
struct PerfTable perfTable[] = {
/* PERF_TYPE_HARDWARE events */
#define PC(n) PERF_TYPE_HARDWARE, PERF_COUNT_HW_ ## n
{ "cpu-cycles", PC(CPU_CYCLES) },
{ "cycles", PC(CPU_CYCLES) },
{ "instructions", PC(INSTRUCTIONS) },
{ "cache-references", PC(CACHE_REFERENCES) },
{ "cache-misses", PC(CACHE_MISSES) },
{ "branch-instructions", PC(BRANCH_INSTRUCTIONS) },
{ "branches", PC(BRANCH_INSTRUCTIONS) },
{ "branch-misses", PC(BRANCH_MISSES) },
{ "bus-cycles", PC(BUS_CYCLES) },
{ "stalled-cycles-frontend", PC(STALLED_CYCLES_FRONTEND) },
{ "stalled-cycles-backend", PC(STALLED_CYCLES_BACKEND) },
/* PERF_TYPE_HW_CACHE hw_cache_id */
#define PCC(n) PERF_TYPE_HW_CACHE, PERF_COUNT_HW_CACHE_ ## n
{ "L1-dcache-", PCC(L1D) },
{ "L1-icache-", PCC(L1I) },
{ "LLC-", PCC(LL) },
{ "dTLB-", PCC(DTLB) },
{ "iTLB-", PCC(ITLB) },
{ "branch-", PCC(BPU) },
/* PERF_TYPE_HW_CACHE hw_cache_op, hw_cache_result */
#define PCCO(n, m) PERF_TYPE_HW_CACHE, \
((PERF_COUNT_HW_CACHE_OP_ ## n) << 8 | \
(PERF_COUNT_HW_CACHE_RESULT_ ## m) << 16)
{ "loads", PCCO(READ, ACCESS) },
{ "load-misses", PCCO(READ, MISS) },
{ "stores",
没有合适的资源?快使用搜索试试~ 我知道了~
react-15.1.0.tar.gz
需积分: 0 0 下载量 97 浏览量
2024-05-04
14:34:16
上传
评论
收藏 39.62MB GZ 举报
温馨提示
react.js for linux 各个版本,免费下载 前端三大框架之一 react 各个版本,免费下载 如果下载不了,关注我,评论区联系我 React 是一个库。它允许你将组件放在一起,但不关注路由和数据获取。要使用 React 构建整个应用程序,建议使用像 Next.js 或 Remix 这样的全栈 React 框架。
资源推荐
资源详情
资源评论
收起资源包目录
react-15.1.0.tar.gz (1035个子文件)
AUTHORS 25KB
authors 284B
.babelrc 975B
.babelrc 37B
ReactCoffeeScriptClass-test.coffee 11KB
hardware-counter.cpp 13KB
jsc-perf.cpp 5KB
thread-local.cpp 2KB
perf-counters.cpp 2KB
codemirror.css 6KB
syntax.css 4KB
main.css 3KB
base.css 835B
transition.css 761B
example.css 28B
.editorconfig 293B
.eslintignore 386B
.eslintrc 113B
Gemfile 287B
steve_reverse.gif 5.4MB
devtools-full.gif 1.35MB
modus-create.gif 992KB
devtools-search.gif 929KB
gpu-cursor-move.gif 790KB
monkeys.gif 532KB
devtools-side-pane.gif 43KB
.gitattributes 12B
.gitignore 349B
.gitignore 13B
binding.gyp 259B
thread-local.h 19KB
portability.h 5KB
hardware-counter.h 3KB
default.html 5KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1KB
nav_docs.html 1024B
index.html 867B
index.html 729B
docs.html 720B
blog_post.html 656B
single.html 605B
tips.html 568B
all.html 530B
nav_blog.html 381B
redirect.html 324B
post.html 242B
page.html 83B
favicon.ico 24KB
react-dev-tools.jpg 81KB
polarr.jpg 69KB
parse-react.jpg 56KB
animal-sounds.jpg 52KB
react-hackathon.jpg 51KB
guess_filter.jpg 40KB
react-browserify-gulp.jpg 25KB
react.js 644KB
bench-pe-es5.js 259KB
codemirror.js 232KB
webcomponents.js 227KB
bench-pe.js 179KB
ReactDOMComponent-test.js 44KB
ReactComponentTreeDevtool-test.js 42KB
ResponderEventPlugin-test.js 42KB
ReactComponentTreeDevtool-test.native.js 41KB
ReactCompositeComponent.js 36KB
ReactDOMComponent.js 36KB
ReactCompositeComponent-test.js 35KB
ReactUpdates-test.js 30KB
ReactPropTypes-test.js 26KB
ReactClass.js 25KB
ResponderEventPlugin.js 24KB
ReactMount.js 24KB
ReactDOMInput-test.js 23KB
ReactNativeOperationHistoryDevtool-test.js 22KB
ReactDOMSelect-test.js 20KB
ReactMultiChildReconcile-test.js 20KB
ReactTestUtils.js 19KB
marked.min.js 19KB
SimpleEventPlugin.js 19KB
ReactElement-test.js 18KB
ReactComponentLifeCycle-test.js 17KB
es5-shim.min.js 17KB
ReactTestUtils-test.js 15KB
ReactElementValidator-test.js 15KB
javascript.js 15KB
ReactChildren-test.js 14KB
ReactNativeAttributePayload.js 14KB
traverseAllChildren-test.js 14KB
bench-createclass.js 14KB
BeforeInputEventPlugin.js 14KB
共 1035 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
资源评论
段子手-168
- 粉丝: 4486
- 资源: 2745
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 聚类算法上手操作说明.pptx
- 《异形大战铁血战士 2》的 DirectX 11 渲染器.zip
- 《使命召唤 4》dll 使用 DirectX 9 挂钩计算玩家速度来绘制 UI.zip
- 基于微信小程序的校园二手交易平台小程序高分毕业设计项目 (源码+使用教程)
- 《Wing Commander Kilrathi Saga》的 DirectX DLL 和其他增强功能.zip
- 机载激光雷达点云等高线批量提取,断裂线提取流程
- TigerBot使用的微调中文数据集
- yolov8 tensorrt python推理
- sigcheck执行程序
- sharegpt格式的中文多轮对话微调数据集,模拟用户与AI间的交互
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功