Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
a66bc85c
Commit
a66bc85c
authored
5 years ago
by
Michael Davis
Browse files
Options
Downloads
Patches
Plain Diff
[cta-admin] Scales data size in text output to K,M,G,T,P,E
parent
85920389
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmdline/CtaAdminTextFormatter.cpp
+24
-10
24 additions, 10 deletions
cmdline/CtaAdminTextFormatter.cpp
cmdline/CtaAdminTextFormatter.hpp
+8
-5
8 additions, 5 deletions
cmdline/CtaAdminTextFormatter.hpp
with
32 additions
and
15 deletions
cmdline/CtaAdminTextFormatter.cpp
+
24
−
10
View file @
a66bc85c
...
...
@@ -37,6 +37,26 @@ std::string timeToString(const time_t &time)
}
std
::
string
TextFormatter
::
getDataSize
(
uint64_t
value
)
{
const
std
::
vector
<
char
>
suffix
=
{
'E'
,
'P'
,
'T'
,
'G'
,
'M'
,
'K'
};
// Simple case, values less than 1000 bytes don't take a suffix
if
(
value
<
1000
)
return
std
::
to_string
(
value
);
// Find the correct scaling, starting at 1 EB and working down. I'm assuming we won't have
// zettabytes or yottabytes of data in a tapepool anytime soon.
uint64_t
divisor
;
int
unit
;
for
(
unit
=
0
,
divisor
=
1'000'000'000'000'000'000
;
value
<
divisor
;
divisor
/=
1000
,
++
unit
)
;
// Convert to format like "3.1G"
std
::
stringstream
ss
;
double
val_d
=
static_cast
<
double
>
(
value
)
/
static_cast
<
double
>
(
divisor
);
ss
<<
std
::
fixed
<<
std
::
setprecision
(
1
)
<<
val_d
<<
suffix
[
unit
];
return
ss
.
str
();
}
void
TextFormatter
::
flush
()
{
if
(
m_outputBuffer
.
empty
())
return
;
...
...
@@ -176,11 +196,8 @@ void TextFormatter::print(const cta::admin::FailedRequestLsItem &frls_item) {
frls_item
.
af
().
df
().
path
()
);
for
(
auto
&
errLogMsg
:
frls_item
.
failurelogs
())
{
push_back
(
""
,
""
,
""
,
""
,
""
,
errLogMsg
);
}
// Note: failure log messages are available in frls_item.failurelogs(). These are not currently
// displayed in the text output, only in JSON.
}
void
TextFormatter
::
printFrLsSummaryHeader
()
{
...
...
@@ -427,9 +444,6 @@ void TextFormatter::printTapePoolLsHeader() {
void
TextFormatter
::
print
(
const
cta
::
admin
::
TapePoolLsItem
&
tpls_item
)
{
auto
capacity_str
=
std
::
to_string
(
tpls_item
.
capacity_bytes
()
/
1000000000
)
+
"G"
;
auto
data_str
=
std
::
to_string
(
tpls_item
.
data_bytes
()
/
1000000000
)
+
"G"
;
uint64_t
avail
=
tpls_item
.
capacity_bytes
()
>
tpls_item
.
data_bytes
()
?
tpls_item
.
capacity_bytes
()
-
tpls_item
.
data_bytes
()
:
0
;
auto
avail_str
=
std
::
to_string
(
avail
/
1000000000
)
+
"G"
;
...
...
@@ -445,8 +459,8 @@ void TextFormatter::print(const cta::admin::TapePoolLsItem &tpls_item)
tpls_item
.
num_tapes
(),
tpls_item
.
num_partial_tapes
(),
tpls_item
.
num_physical_files
(),
capacity_
str
,
data_str
,
getDataSize
(
tpls_item
.
capacity_
bytes
())
,
getDataSize
(
tpls_item
.
data_bytes
())
,
avail_str
,
use_percent_ss
.
str
(),
tpls_item
.
encrypt
(),
...
...
This diff is collapsed.
Click to expand it.
cmdline/CtaAdminTextFormatter.hpp
+
8
−
5
View file @
a66bc85c
...
...
@@ -81,23 +81,23 @@ private:
//! Recursive variadic method to build a log string from an arbitrary number of items of arbitrary type
template
<
typename
T
,
typename
...
Args
>
void
buildVector
(
std
::
vector
<
std
::
string
>
&
line
,
const
T
&
item
,
Args
...
args
)
{
static
void
buildVector
(
std
::
vector
<
std
::
string
>
&
line
,
const
T
&
item
,
Args
...
args
)
{
buildVector
(
line
,
item
);
buildVector
(
line
,
args
...);
}
//! Base case method to add one item to the log
void
buildVector
(
std
::
vector
<
std
::
string
>
&
line
,
const
std
::
string
&
item
)
{
static
void
buildVector
(
std
::
vector
<
std
::
string
>
&
line
,
const
std
::
string
&
item
)
{
line
.
push_back
(
item
);
}
//! Base case method to add one item to the log, overloaded for char*
void
buildVector
(
std
::
vector
<
std
::
string
>
&
line
,
const
char
*
item
)
{
static
void
buildVector
(
std
::
vector
<
std
::
string
>
&
line
,
const
char
*
item
)
{
line
.
push_back
(
std
::
string
(
item
));
}
//! Base case method to add one item to the log, overloaded for bool
void
buildVector
(
std
::
vector
<
std
::
string
>
&
line
,
bool
item
)
{
static
void
buildVector
(
std
::
vector
<
std
::
string
>
&
line
,
bool
item
)
{
line
.
push_back
(
item
?
"true"
:
"false"
);
}
...
...
@@ -106,10 +106,13 @@ private:
* (works for all integer and floating-point types)
*/
template
<
typename
T
>
void
buildVector
(
std
::
vector
<
std
::
string
>
&
line
,
const
T
&
item
)
{
static
void
buildVector
(
std
::
vector
<
std
::
string
>
&
line
,
const
T
&
item
)
{
line
.
push_back
(
std
::
to_string
(
item
));
}
//! Convert data size in bytes to abbreviated string with appropriate size suffix (K/M/G/T/P/E)
static
std
::
string
getDataSize
(
uint64_t
value
);
//! Flush buffer to stdout
void
flush
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment