-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84a584e
commit c9519a9
Showing
31 changed files
with
261 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
import type { CharPtr, VoidPtr } from "./types/emscripten"; | ||
import type { DiagModuleExportsInternal } from "./types/internal"; | ||
|
||
import { diagHelpers, globalObjectsRoot, loaderHelpers, mono_assert } from "./globals"; | ||
|
||
export function ds_rt_websocket_create (urlPtr :CharPtr):number { | ||
return diagHelpers.ds_rt_websocket_create(urlPtr); | ||
} | ||
|
||
export function ds_rt_websocket_send (client_socket :number, buffer:VoidPtr, bytes_to_write:number):number { | ||
return diagHelpers.ds_rt_websocket_send(client_socket, buffer, bytes_to_write); | ||
} | ||
|
||
export function ds_rt_websocket_poll (client_socket :number):number { | ||
return diagHelpers.ds_rt_websocket_poll(client_socket); | ||
} | ||
|
||
export function ds_rt_websocket_recv (client_socket :number, buffer:VoidPtr, bytes_to_read:number):number { | ||
return diagHelpers.ds_rt_websocket_recv(client_socket, buffer, bytes_to_read); | ||
} | ||
|
||
export function ds_rt_websocket_close (client_socket :number):number { | ||
return diagHelpers.ds_rt_websocket_close(client_socket); | ||
} | ||
|
||
export async function loadDiagnosticServer ():Promise<void> { | ||
const asset = loaderHelpers.resolve_single_asset_path("js-module-diag"); | ||
const uri = asset.resolvedUrl; | ||
mono_assert(uri !== undefined, "could not resolve the uri for the js-module-threads asset"); | ||
const mod:DiagModuleExportsInternal = await import(/*! webpackIgnore: true */uri); | ||
mod.setRuntimeGlobals(globalObjectsRoot); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
import type { DiagHelpers, GlobalObjects, LoaderHelpers, RuntimeHelpers, DotnetModuleInternal } from "../types/internal"; | ||
|
||
export let _diagModuleLoaded = false; // please keep it in place also as rollup guard | ||
|
||
export let diagHelpers: DiagHelpers = null as any; | ||
export let runtimeHelpers: RuntimeHelpers = null as any; | ||
export let loaderHelpers: LoaderHelpers = null as any; | ||
export let Module: DotnetModuleInternal = null as any; | ||
|
||
export function setRuntimeGlobalsImpl (globalObjects: GlobalObjects): void { | ||
if (_diagModuleLoaded) { | ||
throw new Error("Diag module already loaded"); | ||
} | ||
_diagModuleLoaded = true; | ||
diagHelpers = globalObjects.diagHelpers; | ||
runtimeHelpers = globalObjects.runtimeHelpers; | ||
loaderHelpers = globalObjects.loaderHelpers; | ||
Module = globalObjects.module; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,70 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
import WasmEnablePerfTracing from "consts:wasmEnablePerfTracing"; | ||
import type { GlobalObjects } from "../types/internal"; | ||
import type { CharPtr, VoidPtr } from "../types/emscripten"; | ||
|
||
import { Module } from "../globals"; | ||
import { utf8ToString } from "../strings"; | ||
import { CharPtr, VoidPtr } from "../types/emscripten"; | ||
import { Module, runtimeHelpers } from "./globals"; | ||
import { createDiagConnectionJs } from "./diag-js"; | ||
import { IDiagConnection } from "./common"; | ||
import { createDiagConnectionWs } from "./diag-ws"; | ||
import { diagHelpers, setRuntimeGlobalsImpl } from "./globals"; | ||
|
||
let socket_handles:Map<number, IDiagConnection> = undefined as any; | ||
let next_socket_handle = 1; | ||
|
||
export function ds_rt_websocket_create (urlPtr :CharPtr):number { | ||
if (!WasmEnablePerfTracing) { | ||
return -1; | ||
} | ||
if (!socket_handles) { | ||
socket_handles = new Map<number, IDiagConnection>(); | ||
} | ||
const url = utf8ToString(urlPtr); | ||
const socket_handle = next_socket_handle++; | ||
const isWebSocket = url.startsWith("ws://") || url.startsWith("wss://"); | ||
const wrapper = isWebSocket | ||
? createDiagConnectionWs(socket_handle, url) | ||
: createDiagConnectionJs(socket_handle, url); | ||
socket_handles.set(socket_handle, wrapper); | ||
return socket_handle; | ||
} | ||
export function setRuntimeGlobals (globalObjects: GlobalObjects): void { | ||
setRuntimeGlobalsImpl(globalObjects); | ||
|
||
export function ds_rt_websocket_send (client_socket :number, buffer:VoidPtr, bytes_to_write:number):number { | ||
if (!WasmEnablePerfTracing) { | ||
return -1; | ||
} | ||
const wrapper = socket_handles.get(client_socket); | ||
if (!wrapper) { | ||
return -1; | ||
} | ||
const message = (new Uint8Array(Module.HEAPU8.buffer, buffer as any, bytes_to_write)).slice(); | ||
return wrapper.send(message); | ||
} | ||
diagHelpers.ds_rt_websocket_create = (urlPtr :CharPtr):number => { | ||
if (!socket_handles) { | ||
socket_handles = new Map<number, IDiagConnection>(); | ||
} | ||
const url = runtimeHelpers.utf8ToString(urlPtr); | ||
const socket_handle = next_socket_handle++; | ||
const isWebSocket = url.startsWith("ws://") || url.startsWith("wss://"); | ||
const wrapper = isWebSocket | ||
? createDiagConnectionWs(socket_handle, url) | ||
: createDiagConnectionJs(socket_handle, url); | ||
socket_handles.set(socket_handle, wrapper); | ||
return socket_handle; | ||
}; | ||
|
||
export function ds_rt_websocket_poll (client_socket :number):number { | ||
if (!WasmEnablePerfTracing) { | ||
return -1; | ||
} | ||
const wrapper = socket_handles.get(client_socket); | ||
if (!wrapper) { | ||
return 0; | ||
} | ||
return wrapper.poll(); | ||
} | ||
diagHelpers.ds_rt_websocket_send = (client_socket :number, buffer:VoidPtr, bytes_to_write:number):number => { | ||
const wrapper = socket_handles.get(client_socket); | ||
if (!wrapper) { | ||
return -1; | ||
} | ||
const message = (new Uint8Array(Module.HEAPU8.buffer, buffer as any, bytes_to_write)).slice(); | ||
return wrapper.send(message); | ||
}; | ||
|
||
export function ds_rt_websocket_recv (client_socket :number, buffer:VoidPtr, bytes_to_read:number):number { | ||
if (!WasmEnablePerfTracing) { | ||
return -1; | ||
} | ||
const wrapper = socket_handles.get(client_socket); | ||
if (!wrapper) { | ||
return -1; | ||
} | ||
return wrapper.recv(buffer, bytes_to_read); | ||
} | ||
diagHelpers.ds_rt_websocket_poll = (client_socket :number):number => { | ||
const wrapper = socket_handles.get(client_socket); | ||
if (!wrapper) { | ||
return 0; | ||
} | ||
return wrapper.poll(); | ||
}; | ||
|
||
export function ds_rt_websocket_close (client_socket :number):number { | ||
if (!WasmEnablePerfTracing) { | ||
return -1; | ||
} | ||
const wrapper = socket_handles.get(client_socket); | ||
if (!wrapper) { | ||
return -1; | ||
} | ||
socket_handles.delete(client_socket); | ||
return wrapper.close(); | ||
} | ||
diagHelpers.ds_rt_websocket_recv = (client_socket :number, buffer:VoidPtr, bytes_to_read:number):number => { | ||
const wrapper = socket_handles.get(client_socket); | ||
if (!wrapper) { | ||
return -1; | ||
} | ||
return wrapper.recv(buffer, bytes_to_read); | ||
}; | ||
|
||
diagHelpers. ds_rt_websocket_close = (client_socket :number):number => { | ||
const wrapper = socket_handles.get(client_socket); | ||
if (!wrapper) { | ||
return -1; | ||
} | ||
socket_handles.delete(client_socket); | ||
return wrapper.close(); | ||
}; | ||
|
||
globalObjects.api.collectTrace = () => { | ||
//TODO | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// TODO | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
|
||
export function mono_log_debug (messageFactory: string | (() => string)) { | ||
} | ||
|
||
export function mono_log_info (msg: string, ...data: any) { | ||
} | ||
|
||
export function mono_log_warn (msg: string, ...data: any) { | ||
} | ||
|
||
export function mono_log_error (msg: string, ...data: any) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.