Skip to content

Commit 5deb90a

Browse files
committed
make the tour profiling information a bit more useful
1 parent b98fa7e commit 5deb90a

20 files changed

+447
-87
lines changed

Sources/HTTP/ServerResource.Content.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ extension ServerResource
1313
}
1414
extension ServerResource.Content
1515
{
16+
@inlinable public
17+
var size:Int
18+
{
19+
switch self
20+
{
21+
case .binary(let buffer): return buffer.count
22+
case .buffer(let buffer): return buffer.readableBytes
23+
case .string(let string): return string.utf8.count
24+
case .length: return 0
25+
}
26+
}
1627
@inlinable public
1728
var length:Int
1829
{

Sources/UnidocPages/UI/StatsBreakdown.Stat.swift renamed to Sources/UnidocPages/Stats/Unidoc.Stat.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import HTML
2+
import Unidoc
23

3-
extension StatsBreakdown
4+
extension Unidoc
45
{
56
struct Stat:Sendable
67
{
@@ -18,7 +19,7 @@ extension StatsBreakdown
1819
}
1920
}
2021
}
21-
extension StatsBreakdown.Stat
22+
extension Unidoc.Stat
2223
{
2324
private static
2425
func format(share:Double) -> String
@@ -30,7 +31,7 @@ extension StatsBreakdown.Stat
3031
return "\(percent).\(f)"
3132
}
3233
}
33-
extension StatsBreakdown.Stat:PieSector
34+
extension Unidoc.Stat:PieSector
3435
{
3536
func legend(_ html:inout HTML.ContentEncoder, share:Double)
3637
{

Sources/UnidocPages/UI/StatsBreakdown.Condensed.swift renamed to Sources/UnidocPages/Stats/Unidoc.StatsBreakdown.Condensed.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import HTML
2+
import Unidoc
23

3-
extension StatsBreakdown
4+
extension Unidoc.StatsBreakdown
45
{
56
struct Condensed
67
{
78
private
8-
let unweighted:Pie<Stat>
9+
let unweighted:Pie<Unidoc.Stat>
910
private
10-
let weighted:Pie<Stat>
11+
let weighted:Pie<Unidoc.Stat>
1112

12-
init(unweighted:Pie<Stat>, weighted:Pie<Stat>)
13+
init(unweighted:Pie<Unidoc.Stat>, weighted:Pie<Unidoc.Stat>)
1314
{
1415
self.unweighted = unweighted
1516
self.weighted = weighted
1617
}
1718
}
1819
}
19-
extension StatsBreakdown.Condensed:HyperTextOutputStreamable
20+
extension Unidoc.StatsBreakdown.Condensed:HyperTextOutputStreamable
2021
{
2122
static
2223
func += (html:inout HTML.ContentEncoder, self:Self)

Sources/UnidocPages/UI/StatsBreakdown.swift renamed to Sources/UnidocPages/Stats/Unidoc.StatsBreakdown.swift

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import HTML
2+
import Unidoc
23
import UnidocRecords
34

4-
struct StatsBreakdown
5+
extension Unidoc
56
{
6-
private
7-
var unweighted:Pie<Stat>
8-
private
9-
var weighted:Pie<Stat>
10-
11-
private
12-
init(unweighted:Pie<Stat> = [], weighted:Pie<Stat> = [])
7+
struct StatsBreakdown
138
{
14-
self.unweighted = unweighted
15-
self.weighted = weighted
9+
private
10+
var unweighted:Pie<Stat>
11+
private
12+
var weighted:Pie<Stat>
13+
14+
private
15+
init(unweighted:Pie<Stat> = [], weighted:Pie<Stat> = [])
16+
{
17+
self.unweighted = unweighted
18+
self.weighted = weighted
19+
}
1620
}
1721
}
18-
extension StatsBreakdown
22+
extension Unidoc.StatsBreakdown
1923
{
2024
private
2125
init<Stats>(
@@ -51,9 +55,7 @@ extension StatsBreakdown
5155
}
5256
}
5357
}
54-
}
55-
extension StatsBreakdown
56-
{
58+
5759
init(
5860
unweighted:__shared Volume.Stats.Coverage,
5961
weighted:__shared Volume.Stats.Coverage,
@@ -150,14 +152,14 @@ extension StatsBreakdown
150152
}
151153
}
152154
}
153-
extension StatsBreakdown
155+
extension Unidoc.StatsBreakdown
154156
{
155157
var condensed:Condensed
156158
{
157159
.init(unweighted: self.unweighted, weighted: self.weighted)
158160
}
159161
}
160-
extension StatsBreakdown:HyperTextOutputStreamable
162+
extension Unidoc.StatsBreakdown:HyperTextOutputStreamable
161163
{
162164
static
163165
func += (html:inout HTML.ContentEncoder, self:Self)

Sources/UnidocPages/Templates/Site.Admin.Tour.swift

Lines changed: 0 additions & 21 deletions
This file was deleted.

Sources/UnidocPages/Templates/Site.Admin.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ extension Site
1111
public
1212
let configuration:Mongo.ReplicaSetConfiguration
1313
public
14-
let tour:Tour
14+
let tour:ServerTour
1515

1616
@inlinable public
17-
init(configuration:Mongo.ReplicaSetConfiguration, tour:Tour)
17+
init(configuration:Mongo.ReplicaSetConfiguration, tour:ServerTour)
1818
{
1919
self.configuration = configuration
2020
self.tour = tour
@@ -114,12 +114,14 @@ extension Site.Admin:AdministrativePage
114114
$0[.dd] = "\(self.tour.started.duration(to: .now))"
115115

116116
$0[.dt] = "requests"
117-
$0[.dd] = "\(self.tour.requests)"
117+
$0[.dd] = "\(self.tour.stats.requests.total)"
118118

119119
$0[.dt] = "bytes transferred (content only)"
120-
$0[.dd] = "\(self.tour.transferred)"
120+
$0[.dd] = "\(self.tour.stats.bytes.total)"
121121
}
122122

123+
main += ServerTour.StatsBreakdown.init(self.tour.stats)
124+
123125
main[.hr]
124126

125127
main[.h2] = "Replica set information"

Sources/UnidocPages/Templates/Site.Docs.Culture.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ extension Site.Docs.Culture:ApplicationPage
109109
{
110110
$0[.h2] = "Interface Breakdown"
111111

112-
$0 += StatsBreakdown.init(
112+
$0 += Unidoc.StatsBreakdown.init(
113113
unweighted: self.master.census.unweighted.decls,
114114
weighted: self.master.census.weighted.decls,
115115
domain: "this module").condensed
116116

117117

118118
$0[.h2] = "Doc Coverage"
119119

120-
$0 += StatsBreakdown.init(
120+
$0 += Unidoc.StatsBreakdown.init(
121121
unweighted: self.master.census.unweighted.coverage,
122122
weighted: self.master.census.weighted.coverage,
123123
domain: "this module").condensed

Sources/UnidocPages/Templates/Site.Docs.Meta.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ extension Site.Docs.Meta:ApplicationPage
155155

156156
$0[.h2] = "Interface Breakdown"
157157

158-
$0 += StatsBreakdown.init(
158+
$0 += Unidoc.StatsBreakdown.init(
159159
unweighted: self.master.census.unweighted.decls,
160160
weighted: self.master.census.weighted.decls,
161161
domain: "this package")
162162

163163

164164
$0[.h2] = "Documentation Coverage"
165165

166-
$0 += StatsBreakdown.init(
166+
$0 += Unidoc.StatsBreakdown.init(
167167
unweighted: self.master.census.unweighted.coverage,
168168
weighted: self.master.census.weighted.coverage,
169169
domain: "this package")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import HTML
2+
3+
extension ServerTour
4+
{
5+
struct Stat:Sendable
6+
{
7+
let stratum:String
8+
let state:String
9+
let value:Int
10+
let `class`:String?
11+
12+
init(stratum:String, state:String, value:Int, `class`:String? = nil)
13+
{
14+
self.stratum = stratum
15+
self.state = state
16+
self.value = value
17+
self.class = `class`
18+
}
19+
}
20+
}
21+
extension ServerTour.Stat
22+
{
23+
private static
24+
func format(share:Double) -> String
25+
{
26+
let permille:Int = .init((share * 1000).rounded())
27+
let (percent, f):(Int, Int) = permille.quotientAndRemainder(
28+
dividingBy: 10)
29+
30+
return "\(percent).\(f)"
31+
}
32+
}
33+
extension ServerTour.Stat:PieSector
34+
{
35+
func legend(_ html:inout HTML.ContentEncoder, share:Double)
36+
{
37+
if share < 0.001
38+
{
39+
return
40+
}
41+
42+
html[.dt] { $0.class = self.class } = "\(self.state)"
43+
html[.dd] = "\(Self.format(share: share))%"
44+
}
45+
46+
func label(share:Double) -> String
47+
{
48+
"""
49+
\(Self.format(share: share)) percent of the \
50+
\(self.stratum) served during this tour were \
51+
\(self.state)
52+
"""
53+
}
54+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
extension ServerTour.Stats
2+
{
3+
@frozen public
4+
struct ByStatus
5+
{
6+
public
7+
var ok:Int
8+
public
9+
var notModified:Int
10+
public
11+
var redirectedPermanently:Int
12+
public
13+
var redirectedTemporarily:Int
14+
public
15+
var notFound:Int
16+
public
17+
var errored:Int
18+
public
19+
var unauthorized:Int
20+
21+
@inlinable public
22+
init(ok:Int = 0,
23+
notModified:Int = 0,
24+
redirectedPermanently:Int = 0,
25+
redirectedTemporarily:Int = 0,
26+
notFound:Int = 0,
27+
errored:Int = 0,
28+
unauthorized:Int = 0)
29+
{
30+
self.ok = ok
31+
self.notModified = notModified
32+
self.redirectedPermanently = redirectedPermanently
33+
self.redirectedTemporarily = redirectedTemporarily
34+
self.notFound = notFound
35+
self.errored = errored
36+
self.unauthorized = unauthorized
37+
}
38+
}
39+
}
40+
extension ServerTour.Stats.ByStatus:ExpressibleByDictionaryLiteral
41+
{
42+
@inlinable public
43+
init(dictionaryLiteral elements:(Never, Int)...)
44+
{
45+
self.init(ok: 0)
46+
}
47+
}

0 commit comments

Comments
 (0)