Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions test/apps/instrumentation-overhead/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Instrumentation Overhead Benchmark</title>
</head>
<body>
<h1>Instrumentation Overhead Benchmark</h1>
<p>This page is used for benchmarking debugger instrumentation overhead.</p>
<script src="dist/app.js"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions test/apps/instrumentation-overhead/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "instrumentation-overhead-app",
"private": true,
"scripts": {
"build": "webpack --config ./webpack.config.js"
},
"peerDependencies": {
"@datadog/browser-debugger": "*"
},
"peerDependenciesMeta": {
"@datadog/browser-debugger": {
"optional": true
}
},
"resolutions": {
"@datadog/browser-core": "file:../../../packages/core/package.tgz",
"@datadog/browser-debugger": "file:../../../packages/debugger/package.tgz"
},
"devDependencies": {
"ts-loader": "9.5.1",
"typescript": "5.9.3",
"webpack": "5.105.2"
},
"volta": {
"extends": "../../../package.json"
},
"packageManager": "yarn@4.12.0"
}
23 changes: 23 additions & 0 deletions test/apps/instrumentation-overhead/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Main entry point for instrumentation overhead benchmark
* Exposes both instrumented and non-instrumented functions to window
*/

import * as nonInstrumented from './functions'
import * as instrumented from './instrumented'

declare global {
interface Window {
testFunctions: {
add1: (a: number, b: number) => number
add2: (a: number, b: number) => number
}
USE_INSTRUMENTED?: boolean
}
}

// Expose functions to window based on configuration
// The benchmark will set USE_INSTRUMENTED flag before loading this script
if (typeof window !== 'undefined') {
window.testFunctions = window.USE_INSTRUMENTED ? instrumented : nonInstrumented
}
12 changes: 12 additions & 0 deletions test/apps/instrumentation-overhead/src/functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Non-instrumented baseline functions
* These are the original functions without any instrumentation overhead
*/

export function add1(a: number, b: number): number {
return a + b
}

export function add2(a: number, b: number): number {
return a + b
}
43 changes: 43 additions & 0 deletions test/apps/instrumentation-overhead/src/instrumented.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-disable camelcase, curly, @typescript-eslint/no-unsafe-return */

/**
* Instrumented versions of the functions.
* These follow the debugger instrumentation pattern where $dd_* identifiers
* are injected by the debugger SDK at runtime.
*/

// Global hooks injected by debugger SDK
declare const $dd_probes: (functionId: string) => any[] | undefined
declare const $dd_entry: (probes: any[], self: any, args: Record<string, any>) => void
declare const $dd_return: (
probes: any[],
value: any,
self: any,
args: Record<string, any>,
locals: Record<string, any>
) => any
declare const $dd_throw: (probes: any[], error: Error, self: any, args: Record<string, any>) => void

export function add1(a: number, b: number): number {
const $dd_p = $dd_probes('instrumented.ts;add1')
try {
if ($dd_p) $dd_entry($dd_p, null, { a, b })
const result = a + b
return $dd_p ? $dd_return($dd_p, result, null, { a, b }, { result }) : result
} catch (e) {
if ($dd_p) $dd_throw($dd_p, e as Error, null, { a, b })
throw e
}
}

export function add2(a: number, b: number): number {
const $dd_p = $dd_probes('instrumented.ts;add2')
try {
if ($dd_p) $dd_entry($dd_p, null, { a, b })
const result = a + b
return $dd_p ? $dd_return($dd_p, result, null, { a, b }, { result }) : result
} catch (e) {
if ($dd_p) $dd_throw($dd_p, e as Error, null, { a, b })
throw e
}
}
11 changes: 11 additions & 0 deletions test/apps/instrumentation-overhead/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"outDir": "./dist/",
"strict": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
"lib": ["ES2015", "DOM"],
"types": []
}
}
25 changes: 25 additions & 0 deletions test/apps/instrumentation-overhead/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const path = require('node:path')

module.exports = {
mode: 'production',
entry: './src/app.ts',
target: ['web', 'es2018'],
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
optimization: {
chunkIds: 'named',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'app.js',
},
}
Loading
Loading