Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
1f3fbd8e
Commit
1f3fbd8e
authored
Nov 23, 2011
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make VSC/varnishstat sorta-work again.
parent
6cc6f23f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
297 additions
and
151 deletions
+297
-151
varnishstat.c
bin/varnishstat/varnishstat.c
+22
-22
varnishstat_curses.c
bin/varnishstat/varnishstat_curses.c
+6
-10
vsc.h
include/vapi/vsc.h
+37
-19
vsc.c
lib/libvarnishapi/vsc.c
+231
-99
vsm.c
lib/libvarnishapi/vsm.c
+1
-1
No files found.
bin/varnishstat/varnishstat.c
View file @
1f3fbd8e
...
@@ -52,7 +52,9 @@ do_xml_cb(void *priv, const struct VSC_point * const pt)
...
@@ -52,7 +52,9 @@ do_xml_cb(void *priv, const struct VSC_point * const pt)
uint64_t
val
;
uint64_t
val
;
(
void
)
priv
;
(
void
)
priv
;
assert
(
!
strcmp
(
pt
->
fmt
,
"uint64_t"
));
if
(
pt
==
NULL
)
return
(
0
);
assert
(
!
strcmp
(
pt
->
desc
->
fmt
,
"uint64_t"
));
val
=
*
(
const
volatile
uint64_t
*
)
pt
->
ptr
;
val
=
*
(
const
volatile
uint64_t
*
)
pt
->
ptr
;
printf
(
"
\t
<stat>
\n
"
);
printf
(
"
\t
<stat>
\n
"
);
...
@@ -60,10 +62,10 @@ do_xml_cb(void *priv, const struct VSC_point * const pt)
...
@@ -60,10 +62,10 @@ do_xml_cb(void *priv, const struct VSC_point * const pt)
printf
(
"
\t\t
<type>%s</type>
\n
"
,
pt
->
class
);
printf
(
"
\t\t
<type>%s</type>
\n
"
,
pt
->
class
);
if
(
strcmp
(
pt
->
ident
,
""
))
if
(
strcmp
(
pt
->
ident
,
""
))
printf
(
"
\t\t
<ident>%s</ident>
\n
"
,
pt
->
ident
);
printf
(
"
\t\t
<ident>%s</ident>
\n
"
,
pt
->
ident
);
printf
(
"
\t\t
<name>%s</name>
\n
"
,
pt
->
name
);
printf
(
"
\t\t
<name>%s</name>
\n
"
,
pt
->
desc
->
name
);
printf
(
"
\t\t
<value>%ju</value>
\n
"
,
val
);
printf
(
"
\t\t
<value>%ju</value>
\n
"
,
val
);
printf
(
"
\t\t
<flag>%c</flag>
\n
"
,
pt
->
flag
);
printf
(
"
\t\t
<flag>%c</flag>
\n
"
,
pt
->
desc
->
flag
);
printf
(
"
\t\t
<description>%s</description>
\n
"
,
pt
->
desc
);
printf
(
"
\t\t
<description>%s</description>
\n
"
,
pt
->
desc
->
sdesc
);
printf
(
"
\t
</stat>
\n
"
);
printf
(
"
\t
</stat>
\n
"
);
return
(
0
);
return
(
0
);
}
}
...
@@ -91,9 +93,11 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
...
@@ -91,9 +93,11 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
uint64_t
val
;
uint64_t
val
;
int
*
jp
;
int
*
jp
;
jp
=
priv
;
if
(
pt
==
NULL
)
return
(
0
);
assert
(
!
strcmp
(
pt
->
fmt
,
"uint64_t"
));
jp
=
priv
;
assert
(
!
strcmp
(
pt
->
desc
->
fmt
,
"uint64_t"
));
val
=
*
(
const
volatile
uint64_t
*
)
pt
->
ptr
;
val
=
*
(
const
volatile
uint64_t
*
)
pt
->
ptr
;
if
(
*
jp
)
*
jp
=
0
;
else
printf
(
",
\n
"
);
if
(
*
jp
)
*
jp
=
0
;
else
printf
(
",
\n
"
);
...
@@ -104,15 +108,15 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
...
@@ -104,15 +108,15 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
printf
(
"%s."
,
pt
->
class
);
printf
(
"%s."
,
pt
->
class
);
if
(
pt
->
ident
[
0
])
if
(
pt
->
ident
[
0
])
printf
(
"%s."
,
pt
->
ident
);
printf
(
"%s."
,
pt
->
ident
);
printf
(
"%s
\"
: {"
,
pt
->
name
);
printf
(
"%s
\"
: {"
,
pt
->
desc
->
name
);
if
(
strcmp
(
pt
->
class
,
""
))
printf
(
"
\"
type
\"
:
\"
%s
\"
, "
,
pt
->
class
);
if
(
strcmp
(
pt
->
class
,
""
))
printf
(
"
\"
type
\"
:
\"
%s
\"
, "
,
pt
->
class
);
if
(
strcmp
(
pt
->
ident
,
""
))
printf
(
"
\"
ident
\"
:
\"
%s
\"
, "
,
pt
->
ident
);
if
(
strcmp
(
pt
->
ident
,
""
))
printf
(
"
\"
ident
\"
:
\"
%s
\"
, "
,
pt
->
ident
);
printf
(
"
\"
value
\"
: %ju, "
,
val
);
printf
(
"
\"
value
\"
: %ju, "
,
val
);
printf
(
"
\"
flag
\"
:
\"
%c
\"
, "
,
pt
->
flag
);
printf
(
"
\"
flag
\"
:
\"
%c
\"
, "
,
pt
->
desc
->
flag
);
printf
(
"
\"
description
\"
:
\"
%s
\"
"
,
pt
->
desc
);
printf
(
"
\"
description
\"
:
\"
%s
\"
"
,
pt
->
desc
->
sdesc
);
printf
(
"}"
);
printf
(
"}"
);
if
(
*
jp
)
printf
(
"
\n
"
);
if
(
*
jp
)
printf
(
"
\n
"
);
...
@@ -153,22 +157,24 @@ do_once_cb(void *priv, const struct VSC_point * const pt)
...
@@ -153,22 +157,24 @@ do_once_cb(void *priv, const struct VSC_point * const pt)
uint64_t
val
;
uint64_t
val
;
int
i
;
int
i
;
if
(
pt
==
NULL
)
return
(
0
);
op
=
priv
;
op
=
priv
;
assert
(
!
strcmp
(
pt
->
fmt
,
"uint64_t"
));
assert
(
!
strcmp
(
pt
->
desc
->
fmt
,
"uint64_t"
));
val
=
*
(
const
volatile
uint64_t
*
)
pt
->
ptr
;
val
=
*
(
const
volatile
uint64_t
*
)
pt
->
ptr
;
i
=
0
;
i
=
0
;
if
(
strcmp
(
pt
->
class
,
""
))
if
(
strcmp
(
pt
->
class
,
""
))
i
+=
printf
(
"%s."
,
pt
->
class
);
i
+=
printf
(
"%s."
,
pt
->
class
);
if
(
strcmp
(
pt
->
ident
,
""
))
if
(
strcmp
(
pt
->
ident
,
""
))
i
+=
printf
(
"%s."
,
pt
->
ident
);
i
+=
printf
(
"%s."
,
pt
->
ident
);
i
+=
printf
(
"%s"
,
pt
->
name
);
i
+=
printf
(
"%s"
,
pt
->
desc
->
name
);
if
(
i
>
op
->
pad
)
if
(
i
>
op
->
pad
)
op
->
pad
=
i
+
1
;
op
->
pad
=
i
+
1
;
printf
(
"%*.*s"
,
op
->
pad
-
i
,
op
->
pad
-
i
,
""
);
printf
(
"%*.*s"
,
op
->
pad
-
i
,
op
->
pad
-
i
,
""
);
if
(
pt
->
flag
==
'a'
||
pt
->
flag
==
'c'
)
if
(
pt
->
desc
->
flag
==
'a'
||
pt
->
desc
->
flag
==
'c'
)
printf
(
"%12ju %12.2f %s
\n
"
,
val
,
val
/
op
->
up
,
pt
->
desc
);
printf
(
"%12ju %12.2f %s
\n
"
,
val
,
val
/
op
->
up
,
pt
->
desc
->
sdesc
);
else
else
printf
(
"%12ju %12s %s
\n
"
,
val
,
". "
,
pt
->
desc
);
printf
(
"%12ju %12s %s
\n
"
,
val
,
". "
,
pt
->
desc
->
sdesc
);
return
(
0
);
return
(
0
);
}
}
...
@@ -197,10 +203,10 @@ do_list_cb(void *priv, const struct VSC_point * const pt)
...
@@ -197,10 +203,10 @@ do_list_cb(void *priv, const struct VSC_point * const pt)
i
+=
fprintf
(
stderr
,
"%s."
,
pt
->
class
);
i
+=
fprintf
(
stderr
,
"%s."
,
pt
->
class
);
if
(
strcmp
(
pt
->
ident
,
""
))
if
(
strcmp
(
pt
->
ident
,
""
))
i
+=
fprintf
(
stderr
,
"%s."
,
pt
->
ident
);
i
+=
fprintf
(
stderr
,
"%s."
,
pt
->
ident
);
i
+=
fprintf
(
stderr
,
"%s"
,
pt
->
name
);
i
+=
fprintf
(
stderr
,
"%s"
,
pt
->
desc
->
name
);
if
(
i
<
30
)
if
(
i
<
30
)
fprintf
(
stderr
,
"%*s"
,
i
-
30
,
""
);
fprintf
(
stderr
,
"%*s"
,
i
-
30
,
""
);
fprintf
(
stderr
,
" %s
\n
"
,
pt
->
desc
);
fprintf
(
stderr
,
" %s
\n
"
,
pt
->
desc
->
sdesc
);
return
(
0
);
return
(
0
);
}
}
...
@@ -253,7 +259,6 @@ main(int argc, char * const *argv)
...
@@ -253,7 +259,6 @@ main(int argc, char * const *argv)
int
delay
=
1
,
once
=
0
,
xml
=
0
,
json
=
0
,
do_repeat
=
0
;
int
delay
=
1
,
once
=
0
,
xml
=
0
,
json
=
0
,
do_repeat
=
0
;
vd
=
VSM_New
();
vd
=
VSM_New
();
VSC_Setup
(
vd
);
while
((
c
=
getopt
(
argc
,
argv
,
VSC_ARGS
"1f:lVw:xjt:"
))
!=
-
1
)
{
while
((
c
=
getopt
(
argc
,
argv
,
VSC_ARGS
"1f:lVw:xjt:"
))
!=
-
1
)
{
switch
(
c
)
{
switch
(
c
)
{
...
@@ -261,8 +266,6 @@ main(int argc, char * const *argv)
...
@@ -261,8 +266,6 @@ main(int argc, char * const *argv)
once
=
1
;
once
=
1
;
break
;
break
;
case
'l'
:
case
'l'
:
if
(
VSC_Open
(
vd
,
1
))
exit
(
1
);
list_fields
(
vd
);
list_fields
(
vd
);
exit
(
0
);
exit
(
0
);
case
'V'
:
case
'V'
:
...
@@ -285,9 +288,6 @@ main(int argc, char * const *argv)
...
@@ -285,9 +288,6 @@ main(int argc, char * const *argv)
}
}
}
}
if
(
VSC_Open
(
vd
,
1
))
exit
(
1
);
VSC_C_main
=
VSC_Main
(
vd
);
VSC_C_main
=
VSC_Main
(
vd
);
AN
(
VSC_C_main
);
AN
(
VSC_C_main
);
...
...
bin/varnishstat/varnishstat_curses.c
View file @
1f3fbd8e
...
@@ -81,7 +81,9 @@ do_curses_cb(void *priv, const struct VSC_point * const sp)
...
@@ -81,7 +81,9 @@ do_curses_cb(void *priv, const struct VSC_point * const sp)
char
buf
[
128
];
char
buf
[
128
];
(
void
)
priv
;
(
void
)
priv
;
assert
(
!
strcmp
(
sp
->
fmt
,
"uint64_t"
));
if
(
sp
==
NULL
)
return
(
0
);
assert
(
!
strcmp
(
sp
->
desc
->
fmt
,
"uint64_t"
));
pt
=
calloc
(
sizeof
*
pt
,
1
);
pt
=
calloc
(
sizeof
*
pt
,
1
);
AN
(
pt
);
AN
(
pt
);
...
@@ -89,7 +91,7 @@ do_curses_cb(void *priv, const struct VSC_point * const sp)
...
@@ -89,7 +91,7 @@ do_curses_cb(void *priv, const struct VSC_point * const sp)
pt
->
ptr
=
sp
->
ptr
;
pt
->
ptr
=
sp
->
ptr
;
pt
->
ref
=
*
pt
->
ptr
;
pt
->
ref
=
*
pt
->
ptr
;
pt
->
flag
=
sp
->
flag
;
pt
->
flag
=
sp
->
desc
->
flag
;
*
buf
=
'\0'
;
*
buf
=
'\0'
;
if
(
strcmp
(
sp
->
class
,
""
))
{
if
(
strcmp
(
sp
->
class
,
""
))
{
...
@@ -100,9 +102,9 @@ do_curses_cb(void *priv, const struct VSC_point * const sp)
...
@@ -100,9 +102,9 @@ do_curses_cb(void *priv, const struct VSC_point * const sp)
strcat
(
buf
,
sp
->
ident
);
strcat
(
buf
,
sp
->
ident
);
strcat
(
buf
,
"."
);
strcat
(
buf
,
"."
);
}
}
strcat
(
buf
,
sp
->
name
);
strcat
(
buf
,
sp
->
desc
->
name
);
strcat
(
buf
,
" - "
);
strcat
(
buf
,
" - "
);
strcat
(
buf
,
sp
->
desc
);
strcat
(
buf
,
sp
->
desc
->
sdesc
);
pt
->
name
=
strdup
(
buf
);
pt
->
name
=
strdup
(
buf
);
AN
(
pt
->
name
);
AN
(
pt
->
name
);
return
(
0
);
return
(
0
);
...
@@ -144,7 +146,6 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main,
...
@@ -144,7 +146,6 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main,
int
ch
,
line
;
int
ch
,
line
;
struct
pt
*
pt
;
struct
pt
*
pt
;
double
act
,
lact
;
double
act
,
lact
;
unsigned
seq
;
(
void
)
initscr
();
(
void
)
initscr
();
AC
(
raw
());
AC
(
raw
());
...
@@ -157,7 +158,6 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main,
...
@@ -157,7 +158,6 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main,
/*
/*
* Initialization goes in outher loop
* Initialization goes in outher loop
*/
*/
seq
=
VSM_Seq
(
vd
);
prep_pts
(
vd
);
prep_pts
(
vd
);
AC
(
erase
());
AC
(
erase
());
AC
(
refresh
());
AC
(
refresh
());
...
@@ -170,15 +170,11 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main,
...
@@ -170,15 +170,11 @@ do_curses(struct VSM_data *vd, const struct VSC_C_main *VSC_C_main,
lact
=
0
;
lact
=
0
;
while
(
1
)
{
while
(
1
)
{
if
(
seq
!=
VSM_Seq
(
vd
))
break
;
/*
/*
* Break to outher loop if we need to re-read file.
* Break to outher loop if we need to re-read file.
* Only check if it looks like nothing is happening.
* Only check if it looks like nothing is happening.
*/
*/
act
=
VSC_C_main
->
cache_hit
+
VSC_C_main
->
cache_miss
+
1
;
act
=
VSC_C_main
->
cache_hit
+
VSC_C_main
->
cache_miss
+
1
;
if
(
act
==
lact
&&
VSM_ReOpen
(
vd
,
1
))
break
;
lact
=
act
;
lact
=
act
;
AZ
(
gettimeofday
(
&
tv
,
NULL
));
AZ
(
gettimeofday
(
&
tv
,
NULL
));
...
...
include/vapi/vsc.h
View file @
1f3fbd8e
...
@@ -26,6 +26,10 @@
...
@@ -26,6 +26,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* SUCH DAMAGE.
*
*
* This is the public API for the VSC access.
*
* VSC is a "subclass" of VSM.
*
*/
*/
#ifndef VAPI_VSC_H_INCLUDED
#ifndef VAPI_VSC_H_INCLUDED
...
@@ -34,17 +38,12 @@
...
@@ -34,17 +38,12 @@
#include "vapi/vsc_int.h"
#include "vapi/vsc_int.h"
struct
VSM_data
;
struct
VSM_data
;
struct
VSM_fantom
;
/*---------------------------------------------------------------------
/*---------------------------------------------------------------------
* VSC level access functions
* VSC level access functions
*/
*/
void
VSC_Setup
(
struct
VSM_data
*
vd
);
/*
* Setup vd for use with VSC functions.
* Must be called once before any other VSC function is called
*/
#define VSC_ARGS "f:n:"
#define VSC_ARGS "f:n:"
#define VSC_n_USAGE VSM_n_USAGE
#define VSC_n_USAGE VSM_n_USAGE
#define VSC_f_USAGE "[-f field_name,...]"
#define VSC_f_USAGE "[-f field_name,...]"
...
@@ -55,39 +54,58 @@ int VSC_Arg(struct VSM_data *vd, int arg, const char *opt);
...
@@ -55,39 +54,58 @@ int VSC_Arg(struct VSM_data *vd, int arg, const char *opt);
/*
/*
* Handle standard stat-presenter arguments
* Handle standard stat-presenter arguments
* Return:
* Return:
* -1 error
* -1 error
, VSM_Error() returns diagnostic string
* 0 not handled
* 0 not handled
* 1 Handled.
* 1 Handled.
*/
*/
int
VSC_Open
(
struct
VSM_data
*
vd
,
int
diag
);
struct
VSC_C_main
*
VSC_Main
(
struct
VSM_data
*
vd
);
/*
* Open shared memory for VSC processing.
* args and returns as VSM_Open()
*/
struct
VSC_C_main
*
VSC_Main
(
const
struct
VSM_data
*
vd
);
/*
/*
* return Main stats structure
* return Main stats structure
* returns NULL until child has been started.
* returns NULL until child has been started.
*/
*/
struct
VSC_desc
{
const
char
*
name
;
/* field name */
const
char
*
fmt
;
/* field format ("uint64_t") */
int
flag
;
/* 'c' = counter, 'g' = gauge */
const
char
*
sdesc
;
/* short description */
const
char
*
ldesc
;
/* long description */
};
struct
VSC_point
{
struct
VSC_point
{
const
char
*
class
;
/* stat struct type */
const
char
*
class
;
/* stat struct type */
const
char
*
ident
;
/* stat struct ident */
const
char
*
ident
;
/* stat struct ident */
const
char
*
name
;
/* field name */
const
struct
VSC_desc
*
desc
;
/* point description */
const
char
*
fmt
;
/* field format ("uint64_t") */
int
flag
;
/* 'a' = counter, 'i' = gauge */
const
char
*
desc
;
/* description */
const
volatile
void
*
ptr
;
/* field value */
const
volatile
void
*
ptr
;
/* field value */
struct
VSM_fantom
*
vf
;
};
};
typedef
int
VSC_iter_f
(
void
*
priv
,
const
struct
VSC_point
*
const
pt
);
typedef
int
VSC_iter_f
(
void
*
priv
,
const
struct
VSC_point
*
const
pt
);
int
VSC_Iter
(
const
struct
VSM_data
*
vd
,
VSC_iter_f
*
func
,
void
*
priv
);
int
VSC_Iter
(
struct
VSM_data
*
vd
,
VSC_iter_f
*
func
,
void
*
priv
);
/*
/*
* Iterate over all statistics counters, calling "func" for
* Iterate over all statistics counters, calling "func" for
* each counter not suppressed by any "-f" arguments.
* each counter not suppressed by any "-f" arguments.
*
* Func is called with pt == NULL, whenever VSM allocations
* change (child restart, allocations/deallocations)
*
* Returns:
* !=0: func returned non-zero
* -1: No VSC's available
* 0: Done
*/
*/
/**********************************************************************
* Precompiled VSC_desc's for all know VSCs.
*/
#define VSC_F(n,t,l,f,d,e)
#define VSC_DO(U,l,t) extern const struct VSC_desc VSC_desc_##l[];
#define VSC_DONE(U,l,t)
#include "tbl/vsc_all.h"
#undef VSC_F
#undef VSC_DO
#undef VSC_DONE
#endif
/* VAPI_VSC_H_INCLUDED */
#endif
/* VAPI_VSC_H_INCLUDED */
lib/libvarnishapi/vsc.c
View file @
1f3fbd8e
...
@@ -47,15 +47,22 @@
...
@@ -47,15 +47,22 @@
#include "vqueue.h"
#include "vqueue.h"
#include "vsm_api.h"
#include "vsm_api.h"
struct
vsc_pt
{
unsigned
magic
;
#define VSC_PT_MAGIC 0xa4ff159a
struct
VSC_point
point
;
VTAILQ_ENTRY
(
vsc_pt
)
list
;
};
struct
vsc_sf
{
struct
vsc_sf
{
unsigned
magic
;
unsigned
magic
;
#define VS
L
_SF_MAGIC 0x558478dd
#define VS
C
_SF_MAGIC 0x558478dd
VTAILQ_ENTRY
(
vsc_sf
)
nex
t
;
VTAILQ_ENTRY
(
vsc_sf
)
lis
t
;
int
flags
;
int
flags
;
#define VS
L
_SF_EXCL (1 << 0)
#define VS
C
_SF_EXCL (1 << 0)
#define VS
L
_SF_CL_WC (1 << 1)
#define VS
C
_SF_CL_WC (1 << 1)
#define VS
L
_SF_ID_WC (1 << 2)
#define VS
C
_SF_ID_WC (1 << 2)
#define VS
L
_SF_NM_WC (1 << 3)
#define VS
C
_SF_NM_WC (1 << 3)
char
*
class
;
char
*
class
;
char
*
ident
;
char
*
ident
;
char
*
name
;
char
*
name
;
...
@@ -65,40 +72,56 @@ struct vsc {
...
@@ -65,40 +72,56 @@ struct vsc {
unsigned
magic
;
unsigned
magic
;
#define VSC_MAGIC 0x3373554a
#define VSC_MAGIC 0x3373554a
int
sf_ini
t
;
VTAILQ_HEAD
(,
vsc_pt
)
pt_lis
t
;
VTAILQ_HEAD
(,
vsc_sf
)
sf_list
;
VTAILQ_HEAD
(,
vsc_sf
)
sf_list
;
struct
VSM_fantom
main_fantom
;
struct
VSM_fantom
iter_fantom
;
};
};
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
void
static
struct
vsc
*
VSC_S
etup
(
struct
VSM_data
*
vd
)
vsc_s
etup
(
struct
VSM_data
*
vd
)
{
{
CHECK_OBJ_NOTNULL
(
vd
,
VSM_MAGIC
);
CHECK_OBJ_NOTNULL
(
vd
,
VSM_MAGIC
);
AZ
(
vd
->
vsc
);
if
(
vd
->
vsc
==
NULL
)
{
ALLOC_OBJ
(
vd
->
vsc
,
VSC_MAGIC
);
ALLOC_OBJ
(
vd
->
vsc
,
VSC_MAGIC
);
AN
(
vd
->
vsc
);
VTAILQ_INIT
(
&
vd
->
vsc
->
sf_list
);
VTAILQ_INIT
(
&
vd
->
vsc
->
sf_list
);
VTAILQ_INIT
(
&
vd
->
vsc
->
pt_list
);
}
CHECK_OBJ_NOTNULL
(
vd
->
vsc
,
VSC_MAGIC
);
return
(
vd
->
vsc
);
}
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
void
static
void
VSC_Delete
(
struct
VSM_data
*
vd
)
vsc_delete_pts
(
struct
vsc
*
vsc
)
{
struct
vsc_pt
*
pt
;
struct
VSM_fantom
*
vf
=
NULL
;
while
(
!
VTAILQ_EMPTY
(
&
vsc
->
pt_list
))
{
pt
=
VTAILQ_FIRST
(
&
vsc
->
pt_list
);
VTAILQ_REMOVE
(
&
vsc
->
pt_list
,
pt
,
list
);
if
(
pt
->
point
.
vf
!=
vf
)
{
vf
=
pt
->
point
.
vf
;
free
(
vf
);
}
FREE_OBJ
(
pt
);
}
}
static
void
vsc_delete_sfs
(
struct
vsc
*
vsc
)
{
{
struct
vsc_sf
*
sf
;
struct
vsc_sf
*
sf
;
struct
vsc
*
vsc
;
CHECK_OBJ_NOTNULL
(
vd
,
VSM_MAGIC
);
vsc
=
vd
->
vsc
;
vd
->
vsc
=
NULL
;
CHECK_OBJ_NOTNULL
(
vsc
,
VSC_MAGIC
);
while
(
!
VTAILQ_EMPTY
(
&
vsc
->
sf_list
))
{
while
(
!
VTAILQ_EMPTY
(
&
vsc
->
sf_list
))
{
sf
=
VTAILQ_FIRST
(
&
vsc
->
sf_list
);
sf
=
VTAILQ_FIRST
(
&
vsc
->
sf_list
);
VTAILQ_REMOVE
(
&
vsc
->
sf_list
,
sf
,
nex
t
);
VTAILQ_REMOVE
(
&
vsc
->
sf_list
,
sf
,
lis
t
);
free
(
sf
->
class
);
free
(
sf
->
class
);
free
(
sf
->
ident
);
free
(
sf
->
ident
);
free
(
sf
->
name
);
free
(
sf
->
name
);
...
@@ -106,39 +129,42 @@ VSC_Delete(struct VSM_data *vd)
...
@@ -106,39 +129,42 @@ VSC_Delete(struct VSM_data *vd)
}
}
}
}
/*--------------------------------------------------------------------*/
void
VSC_Delete
(
struct
VSM_data
*
vd
)
static
int
vsc_sf_arg
(
const
struct
VSM_data
*
vd
,
const
char
*
opt
)
{
{
struct
vsc
*
vsc
;
struct
vsc
*
vsc
;
struct
vsc_sf
*
sf
;
char
**
av
,
*
q
,
*
p
;
int
i
;
CHECK_OBJ_NOTNULL
(
vd
,
VSM_MAGIC
);
CHECK_OBJ_NOTNULL
(
vd
,
VSM_MAGIC
);
vsc
=
vd
->
vsc
;
vsc
=
vd
->
vsc
;
vd
->
vsc
=
NULL
;
CHECK_OBJ_NOTNULL
(
vsc
,
VSC_MAGIC
);
CHECK_OBJ_NOTNULL
(
vsc
,
VSC_MAGIC
);
vsc_delete_sfs
(
vsc
);
vsc_delete_pts
(
vsc
);
FREE_OBJ
(
vsc
);
}
if
(
VTAILQ_EMPTY
(
&
vsc
->
sf_list
))
{
/*--------------------------------------------------------------------*/
if
(
*
opt
==
'^'
)
vsc
->
sf_init
=
1
;
static
int
}
vsc_f_arg
(
struct
VSM_data
*
vd
,
const
char
*
opt
)
{
struct
vsc
*
vsc
=
vsc_setup
(
vd
);
struct
vsc_sf
*
sf
;
char
**
av
,
*
q
,
*
p
;
int
i
;
av
=
VAV_Parse
(
opt
,
NULL
,
ARGV_COMMA
);
av
=
VAV_Parse
(
opt
,
NULL
,
ARGV_COMMA
);
AN
(
av
);
AN
(
av
);
if
(
av
[
0
]
!=
NULL
)
{
if
(
av
[
0
]
!=
NULL
)
vd
->
diag
(
vd
->
priv
,
"Parse error: %s"
,
av
[
0
]);
return
(
vsm_diag
(
vd
,
"Parse error: %s"
,
av
[
0
]));
return
(
-
1
);
}
for
(
i
=
1
;
av
[
i
]
!=
NULL
;
i
++
)
{
for
(
i
=
1
;
av
[
i
]
!=
NULL
;
i
++
)
{
ALLOC_OBJ
(
sf
,
VS
L
_SF_MAGIC
);
ALLOC_OBJ
(
sf
,
VS
C
_SF_MAGIC
);
AN
(
sf
);
AN
(
sf
);
VTAILQ_INSERT_TAIL
(
&
vsc
->
sf_list
,
sf
,
nex
t
);
VTAILQ_INSERT_TAIL
(
&
vsc
->
sf_list
,
sf
,
lis
t
);
p
=
av
[
i
];
p
=
av
[
i
];
if
(
*
p
==
'^'
)
{
if
(
*
p
==
'^'
)
{
sf
->
flags
|=
VS
L
_SF_EXCL
;
sf
->
flags
|=
VS
C
_SF_EXCL
;
p
++
;
p
++
;
}
}
...
@@ -167,21 +193,21 @@ vsc_sf_arg(const struct VSM_data *vd, const char *opt)
...
@@ -167,21 +193,21 @@ vsc_sf_arg(const struct VSM_data *vd, const char *opt)
q
=
strchr
(
sf
->
class
,
'*'
);
q
=
strchr
(
sf
->
class
,
'*'
);
if
(
q
!=
NULL
&&
q
[
1
]
==
'\0'
)
{
if
(
q
!=
NULL
&&
q
[
1
]
==
'\0'
)
{
*
q
=
'\0'
;
*
q
=
'\0'
;
sf
->
flags
|=
VS
L
_SF_CL_WC
;
sf
->
flags
|=
VS
C
_SF_CL_WC
;
}
}
}
}
if
(
sf
->
ident
!=
NULL
)
{
if
(
sf
->
ident
!=
NULL
)
{
q
=
strchr
(
sf
->
ident
,
'*'
);
q
=
strchr
(
sf
->
ident
,
'*'
);
if
(
q
!=
NULL
&&
q
[
1
]
==
'\0'
)
{
if
(
q
!=
NULL
&&
q
[
1
]
==
'\0'
)
{
*
q
=
'\0'
;
*
q
=
'\0'
;
sf
->
flags
|=
VS
L
_SF_ID_WC
;
sf
->
flags
|=
VS
C
_SF_ID_WC
;
}
}
}
}
if
(
sf
->
name
!=
NULL
)
{
if
(
sf
->
name
!=
NULL
)
{
q
=
strchr
(
sf
->
name
,
'*'
);
q
=
strchr
(
sf
->
name
,
'*'
);
if
(
q
!=
NULL
&&
q
[
1
]
==
'\0'
)
{
if
(
q
!=
NULL
&&
q
[
1
]
==
'\0'
)
{
*
q
=
'\0'
;
*
q
=
'\0'
;
sf
->
flags
|=
VS
L
_SF_NM_WC
;
sf
->
flags
|=
VS
C
_SF_NM_WC
;
}
}
}
}
}
}
...
@@ -195,10 +221,8 @@ int
...
@@ -195,10 +221,8 @@ int
VSC_Arg
(
struct
VSM_data
*
vd
,
int
arg
,
const
char
*
opt
)
VSC_Arg
(
struct
VSM_data
*
vd
,
int
arg
,
const
char
*
opt
)
{
{
CHECK_OBJ_NOTNULL
(
vd
,
VSM_MAGIC
);
AN
(
vd
->
vsc
);
switch
(
arg
)
{
switch
(
arg
)
{
case
'f'
:
return
(
vsc_
s
f_arg
(
vd
,
opt
));
case
'f'
:
return
(
vsc_f_arg
(
vd
,
opt
));
case
'n'
:
return
(
VSM_n_Arg
(
vd
,
opt
));
case
'n'
:
return
(
VSM_n_Arg
(
vd
,
opt
));
default:
default:
return
(
0
);
return
(
0
);
...
@@ -207,33 +231,19 @@ VSC_Arg(struct VSM_data *vd, int arg, const char *opt)
...
@@ -207,33 +231,19 @@ VSC_Arg(struct VSM_data *vd, int arg, const char *opt)
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
int
VSC_Open
(
struct
VSM_data
*
vd
,
int
diag
)
{
int
i
;
CHECK_OBJ_NOTNULL
(
vd
,
VSM_MAGIC
);
AN
(
vd
->
vsc
);
i
=
VSM_Open
(
vd
,
diag
);
return
(
i
);
}
/*--------------------------------------------------------------------*/
struct
VSC_C_main
*
struct
VSC_C_main
*
VSC_Main
(
const
struct
VSM_data
*
vd
)
VSC_Main
(
struct
VSM_data
*
vd
)
{
{
struct
VSM_fantom
vf
;
struct
vsc
*
vsc
=
vsc_setup
(
vd
)
;
CHECK_OBJ_NOTNULL
(
vd
,
VSM_MAGIC
);
if
(
!
vd
->
head
&&
VSM_Open
(
vd
))
CHECK_OBJ_NOTNULL
(
vd
->
vsc
,
VSC_MAGIC
);
if
(
!
VSM_Get
(
vd
,
&
vf
,
VSC_CLASS
,
""
,
""
))
return
(
NULL
);
return
(
NULL
);
return
((
void
*
)
vf
.
b
);
if
(
!
VSM_Get
(
vd
,
&
vsc
->
main_fantom
,
VSC_CLASS
,
""
,
""
))
return
(
NULL
);
return
((
void
*
)
vsc
->
main_fantom
.
b
);
}
}
#if 0
/*--------------------------------------------------------------------
/*--------------------------------------------------------------------
* -1 -> unknown stats encountered.
* -1 -> unknown stats encountered.
*/
*/
...
@@ -256,23 +266,28 @@ iter_call(const struct vsc *vsc, VSC_iter_f *func, void *priv,
...
@@ -256,23 +266,28 @@ iter_call(const struct vsc *vsc, VSC_iter_f *func, void *priv,
const struct VSC_point *const sp)
const struct VSC_point *const sp)
{
{
struct vsc_sf *sf;
struct vsc_sf *sf;
struct vsc_pt *pt;
int good;
int good;
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
if
(
VTAILQ_EMPTY
(
&
vsc
->
sf_list
))
ALLOC_OBJ(pt, VSC_PT_MAGIC);
return
(
func
(
priv
,
sp
)
);
AN(pt
);
good
=
vsc
->
sf_init
;
if (VTAILQ_EMPTY(&vsc->sf_list)) {
VTAILQ_INSERT_TAIL(&vsc->pt_list, pt, list);
return (func(priv, sp));
}
VTAILQ_FOREACH
(
sf
,
&
vsc
->
sf_list
,
next
)
{
good = 0;
if
(
iter_test
(
sf
->
class
,
sp
->
class
,
sf
->
flags
&
VSL_SF_CL_WC
))
VTAILQ_FOREACH(sf, &vsc->sf_list, list) {
if (iter_test(sf->class, sp->class, sf->flags & VSC_SF_CL_WC))
continue;
continue;
if
(
iter_test
(
sf
->
ident
,
sp
->
ident
,
sf
->
flags
&
VS
L
_SF_ID_WC
))
if (iter_test(sf->ident, sp->ident, sf->flags & VS
C
_SF_ID_WC))
continue;
continue;
if
(
iter_test
(
sf
->
name
,
sp
->
name
,
sf
->
flags
&
VSL
_SF_NM_WC
))
if (iter_test(sf->name, sp->
desc->name, sf->flags & VSC
_SF_NM_WC))
continue;
continue;
if
(
sf
->
flags
&
VS
L
_SF_EXCL
)
if (sf->flags & VS
C
_SF_EXCL)
good = 0;
good = 0;
else
else
good = 1;
good = 1;
...
@@ -283,26 +298,27 @@ iter_call(const struct vsc *vsc, VSC_iter_f *func, void *priv,
...
@@ -283,26 +298,27 @@ iter_call(const struct vsc *vsc, VSC_iter_f *func, void *priv,
}
}
#define VSC_DO(U,l,t) \
#define VSC_DO(U,l,t) \
static
int
\
static
void
\
iter_##l(const struct vsc *vsc, struct VSM_fantom *vf, \
iter_##l(const struct vsc *vsc, struct VSM_fantom *vf, \
VSC_iter_f *func, void *priv
) \
const struct VSC_desc *descs
) \
{ \
{ \
struct VSC_C_##l *st; \
struct VSC_C_##l *st; \
struct VS
C_point sp
; \
struct VS
M_fantom *vf2
; \
int i; \
int i; \
\
\
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); \
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); \
st = vf->b; \
st = vf->b; \
sp.class = t; \
sp.class = t; \
sp.ident = vf->chunk->ident;
sp.ident = vf->chunk->ident; \
sp.desc = descs++; \
vf2 = malloc(sizeof *vf2); \
AN(vf2); \
memcpy(vf2, vf, sizeof *vf2);
#define VSC_F(nn,tt,ll,ff,dd,ee) \
#define VSC_F(nn,tt,ll,ff,dd,ee) \
sp.name = #nn; \
sp.fmt = #tt; \
sp.flag = ff; \
sp.desc = dd; \
sp.ptr = &st->nn; \
sp.ptr = &st->nn; \
i = iter_call(vsc, func, priv, &sp); \
sp.vf = vf2; \
i = iter_call(vsc, &sp); \
if (i) \
if (i) \
return(i);
return(i);
...
@@ -315,19 +331,14 @@ iter_call(const struct vsc *vsc, VSC_iter_f *func, void *priv,
...
@@ -315,19 +331,14 @@ iter_call(const struct vsc *vsc, VSC_iter_f *func, void *priv,
#undef VSC_F
#undef VSC_F
#undef VSC_DONE
#undef VSC_DONE
int
static void
VSC_Iter
(
const
struct
VSM_data
*
vd
,
VSC_iter_f
*
func
,
void
*
priv
)
vsc_build_pt_list(struct VSM_data *vd
)
{
{
struct
vsc
*
vsc
;
struct vsc *vsc
= vsc_setup(vd)
;
struct VSM_fantom vf;
struct VSM_fantom vf;
int
i
;
CHECK_OBJ_NOTNULL
(
vd
,
VSM_MAGIC
);
vsc_delete_pts(vsc *vsc);
vsc
=
vd
->
vsc
;
CHECK_OBJ_NOTNULL
(
vsc
,
VSC_MAGIC
);
i
=
0
;
if
(
!
VSM_StillValid
(
vd
,
NULL
))
return
(
-
1
);
VSM_FOREACH_SAFE(&vf, vd) {
VSM_FOREACH_SAFE(&vf, vd) {
if (strcmp(vf.chunk->class, VSC_CLASS))
if (strcmp(vf.chunk->class, VSC_CLASS))
continue;
continue;
...
@@ -335,11 +346,8 @@ VSC_Iter(const struct VSM_data *vd, VSC_iter_f *func, void *priv)
...
@@ -335,11 +346,8 @@ VSC_Iter(const struct VSM_data *vd, VSC_iter_f *func, void *priv)
#define VSC_F(n,t,l,f,d,e)
#define VSC_F(n,t,l,f,d,e)
#define VSC_DONE(a,b,c)
#define VSC_DONE(a,b,c)
#define VSC_DO(U,l,t) \
#define VSC_DO(U,l,t) \
if (!strcmp(vf.chunk->type, t)) { \
if (!strcmp(vf.chunk->type, t)) \
i = iter_##l(vsc, &vf, func, priv); \
iter_##l(vsc, &vf, VSC_desc_##l);
if (!i) \
continue; \
}
#include "tbl/vsc_all.h"
#include "tbl/vsc_all.h"
#undef VSC_F
#undef VSC_F
#undef VSC_DO
#undef VSC_DO
...
@@ -349,3 +357,127 @@ VSC_Iter(const struct VSM_data *vd, VSC_iter_f *func, void *priv)
...
@@ -349,3 +357,127 @@ VSC_Iter(const struct VSM_data *vd, VSC_iter_f *func, void *priv)
}
}
return (i);
return (i);
}
}
#endif
/*--------------------------------------------------------------------
*/
static
void
vsc_add_pt
(
struct
vsc
*
vsc
,
const
char
*
class
,
const
char
*
ident
,
const
struct
VSC_desc
*
desc
,
const
volatile
void
*
ptr
,
struct
VSM_fantom
*
vf
)
{
struct
vsc_pt
*
pt
;
ALLOC_OBJ
(
pt
,
VSC_PT_MAGIC
);
AN
(
pt
);
pt
->
point
.
class
=
class
;
pt
->
point
.
ident
=
ident
;
pt
->
point
.
desc
=
desc
;
pt
->
point
.
ptr
=
ptr
;
pt
->
point
.
vf
=
vf
;
VTAILQ_INSERT_TAIL
(
&
vsc
->
pt_list
,
pt
,
list
);
}
#define VSC_DO(U,l,t) \
static void \
iter_##l(struct vsc *vsc, struct VSM_fantom *vf, \
const struct VSC_desc *descs) \
{ \
struct VSC_C_##l *st; \
struct VSM_fantom *vf2; \
const char *class = t; \
\
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); \
st = vf->b; \
vf2 = malloc(sizeof *vf2); \
AN(vf2); \
memcpy(vf2, vf, sizeof *vf2);
#define VSC_F(nn,tt,ll,ff,dd,ee) \
vsc_add_pt(vsc, class, vf->chunk->ident, descs++, \
&st->nn, vf2);
#define VSC_DONE(U,l,t) \
}
#include "tbl/vsc_all.h"
#undef VSC_DO
#undef VSC_F
#undef VSC_DONE
/*--------------------------------------------------------------------
*/
static
void
vsc_build_pt_list
(
struct
VSM_data
*
vd
)
{
struct
vsc
*
vsc
=
vsc_setup
(
vd
);
struct
VSM_fantom
vf
;
vsc_delete_pts
(
vsc
);
VSM_FOREACH_SAFE
(
&
vf
,
vd
)
{
if
(
strcmp
(
vf
.
chunk
->
class
,
VSC_CLASS
))
continue
;
/*lint -save -e525 -e539 */
#define VSC_F(n,t,l,f,d,e)
#define VSC_DONE(a,b,c)
#define VSC_DO(U,l,t) \
if (!strcmp(vf.chunk->type, t)) \
iter_##l(vsc, &vf, VSC_desc_##l);
#include "tbl/vsc_all.h"
#undef VSC_F
#undef VSC_DO
#undef VSC_DONE
/*lint -restore */
}
/* XXX: filter pt list */
}
/*--------------------------------------------------------------------
*/
int
VSC_Iter
(
struct
VSM_data
*
vd
,
VSC_iter_f
*
func
,
void
*
priv
)
{
struct
vsc
*
vsc
=
vsc_setup
(
vd
);
struct
vsc_pt
*
pt
;
int
i
;
if
(
1
!=
VSM_StillValid
(
vd
,
&
vsc
->
iter_fantom
))
{
if
(
!
VSM_Get
(
vd
,
&
vsc
->
iter_fantom
,
VSC_CLASS
,
""
,
""
))
{
VSM_Close
(
vd
);
if
(
!
vd
->
head
&&
VSM_Open
(
vd
))
return
(
-
1
);
if
(
!
VSM_Get
(
vd
,
&
vsc
->
iter_fantom
,
VSC_CLASS
,
""
,
""
))
{
return
(
-
1
);
}
}
AN
(
vd
->
head
);
func
(
priv
,
NULL
);
vsc_build_pt_list
(
vd
);
}
AN
(
vd
->
head
);
VTAILQ_FOREACH
(
pt
,
&
vsc
->
pt_list
,
list
)
{
i
=
func
(
priv
,
&
pt
->
point
);
if
(
i
)
return
(
i
);
}
return
(
0
);
}
/*--------------------------------------------------------------------
* Build the static point descriptions
*/
#define VSC_F(n,t,l,f,d,e) {#n,#t,f,d,e},
#define VSC_DO(U,l,t) const struct VSC_desc VSC_desc_##l[] = {
#define VSC_DONE(U,l,t) };
#include "tbl/vsc_all.h"
#undef VSC_F
#undef VSC_DO
#undef VSC_DONE
lib/libvarnishapi/vsm.c
View file @
1f3fbd8e
...
@@ -113,7 +113,7 @@ VSM_n_Arg(struct VSM_data *vd, const char *opt)
...
@@ -113,7 +113,7 @@ VSM_n_Arg(struct VSM_data *vd, const char *opt)
{
{
CHECK_OBJ_NOTNULL
(
vd
,
VSM_MAGIC
);
CHECK_OBJ_NOTNULL
(
vd
,
VSM_MAGIC
);
AN
(
vd
->
n_
opt
);
AN
(
opt
);
REPLACE
(
vd
->
n_opt
,
opt
);
REPLACE
(
vd
->
n_opt
,
opt
);
if
(
VIN_N_Arg
(
vd
->
n_opt
,
NULL
,
NULL
,
&
vd
->
fname
))
if
(
VIN_N_Arg
(
vd
->
n_opt
,
NULL
,
NULL
,
&
vd
->
fname
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment