Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
XDG Integration
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
JennaHuntsman
XDG Integration
Commits
704aeb09
Commit
704aeb09
authored
3 years ago
by
Brad Payne (Vir Linden)
Browse files
Options
Downloads
Patches
Plain Diff
SL-15031 - option to remove unreferenced settings
parent
9013a04e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/metrics/viewerstats.py
+54
-1
54 additions, 1 deletion
scripts/metrics/viewerstats.py
with
54 additions
and
1 deletion
scripts/metrics/viewerstats.py
+
54
−
1
View file @
704aeb09
...
@@ -32,8 +32,11 @@
...
@@ -32,8 +32,11 @@
import
json
import
json
from
collections
import
Counter
,
defaultdict
from
collections
import
Counter
,
defaultdict
from
llbase
import
llsd
from
llbase
import
llsd
import
io
import
re
def
show_stats_by_key
(
recs
,
indices
,
settings_sd
=
None
):
def
show_stats_by_key
(
recs
,
indices
,
settings_sd
=
None
):
result
=
()
cnt
=
Counter
()
cnt
=
Counter
()
per_key_cnt
=
defaultdict
(
Counter
)
per_key_cnt
=
defaultdict
(
Counter
)
for
r
in
recs
:
for
r
in
recs
:
...
@@ -89,6 +92,9 @@ def show_stats_by_key(recs,indices,settings_sd = None):
...
@@ -89,6 +92,9 @@ def show_stats_by_key(recs,indices,settings_sd = None):
print
"
======================
"
print
"
======================
"
print
"
\n
"
.
join
(
sorted
(
unrec_keys
))
print
"
\n
"
.
join
(
sorted
(
unrec_keys
))
result
=
(
settings_sd
.
keys
(),
unused_keys_str
,
unused_keys_non_str
,
unrec_keys
)
return
result
def
parse_settings_xml
(
fname
):
def
parse_settings_xml
(
fname
):
# assume we're in scripts/metrics
# assume we're in scripts/metrics
fname
=
"
../../indra/newview/app_settings/
"
+
fname
fname
=
"
../../indra/newview/app_settings/
"
+
fname
...
@@ -96,11 +102,40 @@ def parse_settings_xml(fname):
...
@@ -96,11 +102,40 @@ def parse_settings_xml(fname):
contents
=
f
.
read
()
contents
=
f
.
read
()
return
llsd
.
parse_xml
(
contents
)
return
llsd
.
parse_xml
(
contents
)
def
read_settings_xml
(
fname
):
# assume we're in scripts/metrics
fname
=
"
../../indra/newview/app_settings/
"
+
fname
contents
=
None
with
open
(
fname
,
"
r
"
)
as
f
:
contents
=
f
.
read
()
return
contents
def
write_settings_xml
(
fname
,
contents
):
# assume we're in scripts/metrics
fname
=
"
../../indra/newview/app_settings/
"
+
fname
with
open
(
fname
,
"
w
"
)
as
f
:
f
.
write
(
llsd
.
format_pretty_xml
(
contents
))
f
.
close
()
def
write_raw_settings_xml
(
fname
,
string
):
# assume we're in scripts/metrics
fname
=
"
../../indra/newview/app_settings/
"
+
fname
with
io
.
open
(
fname
,
"
w
"
,
newline
=
'
\n
'
)
as
f
:
f
.
write
(
string
.
decode
(
'
latin1
'
))
f
.
close
()
def
remove_settings
(
string
,
to_remove
):
for
r
in
to_remove
:
subs_str
=
r
"
<key>
"
+
r
+
r
"
<.*?</map>
"
string
=
re
.
sub
(
subs_str
,
""
,
string
,
flags
=
re
.
S
|
re
.
DOTALL
)
return
string
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
(
description
=
"
process tab-separated table containing viewerstats logs
"
)
parser
=
argparse
.
ArgumentParser
(
description
=
"
process tab-separated table containing viewerstats logs
"
)
parser
.
add_argument
(
"
--verbose
"
,
action
=
"
store_true
"
,
help
=
"
verbose flag
"
)
parser
.
add_argument
(
"
--verbose
"
,
action
=
"
store_true
"
,
help
=
"
verbose flag
"
)
parser
.
add_argument
(
"
--preferences
"
,
action
=
"
store_true
"
,
help
=
"
analyze preference info
"
)
parser
.
add_argument
(
"
--preferences
"
,
action
=
"
store_true
"
,
help
=
"
analyze preference info
"
)
parser
.
add_argument
(
"
--remove_unused
"
,
action
=
"
store_true
"
,
help
=
"
remove unused preferences
"
)
parser
.
add_argument
(
"
--column
"
,
help
=
"
name of column containing viewerstats info
"
)
parser
.
add_argument
(
"
--column
"
,
help
=
"
name of column containing viewerstats info
"
)
parser
.
add_argument
(
"
infiles
"
,
nargs
=
"
+
"
,
help
=
"
name of .tsv files to process
"
)
parser
.
add_argument
(
"
infiles
"
,
nargs
=
"
+
"
,
help
=
"
name of .tsv files to process
"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
...
@@ -121,12 +156,30 @@ def parse_settings_xml(fname):
...
@@ -121,12 +156,30 @@ def parse_settings_xml(fname):
settings_sd
=
parse_settings_xml
(
"
settings.xml
"
)
settings_sd
=
parse_settings_xml
(
"
settings.xml
"
)
#for skey,svals in settings_sd.items():
#for skey,svals in settings_sd.items():
# print skey, "=>", svals
# print skey, "=>", svals
show_stats_by_key
(
recs
,[
"
preferences
"
,
"
settings
"
],
settings_sd
)
(
all_str
,
_
,
_
,
_
)
=
show_stats_by_key
(
recs
,[
"
preferences
"
,
"
settings
"
],
settings_sd
)
print
print
print
"
\n
SETTINGS_PER_ACCOUNT.XML
"
print
"
\n
SETTINGS_PER_ACCOUNT.XML
"
settings_pa_sd
=
parse_settings_xml
(
"
settings_per_account.xml
"
)
settings_pa_sd
=
parse_settings_xml
(
"
settings_per_account.xml
"
)
show_stats_by_key
(
recs
,[
"
preferences
"
,
"
settings_per_account
"
],
settings_pa_sd
)
show_stats_by_key
(
recs
,[
"
preferences
"
,
"
settings_per_account
"
],
settings_pa_sd
)
if
args
.
remove_unused
:
# quotestrings created by
# % find . -name '*.cpp' -o -name '*.hpp' -o -name '*.h' -o -name '*cmd_line.xml' | xargs grep -ohP '[\">][a-zA-Z0-9]*[\"<]' | sort | uniq > ../scripts/metrics/quotestrings.out
with
open
(
"
quotestrings.out
"
,
"
r
"
)
as
f
:
used_strings
=
f
.
readlines
()
used_strings
=
[
u
[
1
:
-
2
]
for
u
in
used_strings
]
#print "\n".join(used_strings)
unref_strings
=
list
(
set
(
all_str
)
-
set
(
used_strings
))
print
"
\n
UNREF_IN_CODE
"
+
str
(
len
(
unref_strings
))
+
"
\n
"
print
"
\n
"
.
join
(
unref_strings
)
settings_str
=
read_settings_xml
(
"
settings.xml
"
)
# Do this via direct string munging to generate minimal changeset
settings_edited
=
remove_settings
(
settings_str
,
unref_strings
)
write_raw_settings_xml
(
"
settings.xml
"
,
settings_edited
)
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