/usr/bin/likwid-perfscope is in likwid 4.3.1+dfsg1-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 | #!/usr/bin/lua5.2
--[[
* =======================================================================================
*
* Filename: likwid-perfscope.lua
*
* Description: An application to use the timeline mode of likwid-perfctr to generate
* realtime plots using feedGnuplot
*
* Version: 4.3.1
* Released: 04.01.2018
*
* Author: Thomas Roehl (tr), thomas.roehl@googlemail.com
* Project: likwid
*
* Copyright (C) 2018 RRZE, University Erlangen-Nuremberg
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* =======================================================================================
]]
package.path = '/usr/share/lua/?.lua;' .. package.path
local likwid = require("likwid")
print_stdout = print
print_stderr = function(...) for k,v in pairs({...}) do io.stderr:write(v .. "\n") end end
PERFCTR="/usr/bin/likwid-perfctr"
FEEDGNUPLOT="/usr/bin/feedGnuplot"
local predefined_plots = {
FLOPS_DP = {
perfgroup = "FLOPS_DP",
ymetricmatch = "MFlops/s",
title = "Double Precision Flop Rate",
ytitle = "MFlops/s",
y2title = nil,
xtitle = "Time"
},
FLOPS_SP = {
perfgroup = "FLOPS_SP",
ymetricmatch = "MFlops/s",
title = "Single Precision Flop Rate",
ytitle = "MFlops/s",
y2title = nil,
xtitle = "Time"
},
L2 = {
perfgroup = "L2",
ymetricmatch = "L2D load bandwidth [MBytes/s]",
title = "L2 cache bandwidth",
ytitle = "Load Bandwidth [MBytes/s]",
y2metricmatch = "L2D evict bandwidth [MBytes/s]",
y2title = "Evict Bandwidth [MBytes/s]",
xtitle = "Time"
},
L3 = {
perfgroup = "L3",
ymetricmatch = "L3 load bandwidth [MBytes/s]",
title = "L3 cache bandwidth",
ytitle = "Load Bandwidth [MBytes/s]",
y2title = "Evict Bandwidth [MBytes/s]",
y2metricmatch = "L3 evict bandwidth [MBytes/s]",
xtitle = "Time"
},
MEM = {
perfgroup = "MEM",
ymetricmatch = "Memory bandwidth [MBytes/s]",
title = "Memory bandwidth",
ytitle = "Bandwidth [MBytes/s]",
y2title = nil,
xtitle = "Time"
},
QPI = {
perfgroup = "QPI",
ymetricmatch = "QPI data bandwidth [MByte/s]",
title = "QPI bandwidth",
ytitle = "Bandwidth [MBytes/s]",
y2title = nil,
xtitle = "Time",
y2metricmatch = "QPI link bandwidth [MByte/s]"
},
ENERGY = {
perfgroup = "ENERGY",
ymetricmatch = "Power [W]",
title = "Consumed energy",
ytitle = "Power [W]",
y2title = "Power DRAM [W]",
y2metricmatch = "Power DRAM [W]",
xtitle = "Time"
},
TEMP = {
perfgroup = "ENERGY",
ymetricmatch = "Temperature [C]",
title = "Temperature",
ytitle = "Temperature [C]",
y2title = nil,
xtitle = "Time"
},
NUMA = {
perfgroup = "NUMA",
ymetricmatch = "Local DRAM bandwidth [MByte/s]",
title = "NUMA separated memory bandwidth",
ytitle = "Bandwidth [MBytes/s]",
y2metricmatch = "Remote DRAM bandwidth [MByte/s]",
y2title = nil,
xtitle = "Time"
},
}
local function version()
print_stdout(string.format("likwid-perfscope -- Version %d.%d.%d (commit: %s)",likwid.version,likwid.release,likwid.minor,likwid.commit))
end
local function examples()
print_stdout("Examples:")
print_stdout("Run command on CPU 2 and measure performance group TEST:")
print_stdout("likwid-perfscope -C 2 -g TEST -f 1s ./a.out")
end
local function usage()
version()
print_stdout("A tool to generate pictures on-the-fly from likwid-perfctr measurements\n")
print_stdout("Options:")
print_stdout("-h, --help\t\t Help message")
print_stdout("-v, --version\t\t Version information")
print_stdout("-V, --verbose <level>\t Verbose output, 0 (only errors), 1 (info), 2 (details), 3 (developer)")
print_stdout("-a\t\t\t Print all preconfigured plot configurations for the current system.")
print_stdout("-c <list>\t\t Processor ids to measure, e.g. 1,2-4,8")
print_stdout("-C <list>\t\t Processor ids to pin threads and measure, e.g. 1,2-4,8")
print_stdout("-g, --group <string>\t Preconfigured plot group or custom event set string with plot config. See man page for information.")
print_stdout("-t, --time <time>\t Frequency in s, ms or us, e.g. 300ms, for the timeline mode of likwid-perfctr")
print_stdout("-f, --force\t\t Overwrite counter configuration although already in use")
print_stdout("-d, --dump\t\t Print output as it is send to feedGnuplot.")
print_stdout("-p, --plotdump\t\t Use dump functionality of feedGnuplot. Plots out plot configurations plus data to directly submit to gnuplot")
print_stdout("--host <host>\t\t Run likwid-perfctr on the selected host using SSH. Evaluation and plotting is done locally.")
print_stdout("\t\t\t This can be used for machines that have no gnuplot installed. All paths must be similar to the local machine.")
print_stdout("\n")
examples()
end
local function test_gnuplot()
cmd = "which gnuplot"
f = io.popen(cmd)
if f ~= nil then
io.close(f)
return true
end
return false
end
local eventStrings = {}
local terminal = "x11"
local num_cpus = 0
local cpulist = {}
local matchstring = nil
local group_list = {}
local timeline = "1s"
local print_configs = false
local pinning = false
local dump = false
local plotdump = false
local nrgroups, allgroups = likwid.get_groups()
local mfreq = 1.0
local plotrange = 0
local host = nil
local force = false
if #arg == 0 then
usage()
os.exit(0)
end
for opt,arg in likwid.getopt(arg, {"h","v","g:","C:","c:","t:","r:","a","d","p","f","help", "version","group:","time:","dump","range:","plotdump","all", "host:", "force"}) do
if opt == "h" or opt == "help" then
usage()
os.exit(0)
elseif opt == "v" or opt == "version" then
version()
os.exit(0)
elseif opt == "g" or opt == "group" then
table.insert(eventStrings, arg)
elseif (opt == "c") then
num_cpus, cpulist = likwid.cpustr_to_cpulist(arg)
elseif (opt == "C") then
num_cpus, cpulist = likwid.cpustr_to_cpulist(arg)
pinning = true
elseif opt == "t" or opt == "time" then
timeline = arg
mfreq = likwid.parse_time(timeline) * 1.E-6
elseif opt == "d" or opt == "dump" then
dump = true
elseif opt == "p" or opt == "plotdump" then
plotdump = true
elseif opt == "r" or opt == "range" then
plotrange = tonumber(arg)
elseif opt == "a" or opt == "all" then
print_configs = true
elseif opt == "host" then
host = arg
elseif opt == "f" or opt == "force" then
force = true
elseif opt == "?" then
print_stderr("Invalid commandline option -"..arg)
os.exit(1)
elseif opt == "!" then
print_stderr("Option requires an argument")
os.exit(1)
end
end
local execList = {}
for i=1, likwid.tablelength(arg)-2 do
table.insert(execList, arg[i])
end
if print_configs then
local num_groups, all_groups = likwid.get_groups()
for name, config in pairs(predefined_plots) do
for i,g in pairs(all_groups) do
if g == config["perfgroup"] then
print_stdout("Group "..name)
print_stdout("\tPerfctr group: "..config["perfgroup"])
print_stdout("\tMatch for metric: "..config["ymetricmatch"])
print_stdout("\tTitle of plot: "..config["title"])
print_stdout("\tTitle of x-axis: "..config["xtitle"])
print_stdout("\tTitle of y-axis: "..config["ytitle"])
if config["y2metricmatch"] then
print_stdout("\tMatch for second metric: "..config["y2metricmatch"])
end
if config["y2title"] then
print_stdout("\tTitle of y2-axis: "..config["y2title"])
elseif config["y2metricmatch"] then
print_stdout("\tTitle of y2-axis: "..config["ytitle"])
end
print_stdout("")
break
end
end
end
os.exit(0)
end
if not test_gnuplot() then
print_stderr("GnuPlot not available")
os.exit(1)
end
if num_cpus == 0 then
print_stderr("ERROR: CPU string must be given")
os.exit(1)
end
if #execList == 0 then
print_stderr("ERROR: Executable must be given on commandline")
os.exit(1)
end
for i, event_def in pairs(eventStrings) do
local eventlist = likwid.stringsplit(event_def,",")
event_string = nil
plotgroup = nil
plotgroupconfig = nil
plotdefgroup = false
for j, preconf in pairs(predefined_plots) do
if eventlist[1] == j then
for j,g in pairs(allgroups) do
if g == preconf["perfgroup"] then
event_string = preconf["perfgroup"]
plotdefgroup = true
plotgroupconfig = preconf
plotgroup = j
break;
end
end
break;
end
end
if #eventlist > 1 then
outopts = eventlist[#eventlist]
table.remove(eventlist, #eventlist)
end
if event_string == nil then
if plotdefgroup == false then
event_string = table.concat(eventlist,",")
end
end
local groupdata = nil
groupdata = likwid.get_groupdata(event_string)
if groupdata == nil then
print_stderr("Cannot read event string, it's neither a performance group nor a proper event string <event>:<counter>:<options>,...")
usage()
os.exit(1)
end
if group_list[i] == nil then
group_list[i] = {}
end
group_list[i]["gdata"] = groupdata
formulalist = nil
local title = nil
local ytitle = nil
local y2title = nil
local y2funcindex = nil
local xtitle = nil
local output = nil
if plotgroup ~= nil then
title = plotgroupconfig["title"]
ytitle = plotgroupconfig["ytitle"]
xtitle = plotgroupconfig["xtitle"]
if plotgroupconfig["y2title"] ~= nil then
y2title = plotgroupconfig["y2title"]
elseif plotgroupconfig["y2metricmatch"] ~= nil then
y2title = plotgroupconfig["ytitle"]
end
for i,mconfig in pairs(groupdata["Metrics"]) do
local mmatch = "%a*"..plotgroupconfig["ymetricmatch"]:gsub("%[","%%["):gsub("%]","%%]").."%a*"
if mconfig["description"]:match(mmatch) then
formulalist = {{name=mconfig["description"], index=i}}
end
if plotgroupconfig["y2metricmatch"] ~= nil then
mmatch = "%a*"..plotgroupconfig["y2metricmatch"]:gsub("%[","%%["):gsub("%]","%%]").."%a*"
if mconfig["description"]:match(mmatch) then
table.insert(formulalist, {name=mconfig["description"], index=i})
end
end
end
end
--[[for j,estr in pairs(likwid.stringsplit(outopts, ":")) do
if estr:match("^title=([%g%s]+)") then
title = estr:match("^title=([%g%s]+)")
elseif estr:match("^TITLE=([%g%s]+)") then
title = estr:match("^TITLE=([%g%s]+)")
elseif estr:match("ytitle=([%g%s]+)") then
ytitle = estr:match("ytitle=([%g%s]+)")
elseif estr:match("YTITLE=([%g%s]+)")then
ytitle = estr:match("YTITLE=([%g%s]+)")
elseif estr:match("y2title=(%d+)-([%g%s]+)") then
y2funcindex, y2title = estr:match("y2title=(%d+)-([%g%s]+)")
elseif estr:match("Y2TITLE=(%d+)-([%g%s]+)") then
y2funcindex, y2title = estr:match("Y2TITLE=(%d+)-([%g%s]+)")
elseif estr:match("y2title=([%g%s]+)") then
y2title = estr:match("y2title=([%g%s]+)")
elseif estr:match("Y2TITLE=([%g%s]+)") then
y2title = estr:match("Y2TITLE=([%g%s]+)")
elseif estr:match("xtitle=([%g%s]+)") then
xtitle = estr:match("xtitle=([%g%s]+)")
elseif estr:match("XTITLE=([%g%s]+)")then
xtitle = estr:match("XTITLE=([%g%s]+)")
elseif estr:match("[%g%s]+=[%g]+") then
fname, form = estr:match("([%g%s]+)=([%g]+)")
if formulalist == nil then
formulalist = {}
end
if groupdata["Metrics"] ~= nil then
for i,mconfig in pairs(groupdata["Metrics"]) do
if mconfig["description"]:match(fname) then
table.insert(formulalist, {name=fname, index=i})
break
end
end
else
table.insert(formulalist, {name=fname, formula=form})
end
end
end]]
group_list[i]["eventstring"] = event_string
group_list[i]["counterlist"] = {}
for k=1,#groupdata["Events"] do
table.insert(group_list[i]["counterlist"], groupdata["Events"][k]["Counter"])
end
if title then
group_list[i]["title"] = title
end
if ytitle then
group_list[i]["ytitle"] = ytitle
end
if y2title then
group_list[i]["y2title"] = y2title
end
if y2funcindex then
group_list[i]["y2funcindex"] = y2funcindex - 1
else
if formulalist ~= nil then
group_list[i]["y2funcindex"] = #formulalist - 1
end
end
if xtitle then
group_list[i]["xtitle"] = xtitle
end
if formulalist ~= nil then
group_list[i]["formulas"] = formulalist
else
group_list[i]["formulas"] = {}
end
end
cmd = ""
if host ~= nil then
cmd = cmd .. "ssh "..host.. " \"/bin/bash -c \\\" "
end
cmd = cmd .. " " ..PERFCTR
if pinning then
cmd = cmd .. string.format(" -C %s",table.concat(cpulist,","))
else
cmd = cmd .. string.format(" -c %s",table.concat(cpulist,","))
end
if force then
cmd = cmd .. " -f"
end
cmd = cmd .. string.format(" -t %s", timeline)
for i, group in pairs(group_list) do
cmd = cmd .. " -g "..group["eventstring"]
end
cmd = cmd .. " ".. table.concat(execList, " ")
-- since io.popen can only read stdout we swap stdout and stderr
-- application output is written to stderr, we catch stdout
cmd = cmd .. " 3>&1 1>&2 2>&3 3>&-"
if host ~= nil then
cmd = cmd .. " \\\" \" "
end
for i, group in pairs(group_list) do
gnucmd = string.format("%s --stream %f --with linespoints --domain --nodataid", FEEDGNUPLOT, mfreq/#group_list)
extracmds = {'set xtics font \",10\"', 'set ytics font \",10\"', 'set y2tics font \",10\"',
'set bmargin 10', 'set key font \",12\"' }
gnucmd = gnucmd .. " --geometry \"1280,1024\""
if plotrange > 0 then
gnucmd = gnucmd .. string.format(" --xlen %d", plotrange)
else
gnucmd = gnucmd .. " --xmin 0"
end
if group["title"] ~= nil then
if #group_list > 1 then
--gnucmd = gnucmd .. string.format(" --title %q", "Group "..i..": "..group["title"])
table.insert(extracmds, string.format("set title 'Group %d: %s' font \",12\"", i, group["title"]))
else
--gnucmd = gnucmd .. string.format(" --title %q", group["title"])
table.insert(extracmds, string.format("set title %q font \",12\"", group["title"]))
end
end
if group["xtitle"] ~= nil then
--gnucmd = gnucmd .. string.format(" --xlabel %q", group["xtitle"])
table.insert(extracmds, string.format("set xlabel %q font \",12\"", group["xtitle"]))
else
--gnucmd = gnucmd .. string.format(" --xlabel %q", "Time")
table.insert(extracmds, "set xlabel 'Time' font \",12\"")
end
if group["ytitle"] ~= nil then
--gnucmd = gnucmd .. string.format(" --ylabel %q", group["ytitle"])
table.insert(extracmds, string.format("set ylabel %q font \",12\"", group["ytitle"]))
end
if group["y2title"] ~= nil then
gnucmd = gnucmd .. string.format(" --y2 %d", group["y2funcindex"])
table.insert(extracmds, string.format("set y2label %q font \",12\"", group["y2title"]))
end
if group["formulas"] then
if #cpulist == 1 then
for f, fdesc in pairs(group["formulas"]) do
gnucmd = gnucmd .. string.format(" --legend %d %q", f-1, fdesc["name"])
end
else
local curveID = 0
for c,cpu in pairs(cpulist) do
for f, fdesc in pairs(group["formulas"]) do
gnucmd = gnucmd .. string.format(" --legend %d %q", curveID, "C"..cpu..": "..fdesc["name"])
curveID = curveID + 1
end
end
end
end
gnucmd = gnucmd .. " --set 'key outside bmargin bottom'"
gnucmd = gnucmd .. string.format(" --extracmds '%s'", table.concat(extracmds, ";"))
if plotdump then
gnucmd = gnucmd .. " --dump"
else
gnucmd = gnucmd .. " 1>/dev/null 2>&1"
end
group_list[i]["output"] = assert(io.popen(gnucmd,"w"))
end
likwid.catchSignal()
local mtime = {}
for i,g in pairs(group_list) do
local str = "0 "
for k,t in pairs(cpulist) do
for j,c in pairs(g["formulas"]) do
str = str .."0 "
end
end
mtime[i] = nil
g["output"]:write(str.."\n")
g["output"]:flush()
if dump then
print_stdout(tostring(i).." ".. str)
end
end
perfctr = assert (io.popen (cmd))
olddata = {}
oldmetric = {}
local perfctr_exited = false
local oldtime = 0
local clock = likwid.getCpuClock()
while true do
local l = perfctr:read("*line")
if l == nil then
break
end
if l:match("^%d+ %d+ %d+ [%d.]+ %d+") then
local data = {}
local diff = {}
linelist = likwid.stringsplit(l, " ")
group = tonumber(linelist[1])
nr_events = tonumber(linelist[2])
nr_threads = tonumber(linelist[3])
time = tonumber(linelist[4])
table.remove(linelist, 1)
table.remove(linelist, 1)
table.remove(linelist, 1)
table.remove(linelist, 1)
for i=1,nr_events do
if data[i] == nil then data[i] = {} end
for j=1,nr_threads do
data[i][j] = tonumber(linelist[1])
table.remove(linelist, 1)
end
end
str = tostring(time)
for f, flist in pairs(group_list[group]["formulas"]) do
if flist["index"] ~= nil then
for i=1,nr_threads do
str = str .." ".. data[flist["index"]][i]
end
end
end
group_list[group]["output"]:write(str.."\n")
group_list[group]["output"]:flush()
if dump then
print_stdout(tostring(group).." ".. str)
end
oldtime = time
end
end
if perfctr_exited == false then
while likwid.getSignalState() == 0 do
likwid.sleep(1E6)
end
end
for i, group in pairs(group_list) do
group["output"]:write("exit\n")
io.close(group["output"])
end
io.close(perfctr)
|