2
* Copyright (c) 2008, XenSource Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
* * Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* * Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
* * Neither the name of XenSource Inc. nor the names of its contributors
13
* may be used to endorse or promote products derived from this software
14
* without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
20
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
#ifndef __TAP_PROFILE_H__
30
#define __TAP_PROFILE_H__
52
struct profile_times {
54
uint64_t in, out_sum, cnt;
61
unsigned long long seq;
62
struct profile_times *pt;
68
tp_open(struct profile_info *prof, char *tap_name, char *log_name, int size)
70
memset(prof, 0, sizeof(struct profile_info));
72
prof->log = fopen(log_name, "w");
75
prof->name = strdup(tap_name);
76
prof->pt = malloc(sizeof(struct profile_times) * prof->size);
78
memset(prof->pt, 0, sizeof(struct profile_times) * prof->size);
82
tp_close(struct profile_info *prof)
85
struct profile_times *pt;
87
for (i = 0; i < prof->size; i++) {
90
syslog(LOG_DEBUG, "%s: %s: cnt: %llu, avg time: %llu\n",
91
prof->name, pt->fn_name, pt->cnt,
92
((pt->cnt) ? (pt->out_sum / pt->cnt) : 0));
107
tp_get_id(struct profile_info *prof)
113
tp_fn_id(struct profile_info *prof, const char *name)
116
struct profile_times *pt;
118
for (i = 0; i < prof->size; i++) {
122
if (!strcmp(pt->fn_name, name))
126
return prof->size - 1;
130
__tp_in(struct profile_info *prof, const char *func)
133
int idx = tp_fn_id(prof, func);
134
struct profile_times *pt = &prof->pt[idx];
137
pt->fn_name = strdup(func);
139
asm volatile(".byte 0x0f, 0x31" : "=A" (_time));
143
#define tp_in(prof) __tp_in(prof, __func__)
146
__tp_out(struct profile_info *prof, const char *func)
149
int idx = tp_fn_id(prof, func);
150
struct profile_times *pt = &prof->pt[idx];
152
if (!pt->fn_name || !pt->in)
155
asm volatile(".byte 0x0f, 0x31" : "=A" (_time));
157
pt->out_sum += (_time - pt->in);
161
#define tp_out(prof) __tp_out(prof, __func__)
164
__tp_log(struct profile_info *prof, u64 id, const char *func, int direction)
167
asm volatile(".byte 0x0f, 0x31" : "=A" (_time));
169
if (direction == TAPPROF_IN)
172
__tp_out(prof, func);
176
fprintf(prof->log, "%s: %s: %llu, %lld\n", func,
177
((direction == TAPPROF_IN) ? "in" : "out"), id, _time);
181
#define tp_log(prof, id, direction) __tp_log(prof, id, __func__, direction)
184
#define tp_open(prof, tname, lname, size) ((void)0)
185
#define tp_close(prof) ((void)0)
186
#define tp_in(prof) ((void)0)
187
#define tp_out(prof) ((void)0)
188
#define tp_log(prof, sec, direction) ((void)0)