1203790Sfabient/*- 2203790Sfabient * Copyright (c) 2009, Fabien Thomas 3203790Sfabient * All rights reserved. 4203790Sfabient * 5203790Sfabient * Redistribution and use in source and binary forms, with or without 6203790Sfabient * modification, are permitted provided that the following conditions 7203790Sfabient * are met: 8203790Sfabient * 1. Redistributions of source code must retain the above copyright 9203790Sfabient * notice, this list of conditions and the following disclaimer. 10203790Sfabient * 2. Redistributions in binary form must reproduce the above copyright 11203790Sfabient * notice, this list of conditions and the following disclaimer in the 12203790Sfabient * documentation and/or other materials provided with the distribution. 13203790Sfabient * 14203790Sfabient * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15203790Sfabient * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16203790Sfabient * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17203790Sfabient * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18203790Sfabient * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19203790Sfabient * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20203790Sfabient * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21203790Sfabient * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22203790Sfabient * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23203790Sfabient * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24203790Sfabient * SUCH DAMAGE. 25203790Sfabient * 26203790Sfabient * $FreeBSD: releng/10.2/usr.sbin/pmcstat/pmcstat_top.h 203790 2010-02-11 22:51:44Z fabient $ 27203790Sfabient */ 28203790Sfabient 29203790Sfabient#ifndef _PMCSTAT_TOP_H_ 30203790Sfabient#define _PMCSTAT_TOP_H_ 31203790Sfabient 32203790Sfabient/* Return the ncurses attributes for the given value. */ 33203790Sfabient#define PMCSTAT_ATTRPERCENT(b) \ 34203790Sfabient ((b) > 10.0 ? (args.pa_topcolor ? COLOR_PAIR(1) : A_BOLD) : \ 35203790Sfabient ((b) > 5.0 ? (args.pa_topcolor ? COLOR_PAIR(2) : 0) : \ 36203790Sfabient ((b) > 2.5 ? (args.pa_topcolor ? COLOR_PAIR(3) : 0) : 0))) 37203790Sfabient 38203790Sfabient/* Print to the default ncurse windows if on a terminal or to the file. */ 39203790Sfabient#define PMCSTAT_PRINTW(...) do { \ 40203790Sfabient if (args.pa_toptty) \ 41203790Sfabient printw(__VA_ARGS__); \ 42203790Sfabient else \ 43203790Sfabient fprintf(args.pa_printfile, __VA_ARGS__);\ 44203790Sfabient} while (0) 45203790Sfabient 46203790Sfabient/* If ncurses mode active set attributes. */ 47203790Sfabient#define PMCSTAT_ATTRON(b) do { \ 48203790Sfabient if (args.pa_toptty) \ 49203790Sfabient attron(b); \ 50203790Sfabient} while (0) 51203790Sfabient 52203790Sfabient/* If ncurses mode active unset attributes. */ 53203790Sfabient#define PMCSTAT_ATTROFF(b) do { \ 54203790Sfabient if (args.pa_toptty) \ 55203790Sfabient attroff(b); \ 56203790Sfabient} while (0) 57203790Sfabient 58203790Sfabient/* Erase screen and set cursor to top left. */ 59203790Sfabient#define PMCSTAT_PRINTBEGIN() do { \ 60203790Sfabient if (args.pa_toptty) \ 61203790Sfabient clear(); \ 62203790Sfabient} while (0) 63203790Sfabient 64203790Sfabient/* Flush buffer to backend. */ 65203790Sfabient#define PMCSTAT_PRINTEND() do { \ 66203790Sfabient if (!args.pa_toptty) { \ 67203790Sfabient PMCSTAT_PRINTW("---\n"); \ 68203790Sfabient fflush(args.pa_printfile); \ 69203790Sfabient } else \ 70203790Sfabient refresh(); \ 71203790Sfabient} while (0) 72203790Sfabient 73203790Sfabient/* Function prototypes */ 74203790Sfabient 75203790Sfabient#endif /* _PMCSTAT_TOP_H_ */ 76