/* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ export class PluginConvertUtils { private static crlf: string = "\n"; private static leftBrace: string = "{" private static rightBrace: string = "}" public static createHdcCmd(requestString: string, outputPath: string, time: number) { return "hiprofiler_cmd \\" + this.crlf + " -c - \\" + this.crlf + " -o " + outputPath + " \\" + this.crlf + " -t " + time + " \\" + this.crlf + " -s \\" + this.crlf + " -k \\" + this.crlf + "<, indentation: number, needColon: boolean, spacesNumber: number): string { let text = ""; arr.forEach(arrValue => { switch (typeof arrValue) { case "bigint": text = text + ' '.repeat(spacesNumber).repeat(indentation + 1) + this.humpToSnake(key) + ": " + arrValue.toString() + this.crlf break case "boolean": text = text + ' '.repeat(spacesNumber).repeat(indentation + 1) + this.humpToSnake(key) + ": " + arrValue.toString() + this.crlf break case "number": text = text + ' '.repeat(spacesNumber).repeat(indentation + 1) + this.humpToSnake(key) + ": " + arrValue.toString() + this.crlf break case "string": if (arrValue == '') { break } if (arrValue.startsWith("VMEMINFO") || arrValue.startsWith("PMEM")) { text = text + ' '.repeat(spacesNumber).repeat(indentation + 1) + this.humpToSnake(key) + ": " + arrValue.toString() + this.crlf } else { text = text + ' '.repeat(spacesNumber).repeat(indentation + 1) + this.humpToSnake(key) + ": \"" + arrValue.toString() + "\"" + this.crlf } break case "object": default: if (needColon) { text = text + ' '.repeat(spacesNumber).repeat(indentation + 1) + this.humpToSnake(key) + ": " + this.handleObj(arrValue, indentation + 1, needColon, spacesNumber) + "" + this.crlf } else { text = text + ' '.repeat(spacesNumber).repeat(indentation + 1) + this.humpToSnake(key) + this.handleObj(arrValue, indentation + 1, needColon, spacesNumber) + "" + this.crlf } } }) return text; } // 驼峰转snake private static humpToSnake(humpString: string): string { return humpString.replace(/[A-Z]/g, (value) => '_' + value.toLowerCase()); } }