Processor Counter Monitor
Classes | Macros | Typedefs | Enumerations | Functions | Variables
pcm-raw.cpp File Reference

Example of using CPU counters: implements a performance counter monitoring utility with raw events interface. More...

#include <iostream>
#include <unistd.h>
#include <signal.h>
#include <sys/time.h>
#include <math.h>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <assert.h>
#include <bitset>
#include <regex>
#include <unordered_map>
#include "cpucounters.h"
#include "utils.h"
#include <vector>
Include dependency graph for pcm-raw.cpp:

Classes

struct  PrintOffset
 

Macros

#define PCM_DELAY_MIN   0.015
 
#define MAX_CORES   4096
 

Typedefs

typedef uint64(* UncoreMetricFunc) (const uint32 u, const uint32 i, const ServerUncoreCounterState &before, const ServerUncoreCounterState &after)
 
typedef uint64(* UncoreFixedMetricFunc) (const uint32 u, const ServerUncoreCounterState &before, const ServerUncoreCounterState &after)
 

Enumerations

enum  MSRScope { Thread, Package }
 

Functions

void print_usage (const string &progname)
 
PCM::RawEventConfig initCoreConfig ()
 
void printEvent (const std::string &pmuName, const bool fixed, const PCM::RawEventConfig &config)
 
void lowerCase (std::string &str)
 
bool addEvent (PCM::RawPMUConfigs &curPMUConfigs, string eventStr)
 
bool addEvents (std::vector< PCM::RawPMUConfigs > &PMUConfigs, string fn)
 
int getPrintOffsetIdx (const std::string &value)
 
void printNewLine (const CsvOutputType outputType)
 
void printRowBeginCSV (const std::string &EventName, const CoreCounterState &BeforeState, const CoreCounterState &AfterState, PCM *m)
 
void printRowBeginJson (const std::string &EventName, const CoreCounterState &BeforeState, const CoreCounterState &AfterState, PCM *m)
 
void printRowBegin (const std::string &EventName, const CoreCounterState &BeforeState, const CoreCounterState &AfterState, PCM *m, const CsvOutputType outputType, PrintOffset &printOffset)
 
template<class MetricFunc >
void printRow (const std::string &EventName, MetricFunc metricFunc, const std::vector< CoreCounterState > &BeforeState, const std::vector< CoreCounterState > &AfterState, PCM *m, const CsvOutputType outputType, PrintOffset &printOffset)
 
uint64 nullFixedMetricFunc (const uint32, const ServerUncoreCounterState &, const ServerUncoreCounterState &)
 
std::string getMSREventString (const uint64 &index, const std::string &type, const PCM::MSRType &msrType)
 
void printTransposed (const PCM::RawPMUConfigs &curPMUConfigs, PCM *m, vector< CoreCounterState > &BeforeState, vector< CoreCounterState > &AfterState, vector< ServerUncoreCounterState > &BeforeUncoreState, vector< ServerUncoreCounterState > &AfterUncoreState, vector< SocketCounterState > &BeforeSocketState, vector< SocketCounterState > &AfterSocketState, const CsvOutputType outputType, const bool &isLastGroup)
 
void print (const PCM::RawPMUConfigs &curPMUConfigs, PCM *m, vector< CoreCounterState > &BeforeState, vector< CoreCounterState > &AfterState, vector< ServerUncoreCounterState > &BeforeUncoreState, vector< ServerUncoreCounterState > &AfterUncoreState, vector< SocketCounterState > &BeforeSocketState, vector< SocketCounterState > &AfterSocketState, const CsvOutputType outputType)
 
void printAll (const PCM::RawPMUConfigs &curPMUConfigs, PCM *m, vector< CoreCounterState > &BeforeState, vector< CoreCounterState > &AfterState, vector< ServerUncoreCounterState > &BeforeUncoreState, vector< ServerUncoreCounterState > &AfterUncoreState, vector< SocketCounterState > &BeforeSocketState, vector< SocketCounterState > &AfterSocketState, std::vector< PCM::RawPMUConfigs > &PMUConfigs, const bool &isLastGroup)
 
int main (int argc, char *argv[])
 

Variables

bool verbose = false
 
double defaultDelay = 1.0
 
bool show_partial_core_output = false
 
bitset< MAX_CORES > ycores
 
bool flushLine = false
 
bool transpose = false
 
bool extendPrintout = false
 
bool singleHeader = false
 
std::string separator = ","
 
const std::string jsonSeparator = "\":"
 
bool sampleSeparator = false
 
bool outputToJson = false
 
std::vector< PrintOffsetprintOffsets
 
std::vector< std::string > printedBlocks
 
const char * fixedCoreEventNames [] = { "InstructionsRetired" , "Cycles", "RefCycles", "TopDownSlots" }
 
const char * topdownEventNames [] = { "PERF_METRICS.FRONTEND_BOUND" , "PERF_METRICS.BAD_SPECULATION", "PERF_METRICS.BACKEND_BOUND", "PERF_METRICS.RETIRING" }
 
constexpr uint32 PerfMetricsConfig = 2
 
constexpr uint64 PerfMetricsMask = 1ULL
 
constexpr uint64 maxPerfMetricsValue = 255ULL
 

Detailed Description

Example of using CPU counters: implements a performance counter monitoring utility with raw events interface.