Skip to content

Commit

Permalink
[chore] Tie perf run results to hardware profile to get more comparab…
Browse files Browse the repository at this point in the history
…le results (#2283)

* [perf-studio] Track hardware profiles and make summaries for each hardware profile

* [perf-studio] Improve icons + previews
  • Loading branch information
bjoerge committed Feb 2, 2021
1 parent f59e1ff commit 2a27727
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 116 deletions.
6 changes: 6 additions & 0 deletions examples/perf-studio/schemas/cases/typingSpeed/doc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import {TerminalIcon} from '@sanity/icons'

export const typingPerf = {
type: 'document',
name: 'typingPerfTest',
title: 'Typing perf test document',
icon: TerminalIcon,
fields: [
{
name: 'rootStringField',
Expand Down Expand Up @@ -33,10 +37,12 @@ export const deeplyNestedObject = {
],
}

// Todo add a case for typing speed on deeply nested objects
export const deeplyNestedObjectTest = {
name: 'deeplyNestedObjectTest',
type: 'document',
title: 'Deeply nested Objects test',
icon: TerminalIcon,
preview: {
select: {
title: 'deeplyNestedObject.first',
Expand Down
69 changes: 62 additions & 7 deletions examples/perf-studio/schemas/cases/typingSpeed/result.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import {ClockIcon, ActivityIcon} from '@sanity/icons'

export const typingPerfRun = {
name: 'typingPerfRun',
type: 'document',
title: 'Typing perf run',
liveEdit: true,
readOnly: true,
icon: ClockIcon,
fields: [
{type: 'number', name: 'result'},
{type: 'boolean', name: 'ci', title: 'CI', description: 'Was this sample from on a CI server?'},
Expand All @@ -27,7 +31,7 @@ export const typingPerfRun = {
],
},
{type: 'string', name: 'baseVersion'},
{type: 'instance', name: 'instance'},
{name: 'instance', type: 'instance'},
{
type: 'object',
name: 'git',
Expand All @@ -52,15 +56,66 @@ export const typingPerfRun = {
result: 'result',
ci: 'ci',
baseVersion: 'baseVersion',
sha: 'git.sha',
hostname: 'instance.hostname',
},
prepare(values) {
prepare({result, ci, hostname, baseVersion}) {
return {
title: `${values.result}ms @ v${values.baseVersion || '<unknown>'}${
values.ci ? ` (CI)` : ''
}`,
subtitle: values.sha,
title: `${result}ms @ ${hostname} ${ci ? ` (CI)` : ''}`,
subtitle: `Base version: v${baseVersion || '<unknown>'}`,
}
},
},
}

export const typingSpeedSummary = {
type: 'document',
icon: ActivityIcon,
name: 'typingSpeedSummary',
title: 'Typing perf summary',
fields: [
{
name: 'hardwareProfile',
type: 'reference',
to: [{type: 'hardwareProfile'}],
},
{
name: 'runs',
type: 'array',
of: [{type: 'reference', to: {type: 'typingPerfRun'}}],
},
],
preview: {
select: {
hardwareProfileCpu: 'hardwareProfile.cpus.0',
run0: 'runs.0.result',
run1: 'runs.1.result',
run2: 'runs.2.result',
run3: 'runs.3.result',
run4: 'runs.4.result',
run5: 'runs.5.result',
},
prepare({hardwareProfileCpu, run0, run1, run2, run3, run4, run5}) {
const runs = [run0, run1, run2, run3, run4, run5].filter(Boolean)
return {
title: hardwareProfileCpu.model,
subtitle: `Avg. last ${runs.length} runs: ${Math.round(
runs.reduce(plus, 0) / runs.length
)}ms`,
}
},
},
}

const plus = (a, b) => a + b

export const summary = {
type: 'document',
name: 'summary',
fields: [
{
name: 'hardwareProfile',
type: 'reference',
to: [{type: 'hardwareProfile'}],
},
],
}
74 changes: 74 additions & 0 deletions examples/perf-studio/schemas/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import prettyBytes from 'pretty-bytes'
import {PlugIcon} from '@sanity/icons'

export const cpu = {
name: 'cpu',
title: 'CPU',
type: 'object',
fields: [
{name: 'model', type: 'string'}, //
{name: 'speed', type: 'number'}, // (in MHz)
],
}

export const hardwareProfile = {
name: 'hardwareProfile',
type: 'document',
icon: PlugIcon,
fields: [
{name: 'cpus', type: 'array', of: [{type: 'cpu'}], readOnly: true},
{name: 'memory', type: 'number'},
],
preview: {
select: {
cpus: 'cpus',
memory: 'memory',
},
prepare({cpus, memory}) {
return {
title: `${cpus.length}x ${cpus[0].model} (${prettyBytes(memory, {bits: true})} mem)`,
}
},
},
}

export const instance = {
name: 'instance',
title: 'Instance',
type: 'object',
liveEdit: true,
preview: {
select: {
title: 'name',
},
},
fields: [
{name: 'name', title: 'Name', type: 'string'},
{name: 'type', type: 'string', readOnly: true},
{name: 'version', type: 'string', readOnly: true},
{name: 'hostname', type: 'string', readOnly: true},
{name: 'platform', type: 'string', readOnly: true},
{name: 'hardwareProfile', type: 'reference', to: [{type: 'hardwareProfile'}]},
{name: 'arch', type: 'string', readOnly: true},
{
name: 'memory',
type: 'object',
readOnly: true,
fields: [
{name: 'free', type: 'number'},
{name: 'total', type: 'number'},
],
},
{name: 'uptime', type: 'number', readOnly: true},
{
name: 'loadavg',
type: 'object',
readOnly: true,
fields: [
{name: 'avg1m', type: 'number'},
{name: 'avg5m', type: 'number'},
{name: 'avg10m', type: 'number'},
],
},
],
}
33 changes: 0 additions & 33 deletions examples/perf-studio/schemas/instance.ts

This file was deleted.

7 changes: 4 additions & 3 deletions examples/perf-studio/schemas/schema.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import createSchema from 'part:@sanity/base/schema-creator'
import schemaTypes from 'all:part:@sanity/base/schema-type'
import {deeplyNestedObject, typingPerf, deeplyNestedObjectTest} from './cases/typingSpeed/doc'
import {typingPerfRun} from './cases/typingSpeed/result'
import {cpu, instance} from './instance'
import {typingPerfRun, typingSpeedSummary} from './cases/typingSpeed/result'
import {cpu, hardwareProfile, instance} from './common/types'

export default createSchema({
name: 'test-examples',
types: schemaTypes.concat([
typingPerf,
typingPerfRun,
typingSpeedSummary,
instance,
cpu,
deeplyNestedObjectTest,
deeplyNestedObject,
hardwareProfile,
]),
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"gulp-newer": "^1.4.0",
"gulp-sourcemaps": "^2.6.5",
"gulp-watch": "^5.0.1",
"hashids": "^2.2.8",
"hard-rejection": "^2.1.0",
"husky": "^2.5.0",
"lerna": "^3.16.4",
Expand Down
80 changes: 7 additions & 73 deletions perf/suite.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,13 @@
import os from 'os'
import getRepoInfo from 'git-repo-info'
import {uuid} from '@sanity/uuid'
import {omit} from 'lodash'
import createClient from '@sanity/client'
import {testTypingSpeed} from './typingSpeed'
import {runTypingSpeedTest} from './typingSpeed/run'

function getEnv(varName: string) {
if (!(varName in process.env)) {
throw new Error(`Missing environment variable "${varName}"`)
}
return process.env[varName]
}

const writeToken = getEnv('PERF_STUDIO_SANITY_WRITE_TOKEN')
const userToken = getEnv('PERF_TEST_SANITY_SESSION_TOKEN')

export const sanity = createClient({
token: writeToken,
projectId: 'ppsg7ml5',
dataset: 'perf',
useCdn: false,
})

function getInstanceInfo() {
return {
type: os.type(),
platform: os.platform(),
version: os.version(),
hostname: os.hostname(),
arch: os.arch(),
cpus: os.cpus().map((cpu, i) => {
return {...omit(cpu, 'times'), _key: `cpu_${i}`}
}),
}
async function runSuite() {
await runTypingSpeedTest()
}

function getWorkflowInfo() {
const workflowName = process.env.GITHUB_WORKFLOW
if (!workflowName) {
return undefined
}
return {
workflow: workflowName,
action: process.env.GITHUB_ACTION,
runId: process.env.GITHUB_RUN_ID,
}
}

if (!writeToken || !userToken) {
throw new Error('Missing required environment variables')
}

const baseVersion = require('../lerna.json').version

const instance = getInstanceInfo()
const repoInfo = getRepoInfo()
const workflowInfo = getWorkflowInfo()

testTypingSpeed({userToken: userToken}).then(
(result) => {
const docId = uuid()
return sanity.create({
_id: docId,
_type: 'typingPerfRun',
baseVersion,
git: {
branch: repoInfo.branch || undefined,
tag: repoInfo.tag || undefined,
sha: repoInfo.sha || undefined,
},
github: workflowInfo,
result: result,
ci: process.env.CI === 'true',
instance,
})
runSuite().then(
() => {
// eslint-disable-next-line no-console
console.log('Ran performance test suite')
},
(err) => {
// eslint-disable-next-line no-console
Expand Down

0 comments on commit 2a27727

Please sign in to comment.