11558Srgrimes/*-
21558Srgrimes * Copyright (c) 2017 Colin Percival
31558Srgrimes * All rights reserved.
41558Srgrimes *
51558Srgrimes * Redistribution and use in source and binary forms, with or without
61558Srgrimes * modification, are permitted provided that the following conditions
71558Srgrimes * are met:
81558Srgrimes *
91558Srgrimes * 1. Redistributions of source code must retain the above copyright
101558Srgrimes *    notice, this list of conditions and the following disclaimer.
111558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
121558Srgrimes *    notice, this list of conditions and the following disclaimer in the
131558Srgrimes *    documentation and/or other materials provided with the distribution.
141558Srgrimes *
151558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161558Srgrimes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171558Srgrimes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
181558Srgrimes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
191558Srgrimes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201558Srgrimes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
211558Srgrimes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
221558Srgrimes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231558Srgrimes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
241558Srgrimes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
251558Srgrimes */
261558Srgrimes
271558Srgrimes#ifndef _TSLOG_H_
281558Srgrimes#define	_TSLOG_H_
2950476Speter
301558Srgrimes#ifdef _KERNEL
311558Srgrimes#ifdef TSLOG
321558Srgrimes#include <sys/_types.h>
3379530Sru#include <sys/pcpu.h>
341558Srgrimes#endif
351558Srgrimes
361558Srgrimes#define TS_ENTER	0
371558Srgrimes#define TS_EXIT		1
3868960Sru#define TS_THREAD	2
391558Srgrimes#define TS_EVENT	3
401558Srgrimes
4199501Scharnier#define TSENTER() TSRAW(curthread, TS_ENTER, __func__, NULL)
4299501Scharnier#define TSENTER2(x) TSRAW(curthread, TS_ENTER, __func__, x)
43131488Sru#define TSEXIT() TSRAW(curthread, TS_EXIT, __func__, NULL)
44131488Sru#define TSEXIT2(x) TSRAW(curthread, TS_EXIT, __func__, x)
451558Srgrimes#define TSTHREAD(td, x) TSRAW(td, TS_THREAD, x, NULL)
4657662Snik#define TSEVENT(x) TSRAW(curthread, TS_EVENT, x, NULL)
471558Srgrimes#define TSEVENT2(x, y) TSRAW(curthread, TS_EVENT, x, y)
481558Srgrimes#define TSLINE() TSEVENT2(__FILE__, __XSTRING(__LINE__))
491558Srgrimes#define TSWAIT(x) TSEVENT2("WAIT", x);
501558Srgrimes#define TSUNWAIT(x) TSEVENT2("UNWAIT", x);
511558Srgrimes#define TSHOLD(x) TSEVENT2("HOLD", x);
521558Srgrimes#define TSRELEASE(x) TSEVENT2("RELEASE", x);
5336626Scharnier#define TSFORK(p, pp) TSRAW_USER(p, pp, NULL, NULL)
54141846Sru#define TSEXEC(p, name) TSRAW_USER(p, (pid_t)(-1), name, NULL)
55102231Strhodes#define TSNAMEI(p, name) TSRAW_USER(p, (pid_t)(-1), NULL, name)
561558Srgrimes#define TSPROCEXIT(p) TSRAW_USER(p, (pid_t)(-1), NULL, NULL)
571558Srgrimes
581558Srgrimes#ifdef TSLOG
591558Srgrimes#define TSRAW(a, b, c, d) tslog(a, b, c, d)
601558Srgrimesvoid tslog(void *, int, const char *, const char *);
611558Srgrimes#define TSRAW_USER(a, b, c, d) tslog_user(a, b, c, d)
621558Srgrimesvoid tslog_user(pid_t, pid_t, const char *, const char *);
631558Srgrimes#else
6479754Sdd#define TSRAW(a, b, c, d)		/* Timestamp logging disabled */
6536626Scharnier#define TSRAW_USER(a, b, c, d)		/* Timestamp logging disabled */
661558Srgrimes#endif
671558Srgrimes
6899501Scharnier#endif /* _KERNEL */
6999501Scharnier#endif /* _TSLOG_H_ */
70102231Strhodes