Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Switch - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
85
Issues
85
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
White Rabbit Switch - Software
Commits
588a361f
Commit
588a361f
authored
Feb 09, 2016
by
Adam Wujek
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
userspace/tools: change interface names in pstats
Signed-off-by:
Adam Wujek
<
adam.wujek@cern.ch
>
parent
feae636c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
46 deletions
+62
-46
wrs_pstats.c
userspace/tools/wrs_pstats.c
+62
-46
No files found.
userspace/tools/wrs_pstats.c
View file @
588a361f
...
...
@@ -15,7 +15,7 @@
#include <libwr/switch_hw.h>
#include <libwr/hal_client.h>
static
void
parse_sysfs
(
int
init
);
static
void
parse_sysfs
(
void
);
#define NPORTS 18
#define CNT_PP 39
...
...
@@ -25,7 +25,13 @@ struct cnt_word {
uint64_t
init
;
};
struct
cnt_word
cnt_pp
[
NPORTS
][
CNT_PP
];
#define IF_SIZE 8
struct
p_cnt
{
char
if_name
[
IF_SIZE
];
struct
cnt_word
counters
[
CNT_PP
];
};
struct
p_cnt
cnt_pp
[
NPORTS
];
int
use_ports
;
char
info
[][
20
]
=
{{
"Tu-run|"
},
// 0
...
...
@@ -72,57 +78,66 @@ char info[][20] = {{"Tu-run|"}, // 0
int
pstats_init
(
int
init
)
{
int
i
,
j
;
FILE
*
file
;
uint32_t
p_index
,
cntr
;
uint32_t
tmp1
;
uint32_t
tmp2
;
uint64_t
val
;
char
filename
[
30
];
printf
(
"module initialized
\n
"
);
for
(
i
=
0
;
i
<
use_ports
;
++
i
)
for
(
j
=
0
;
j
<
CNT_PP
;
++
j
)
{
cnt_pp
[
i
][
j
].
init
=
0
;
cnt_pp
[
i
][
j
].
cnt
=
0
;
cnt_pp
[
i
]
.
counters
[
j
].
init
=
0
;
cnt_pp
[
i
]
.
counters
[
j
].
cnt
=
0
;
}
parse_sysfs
(
init
);
return
0
;
}
static
void
parse_sysfs
(
int
init
)
{
FILE
*
file
;
uint32_t
port
,
cntr
;
uint32_t
tmp1
;
uint32_t
tmp2
;
uint64_t
val
;
char
filename
[
30
];
for
(
p_index
=
0
;
p_index
<
use_ports
;
++
p_index
)
{
/* wrport is numbered from 1 to 18 */
snprintf
(
cnt_pp
[
p_index
].
if_name
,
IF_SIZE
,
"wri%u"
,
p_index
+
1
);
if
(
init
==
1
)
{
for
(
port
=
0
;
port
<
use_ports
;
++
port
)
{
if
(
init
==
1
)
{
sprintf
(
filename
,
"/proc/sys/pstats/wrport%u"
,
p
ort
+
1
);
p
_index
+
1
);
file
=
fopen
(
filename
,
"r"
);
for
(
cntr
=
0
;
cntr
<
CNT_PP
;
++
cntr
)
{
for
(
cntr
=
0
;
cntr
<
CNT_PP
;
++
cntr
)
{
fscanf
(
file
,
"%"
SCNu32
,
&
tmp1
);
fscanf
(
file
,
"%"
SCNu32
,
&
tmp2
);
val
=
(((
uint64_t
)
tmp2
)
<<
32
)
|
tmp1
;
cnt_pp
[
p
ort
]
[
cntr
].
init
=
val
;
cnt_pp
[
p
_index
].
counters
[
cntr
].
init
=
val
;
}
fclose
(
file
);
}
}
else
{
for
(
port
=
0
;
port
<
use_ports
;
++
port
)
{
parse_sysfs
();
return
0
;
}
sprintf
(
filename
,
"/proc/sys/pstats/wrport%u"
,
port
+
1
);
file
=
fopen
(
filename
,
"r"
);
for
(
cntr
=
0
;
cntr
<
CNT_PP
;
++
cntr
)
{
fscanf
(
file
,
"%"
SCNu32
,
&
tmp1
);
fscanf
(
file
,
"%"
SCNu32
,
&
tmp2
);
val
=
(((
uint64_t
)
tmp2
)
<<
32
)
|
tmp1
;
cnt_pp
[
port
][
cntr
].
cnt
=
val
-
cnt_pp
[
port
][
cntr
].
init
;
}
fclose
(
file
);
static
void
parse_sysfs
(
void
)
{
FILE
*
file
;
uint32_t
p_index
,
cntr
;
uint32_t
tmp1
;
uint32_t
tmp2
;
uint64_t
val
;
char
filename
[
30
];
for
(
p_index
=
0
;
p_index
<
use_ports
;
++
p_index
)
{
/* wrport is numbered from 1 to 18 */
sprintf
(
filename
,
"/proc/sys/pstats/wrport%u"
,
p_index
+
1
);
file
=
fopen
(
filename
,
"r"
);
for
(
cntr
=
0
;
cntr
<
CNT_PP
;
++
cntr
)
{
fscanf
(
file
,
"%"
SCNu32
,
&
tmp1
);
fscanf
(
file
,
"%"
SCNu32
,
&
tmp2
);
val
=
(((
uint64_t
)
tmp2
)
<<
32
)
|
tmp1
;
cnt_pp
[
p_index
].
counters
[
cntr
].
cnt
=
val
-
cnt_pp
[
p_index
].
counters
[
cntr
].
init
;
}
fclose
(
file
);
}
}
...
...
@@ -130,8 +145,8 @@ static void parse_sysfs(int init)
void
print_first_n_cnts
(
int
n_cnts
)
{
int
cnt
=
0
;
int
p
ort
=
0
;
printf
(
"P |"
);
int
p
_index
=
0
;
printf
(
"P
|"
);
for
(
cnt
=
0
;
cnt
<
n_cnts
;
++
cnt
)
printf
(
"%2d:%s"
,
cnt
,
info
[
cnt
]);
printf
(
"
\n
"
);
...
...
@@ -140,11 +155,11 @@ void print_first_n_cnts(int n_cnts)
printf
(
"----------"
);
printf
(
"
\n
"
);
for
(
port
=
0
;
port
<
use_ports
;
++
port
)
for
(
p_index
=
0
;
p_index
<
use_ports
;
++
p_index
)
{
printf
(
"%
2u|"
,
port
);
for
(
cnt
=
0
;
cnt
<
n_cnts
;
++
cnt
)
printf
(
"%9llu|"
,
cnt_pp
[
p
ort
]
[
cnt
].
cnt
);
printf
(
"%
-5s|"
,
cnt_pp
[
p_index
].
if_name
);
for
(
cnt
=
0
;
cnt
<
n_cnts
;
++
cnt
)
printf
(
"%9llu|"
,
cnt_pp
[
p
_index
].
counters
[
cnt
].
cnt
);
printf
(
"
\n
"
);
}
}
...
...
@@ -152,9 +167,9 @@ void print_first_n_cnts(int n_cnts)
void
print_chosen_cnts
(
int
cnts_list
[],
int
n_cnts
)
{
int
cnt
=
0
;
int
p
ort
=
0
;
int
p
_index
=
0
;
printf
(
"P |"
);
printf
(
"P
|"
);
for
(
cnt
=
0
;
cnt
<
n_cnts
;
++
cnt
)
printf
(
"%2d:%s"
,
cnts_list
[
cnt
],
info
[
cnts_list
[
cnt
]]);
printf
(
"
\n
"
);
...
...
@@ -162,11 +177,12 @@ void print_chosen_cnts( int cnts_list[], int n_cnts)
for
(
cnt
=
0
;
cnt
<
n_cnts
;
++
cnt
)
printf
(
"----------"
);
printf
(
"
\n
"
);
for
(
port
=
0
;
port
<
use_ports
;
++
port
)
for
(
p_index
=
0
;
p_index
<
use_ports
;
++
p_index
)
{
printf
(
"%2u|"
,
port
);
for
(
cnt
=
0
;
cnt
<
n_cnts
;
++
cnt
)
printf
(
"%9llu|"
,
cnt_pp
[
port
][
cnts_list
[
cnt
]].
cnt
);
printf
(
"%-5s|"
,
cnt_pp
[
p_index
].
if_name
);
for
(
cnt
=
0
;
cnt
<
n_cnts
;
++
cnt
)
printf
(
"%9llu|"
,
cnt_pp
[
p_index
].
counters
[
cnts_list
[
cnt
]].
cnt
);
printf
(
"
\n
"
);
}
}
...
...
@@ -226,7 +242,7 @@ int main(int argc, char **argv)
while
(
1
)
{
printf
(
"
\033
[2J
\033
[1;1H"
);
parse_sysfs
(
0
);
parse_sysfs
();
switch
(
op
)
{
case
'p'
:
print_chosen_cnts
(
prio_cnts
,
8
);
...
...
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