📄 cyclecountaccum.cc
字号:
// -*- c-basic-offset: 4 -*-/* * cyclecountaccum.{cc,hh} -- accumulate cycle counter deltas * Eddie Kohler * * Copyright (c) 1999-2000 Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, subject to the conditions * listed in the Click LICENSE file. These conditions include: you must * preserve this copyright notice, and you cannot mention the copyright * holders in advertising related to the Software without their permission. * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This * notice is a summary of the Click LICENSE file; the license in that file is * legally binding. */#include <click/config.h>#include "cyclecountaccum.hh"#include <click/glue.hh>CycleCountAccum::CycleCountAccum() : Element(1, 1), _accum(0), _count(0), _zero_count(0){}CycleCountAccum::~CycleCountAccum(){}inline voidCycleCountAccum::smaction(Packet *p){ if (p->perfctr_anno()) { _accum += click_get_cycles() - p->perfctr_anno(); _count++; } else { _zero_count++; if (_zero_count == 1) click_chatter("%s: packet with zero cycle counter annotation!", declaration().c_str()); }}voidCycleCountAccum::push(int, Packet *p){ smaction(p); output(0).push(p);}Packet *CycleCountAccum::pull(int){ Packet *p = input(0).pull(); if (p) smaction(p); return p;}StringCycleCountAccum::read_handler(Element *e, void *thunk){ CycleCountAccum *cca = static_cast<CycleCountAccum *>(e); switch ((uintptr_t)thunk) { case 0: return String(cca->_count) + "\n"; case 1: return String(cca->_accum) + "\n"; case 2: return String(cca->_zero_count) + "\n"; default: return String(); }}intCycleCountAccum::reset_handler(const String &, Element *e, void *, ErrorHandler *){ CycleCountAccum *cca = static_cast<CycleCountAccum *>(e); cca->_count = cca->_accum = cca->_zero_count = 0; return 0;}voidCycleCountAccum::add_handlers(){ add_read_handler("count", read_handler, (void *)0); add_read_handler("cycles", read_handler, (void *)1); add_read_handler("zero_count", read_handler, (void *)2); add_write_handler("reset_counts", reset_handler, (void *)0);}ELEMENT_REQUIRES(linuxmodule)EXPORT_ELEMENT(CycleCountAccum)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -