Master station performance test method, electronic equipment and storage medium
By creating business processing threads and performance testing threads in the EtherCAT master, decoupling business code and test code, flexible performance calculation and control cycle adjustment are achieved, and the cost and complexity problems in the existing technology are solved, improving the flexibility and scalability of performance testing of the EtherCAT master.
Patent Information
- Application Number
- CN202510554343.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-28
- Publication Date
- 2025-08-05
AI Technical Summary
The existing EtherCAT master site performance testing methods are costly and have insufficient flexibility and scalability, high hardware cost, and high software code coupling complexity, making it difficult to meet the flexible performance indicator requirements of different users.
By creating business processing threads and performance test threads, decoupling business code and test code, using function pointers to obtain time parameters and calculate performance results in test mode, supporting flexible performance computing strategies and master control cycle adjustments.
It improves the flexibility of master site performance testing and code scalability, reduces development management costs, and supports flexible performance metric configuration and dynamic adjustment of different users.
Smart Images

Figure CN120434148A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a master station performance testing method, electronic equipment, and storage medium. Background Art
[0002] Ethernet for Control Automation Technology (EtherCAT) is a real-time Ethernet communication protocol based on Ethernet technology. It utilizes Ethernet's physical and data link layers but incorporates specialized optimizations at the network and application layers. This allows for superior real-time performance compared to traditional Ethernet, leading to its widespread adoption in fields requiring high real-time control and communication, such as smart manufacturing, industrial production, and robotics. EtherCAT consists of a master and slaves. As the initiator of EtherCAT communication, the EtherCAT master must maintain excellent performance. Therefore, effective performance testing of the EtherCAT master is essential.
[0003] Currently, there are two main methods for performance testing of EtherCAT master stations: one is hardware-based, which requires the use of an expensive EtherCAT protocol analyzer and is very costly; the other is software-based, which couples the master station's business data processing code with the performance testing code, increasing the complexity of code compilation and reducing the solution's flexibility and scalability. Summary of the Invention
[0004] The purpose of this application is to address the deficiencies in the above-mentioned prior art and provide a master station performance testing method, electronic device and storage medium, so as to improve the flexibility of master station device performance testing and the scalability of code.
[0005] To achieve the above objectives, the technical solutions adopted in the embodiments of the present application are as follows:
[0006] In a first aspect, an embodiment of the present application provides a master station performance testing method, which is applied to a master station device, and the method includes:
[0007] Running a main thread according to an application startup instruction, creating a business processing thread and at least one performance test thread when the main thread runs, and obtaining and parsing parameters input by the user, and determining the current operating mode of the master station device according to the parsing results;
[0008] If the operating mode is the test mode, the business processing thread is run;
[0009] When the business processing thread runs, it performs business processing, obtains at least one time parameter and wakes up each performance test thread, so as to store the time parameter of the master station device and calculate the performance result of the master station device through each performance test thread.
[0010] Optionally, the method further includes:
[0011] If the operation mode is non-test mode, the preset time acquisition function pointer is pointed to an empty function, wherein the program code corresponding to the business processing thread includes the time acquisition function pointer;
[0012] The business processing thread is run, and when the business processing thread is run, the business processing is performed.
[0013] Optionally, before obtaining at least one time parameter, the method further includes:
[0014] Point the preset acquisition time function pointer to the target function;
[0015] The obtaining of at least one time parameter includes:
[0016] The target function is run through the acquisition time function pointer to obtain at least one time parameter.
[0017] Optionally, the at least one performance testing thread includes: a performance parameter storage thread and a performance index calculation thread;
[0018] The performance parameter storage thread is used to store the time parameters of the master station device;
[0019] The performance indicator calculation thread is used to calculate the performance result of the master station device.
[0020] Optionally, when the business processing thread is running, the business processing is performed, and at least one time parameter is obtained and each performance test thread is awakened, so that the time parameter of the master station device is stored through each performance test thread and the performance result of the master station device is calculated, including:
[0021] When the business processing thread is running, obtaining the initial time;
[0022] Determining a wake-up time based on the initial time and a preset master station control cycle;
[0023] When the wake-up time is reached, the performance parameter storage thread is awakened, and when the performance parameter storage thread is running, the parameters are stored, and the performance index calculation thread is awakened, and when the performance index calculation thread is running, the performance result of the master station device is generated according to the time parameter of the master station device and the performance calculation strategy;
[0024] When executing business processing, the time parameters of each business processing stage are obtained, and the performance parameter storage thread stores at least one of the time parameters of each business processing stage, the master station control cycle, the initial time and the wake-up time.
[0025] Optionally, when executing the business process, obtaining the time parameters of each business process stage includes:
[0026] In the data receiving stage, the packet receiving function is called to receive the data to be processed, and the data receiving start time and the data receiving end time are obtained through the target function;
[0027] In the data processing stage, a data processing method is called to process the data to be processed and prepare for data transmission;
[0028] In the data sending phase, the data sending method is called to send data, and the data sending start time and the data sending end time are obtained through the target function.
[0029] Optionally, when the performance indicator calculation thread runs, generating a performance result of the master station device according to a time parameter and a performance calculation strategy of the master station device includes:
[0030] When the performance indicator calculation thread is running, the corresponding time parameters of the master station device are read according to the performance calculation strategy;
[0031] A performance result of the master station device is generated according to the corresponding time parameters of the master station device and the performance calculation strategy.
[0032] Optionally, the method further includes:
[0033] Run the command line configuration thread according to the configuration startup instructions;
[0034] When the command line configuration thread is running, receiving at least one performance indicator configuration information input by the user;
[0035] According to each performance indicator configuration information, each performance calculation strategy is determined, and the performance calculation strategy is sent to the performance indicator calculation thread.
[0036] Optionally, the method further includes:
[0037] When the command line configuration thread is running, receiving a period information modification instruction input by a user;
[0038] A new master station control period is determined according to the period information modification instruction, and the new master station control period is sent to the performance parameter storage thread.
[0039] Optionally, the processor of the master station device includes multiple processing cores, and the business processing thread and each performance test thread run on different processing cores respectively.
[0040] In a second aspect, an embodiment of the present application provides an electronic device comprising: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor. When the electronic device is running, the processor and the storage medium communicate through the bus, and the processor executes the machine-readable instructions to implement the master station performance testing method provided in the first aspect.
[0041] In a third aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the master station performance testing method provided in the first aspect is executed.
[0042] The beneficial effects of this application are:
[0043] The present application provides a master station performance testing method, electronic device, and storage medium, including: running a main thread according to an application startup instruction; when the main thread runs, creating a business processing thread and at least one performance testing thread; obtaining and parsing user input parameters, and determining the current operating mode of the master station device based on the parsing results; if the operating mode is test mode, running the business processing thread; when the business processing thread runs, performing business processing, and obtaining at least one time parameter and waking up each performance testing thread, so that the time parameter of the master station device is stored and the performance results of the master station device are calculated through each performance testing thread. By starting the application to execute the main thread, a business processing thread and a performance testing thread can be created respectively, and the business code is run on the business processing thread and the test code is run on the performance testing thread, thereby achieving decoupling of the business code and the test code; determining the operating mode of the master station device by parsing the user's input parameters, so that in test mode, the time parameter can be obtained through the business processing thread, and the performance testing thread can be woken up to calculate the performance results based on the obtained time parameter. Since the business code and the test code are decoupled, conditional compilation macro isolation is not required, which enhances the scalability of the code and makes the code more maintainable, reducing the development and management costs of developers.
[0044] In addition, by creating a command line configuration thread, users can configure corresponding performance calculation strategies based on their own test needs and test scenarios during program execution, and dynamically adjust the master station control cycle without terminating program execution or recompiling the code, or restarting the application, thereby improving the flexibility of performance testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.
[0046] Figure 1 A schematic diagram of an EtherCAT master station communication relationship provided in an embodiment of the present application;
[0047] Figure 2 A schematic diagram of a hardware packet capture environment in the prior art provided in an embodiment of the present application;
[0048] Figure 3 A flowchart of a master station performance testing method provided in an embodiment of the present application;
[0049] Figure 4 A flowchart of another master station performance testing method provided in an embodiment of the present application;
[0050] Figure 5 A flowchart of another master station performance testing method provided in an embodiment of the present application;
[0051] Figure 6 A flowchart of another master station performance testing method provided in an embodiment of the present application;
[0052] Figure 7 A flowchart of another master station performance testing method provided in an embodiment of the present application;
[0053] Figure 8 A flowchart of another master station performance testing method provided in an embodiment of the present application;
[0054] Figure 9 A flowchart of another master station performance testing method provided in an embodiment of the present application;
[0055] Figure 10 A flowchart of another master station performance testing method provided in an embodiment of the present application;
[0056] Figure 11 A complete flow chart of a master station performance testing method provided in an embodiment of the present application;
[0057] Figure 12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0058] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the drawings in the present application only serve the purpose of illustration and description and are not used to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this application illustrate the operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowcharts can be implemented out of sequence, and steps without logical context can be reversed or implemented simultaneously. In addition, those skilled in the art, under the guidance of the contents of this application, can add one or more other operations to the flowchart, or remove one or more operations from the flowchart.
[0059] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present application.
[0060] It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the existence of the features declared thereafter, but does not exclude the addition of other features.
[0061] EtherCAT is a real-time Ethernet communication protocol based on Ethernet technology. It utilizes Ethernet's physical and data link layers but incorporates specialized optimizations at the network and application layers. This allows for higher real-time performance compared to traditional Ethernet, leading to its widespread adoption in fields requiring high real-time control and communication, such as intelligent manufacturing, industrial production, and robotics. EtherCAT consists of a master and slaves. Slaves are external devices or modules connected to the master via the EtherCAT bus, such as servo controllers and I / O modules. They receive control commands and data from the master and send status information and feedback to the master. The master, initiator of EtherCAT communication, connects to the EtherCAT network via an EtherCAT interface, sending EtherCAT data frames to slaves and receiving data frames returned after processing.
[0062] Figure 1 A schematic diagram of an EtherCAT master station communication relationship provided by an embodiment of the present application. An EtherCAT master station can be built by adding an ordinary Ethernet card to its EtherCAT master station network card driver and EtherCAT master station protocol stack.
[0063] EtherCAT user-mode application: It is an application developed by the user, located at the top layer, and is used to implement specific control or business logic.
[0064] System call: As the interface between user-mode applications and kernel mode, it is responsible for transmitting user-mode application requests to the EtherCAT master protocol stack in the kernel.
[0065] EtherCAT master protocol stack: implements the core part of the EtherCAT protocol, handles communication tasks at the data link layer and network layer, and is responsible for data interaction and protocol processing with slave devices.
[0066] EtherCAT master network card driver: used to control the physical network card device and convert the data of the EtherCAT master protocol stack into a format suitable for sending and receiving by the network card.
[0067] Network card: A physical network interface device responsible for sending and receiving EtherCAT data frames on the network.
[0068] During data transmission, the EtherCAT user-mode application generates data and passes it to the EtherCAT master protocol stack through a system call. The protocol stack encapsulates the data according to the EtherCAT protocol and then passes the encapsulated data to the EtherCAT master network card driver. The network card driver further converts the data into electrical or optical signals and transmits them to the network through the network card.
[0069] During data reception, the network card receives EtherCAT data frames and passes them to the EtherCAT master network card driver. The driver parses the data and passes it to the EtherCAT master protocol stack, which decapsulates and verifies the data. Then, through system calls, it passes the valid data to the EtherCAT user-mode application for processing.
[0070] Generally, the performance of the master station is mainly reflected in the following aspects:
[0071] First: Master Station Test Time (Test Time)
[0072] That is, whether the master station can run stably for a long time without any abnormalities.
[0073] Second, the jitter of the master's communication cycle (Circle time) T0. The master's communication cycle refers to how long it takes the master to send an EtherCAT message, or the time interval between two consecutive messages. This is a fundamental parameter for evaluating EtherCAT master performance. While it affects the master's stable operation, the smaller the Cycle Time, the more stable the master's performance.
[0074] We can test under different cycle time conditions, such as 2ms, 1ms, 500us, 250us, 125us, etc., to observe whether the master station can stably send messages according to the set cycle.
[0075] Third: The EtherCAT master protocol stack and the EtherCAT master network card driver consume time.
[0076] This time is divided into two parts:
[0077] The time consumed by receiving packets is divided into two parts:
[0078] The time it takes for the EtherCAT master network card driver to receive messages from the network card;
[0079] The time it takes for the EtherCAT master protocol stack to pass messages to the user-mode application (that is, the upper-layer application).
[0080] The time consumed in sending a package is exactly the opposite of the time consumed in receiving a package, and is also divided into two parts:
[0081] The time it takes for the EtherCAT master protocol stack to encapsulate the message and pass it to the EtherCAT master network card driver;
[0082] The time it takes for the EtherCAT master network card driver to send messages to the network card.
[0083] Fourth: Applications consume time
[0084] Application time includes the following parts: first, the time it takes for the application to process received data; second, the time it takes for the application to encapsulate the application data into data that can be processed by the host protocol stack.
[0085] Upper-level business users pay attention to this indicator and optimize the application based on this performance indicator.
[0086] The existing technologies for testing the performance of master stations are mainly divided into two methods: hardware and software. Figure 2 Schematic diagram of the hardware packet capture environment in the prior art provided in the embodiments of the present application.
[0087] The hardware testing method is mainly divided into the following steps:
[0088] Step 1: Hardware preparation: Connect an EtherCAT protocol analyzer (such as ET2000) between the master and slave stations.
[0089] Step 2: Configuration phase: Master station communication cycle by modifying the code or configuration file.
[0090] Step 3: Start the master station, wait for the communication between the master station and the slave station to stabilize, and then capture the data packets using a packet capture tool (such as WireShark).
[0091] Step 4: Analyze the data and calculate the jitter time when the master station communication cycle is T0.
[0092] For the current hardware solution, the biggest disadvantage is the cost. The current price of EtherCAT protocol analyzers is very high.
[0093] In current software testing methods, business code and performance testing code are usually coupled together, adding many conditional compilation macros or conditional judgment statements. This not only increases the cyclomatic complexity of the code, but also is not flexible enough and cannot obtain the expected performance indicators at any time.
[0094] For example, if a user wants to modify the communication cycle, they can only terminate the application, modify the communication cycle through code or configuration files, and then restart the application. The communication cycle cannot be modified dynamically.
[0095] Different users and different stages may focus on different performance metrics. For example, an EtherCAT driver developer may be more concerned with the jitter of the master station's communication cycle and the protocol stack's duration, while a higher-layer application may be more concerned with application duration. This application fails to differentiate these metrics for different users and simply presents all or some of them to the customer. Customers are left to analyze which metrics they need and which they don't. If the required metrics are not available, the only option is to manually modify the code to print the desired metrics.
[0096] Based on the above problems, this solution provides a master station performance testing method. By creating a business processing thread and a performance test thread, the business code can be run on the business processing thread, and the test code can be run on the performance test thread. By defining a function pointer in the business processing thread and assigning a value to the function pointer according to the running mode, it is possible to call the function pointer through the business processing thread to obtain the time parameter in the test mode, and wake up the performance test thread to calculate the performance indicators based on the obtained time parameter and the configured performance calculation strategy. Since the business code and the test code are decoupled, the scalability of the code is enhanced and the code is more maintainable. Users can flexibly configure the performance calculation strategy according to their needs without restarting the application, which improves the flexibility of the code and reduces the development and management costs of developers.
[0097] Figure 3 The flowchart of a master station performance test method provided in the embodiment of the present application is as follows; the execution subject of this method can be a master station device, which can be the aforementioned EtherCAT master station. Figure 3 As shown, the method may include:
[0098] S101. According to the application startup instruction, the main thread is run. When the main thread is running, a business processing thread and at least one performance test thread are created, and parameters input by the user are obtained and parsed, and the current operation mode of the master station device is determined according to the parsing results.
[0099] The application can be started by the user. The user enters a start instruction through the application interface to start the application, and the application begins to execute the main thread.
[0100] Users can specify the master device's operating mode by inputting parameters. Operating modes can include test mode or non-test mode, with non-test mode also being considered a business mode. During execution, the main thread obtains and parses the user-entered parameters and determines the master device's current operating mode based on the parsed results.
[0101] At the same time, while the main thread is running, it can also create a business processing thread and at least one performance testing thread. The business processing thread is used to run and manage business code to perform business processing, and the performance testing thread is used to run and manage test code to perform performance testing on the master station device. This achieves decoupling of business code and test code.
[0102] S102: If the operation mode is the test mode, the business processing thread is run.
[0103] When the operating mode is determined to be test mode, the business processing thread runs. Of course, the business processing thread also runs when the operating mode is not test mode. In other words, the business processing thread can run to perform business processing regardless of the operating mode. However, in non-test mode, the business processing thread only performs business processing and does not trigger performance testing.
[0104] S103. When the business processing thread runs, it executes business processing, obtains at least one time parameter and wakes up each performance test thread, so as to store the time parameter of the master station device and calculate the performance result of the master station device through each performance test thread.
[0105] In the test mode, when the business processing thread runs, it can execute business processing according to the business logic, obtain at least one time parameter generated during the business processing, and wake up each performance test thread.
[0106] It is worth noting that the various time parameters to be obtained can be pre-configured according to the performance test requirements. Different performance test requirements focus on different performance indicators, and the time parameters required for calculating different performance indicators are also different.
[0107] Optionally, after the performance test thread is awakened, the performance test thread may store the acquired time parameters of the master station device and calculate the performance results of the master station device while running.
[0108] In summary, the master station performance testing method provided in this embodiment includes: running a main thread according to an application startup instruction; when the main thread runs, creating a business processing thread and at least one performance testing thread; obtaining and parsing user input parameters, and determining the current operating mode of the master station device based on the parsing results; if the operating mode is test mode, running the business processing thread; when the business processing thread runs, performing business processing, and obtaining at least one time parameter and waking up each performance testing thread, so that each performance testing thread stores the time parameter of the master station device and calculates the performance results of the master station device. By starting the application to execute the main thread, a business processing thread and a performance testing thread can be created respectively, and the business code runs on the business processing thread and the test code runs on the performance testing thread, thereby achieving decoupling of the business code and the test code; determining the operating mode of the master station device by parsing the user's input parameters, so that in test mode, the time parameter can be obtained through the business processing thread, and the performance testing thread can be woken up to calculate the performance results based on the obtained time parameter. Since the business code and the test code are decoupled, the scalability of the code is enhanced, the code is more maintainable, and the development and management costs of the developer are reduced.
[0109] Figure 4A flow chart of another master station performance testing method provided in an embodiment of the present application; Figure 4 As shown, the method of the present application may further include:
[0110] S201: If the running mode is non-test mode, point the preset acquisition time function pointer to a null function.
[0111] The program code corresponding to the business processing thread includes a time acquisition function pointer.
[0112] Optionally, a time acquisition function pointer p_get_time may be defined in the program code corresponding to the business processing thread.
[0113] A function pointer is a special type of pointer that points to a function, not ordinary data. In a program, a function has its own entry point address, and a function pointer stores this address. Through a function pointer, you can call the function it points to just like calling a normal function.
[0114] In some embodiments, when the running mode is non-test mode, the time acquisition function pointer p_get_time can be pointed to an empty function, and the empty function does nothing.
[0115] S202: Run the business processing thread. When the business processing thread runs, it executes business processing.
[0116] When the business processing thread is running, business processing can be performed. During the business processing, the empty function pointed to by the time acquisition function pointer is called. At this time, the empty function does not perform any operation, and the business processing thread only performs regular business processing.
[0117] Figure 5 A flowchart of another master station performance testing method provided in an embodiment of the present application; optionally, in step S103, before obtaining at least one time parameter, further comprising:
[0118] S301: Point the preset acquisition time function pointer to the target function.
[0119] In the test mode, the time acquisition function pointer p_get_time is pointed to the target function, wherein the target function can be a time acquisition function get_time_stub. Through the target function, the required time parameters can be obtained.
[0120] In step S103, at least one time parameter is obtained, including:
[0121] S302: Run the target function by obtaining a time function pointer to obtain at least one time parameter.
[0122] When the business processing thread runs, it executes business processing. During the business processing, the business processing thread can run a time acquisition function by acquiring a time function pointer to acquire at least one time parameter.
[0123] Optionally, the at least one time parameter may include: the initial time when the business processing thread starts running, the data reception start time, data reception end time, data sending start time and data sending end time during the business processing thread running process, etc.
[0124] Optionally, the at least one performance testing thread mentioned in step S102 may include: a performance parameter storage thread and a performance index calculation thread.
[0125] The performance parameter storage thread is used to store the time parameters of the master station device; the performance index calculation thread is used to calculate the performance results of the master station device.
[0126] In this embodiment, the performance testing threads created by the main thread during execution may include, but are not limited to: a performance parameter storage thread and a performance index calculation thread.
[0127] The acquired time parameters of the master station device can be stored through the performance parameter storage thread, and the performance index calculation thread can use the stored time parameters to calculate the performance results of the master station device.
[0128] By creating multiple performance test threads, you can improve the efficiency of test code execution and improve the scalability of the code.
[0129] Figure 6 A flow chart of another master station performance testing method provided in an embodiment of the present application; optionally, in step S103, when the business processing thread is running, business processing is performed, and at least one time parameter is obtained and each performance testing thread is awakened, so that the time parameter of the master station device is stored through each performance testing thread and the performance result of the master station device is calculated, which may include:
[0130] S401. When the business processing thread is running, the initial time is obtained.
[0131] After the business processing thread starts running, it can first obtain the current time as the initial time.
[0132] S402: Determine a wake-up time according to the initial time and a preset master station control cycle.
[0133] Then, the wake-up time T_wake is calculated according to the initial time and the preset master station control period T0. That is, after sleeping for T0, the wake-up time is reached, and the wake-up time is the initial time + T0.
[0134] S403. When the wake-up time is reached, wake up the performance parameter storage thread. When the performance parameter storage thread runs, it stores the parameters and wakes up the performance indicator calculation thread. When the performance indicator calculation thread runs, it generates the performance results of the master station device according to the time parameters of the master station device and the performance calculation strategy.
[0135] When the wake-up time is reached, the business processing thread wakes up the performance parameter storage thread. When the performance parameter storage thread runs, it can store the time parameters generated by the business processing thread during the business processing process.
[0136] In some embodiments, the business processing thread can also wake up the performance indicator calculation thread. When the performance indicator calculation thread runs, it can perform performance calculation based on the time parameters stored by the performance parameter storage thread and the performance calculation strategy to obtain the performance results of the master station device.
[0137] In other embodiments, the performance indicator calculation thread may be triggered to wake up by the performance parameter storage thread. The performance indicator calculation thread may be woken up to perform performance calculation during the process of storing the time parameters or after the time parameters are stored.
[0138] It is worth noting that the performance calculation strategy can be configured by the system by default or flexibly configured by the user according to needs.
[0139] S404. When executing business processing, obtain the time parameters of each business processing stage, and store at least one of the time parameters of each business processing stage, the master station control period, the initial time, and the wake-up time by the performance parameter storage thread.
[0140] When the business processing thread is running, it can perform business processing. During the business processing, the time acquisition function can be run by obtaining the time function pointer to obtain the time parameters of each business processing stage, and the performance parameter storage thread stores each time parameter.
[0141] In one implementation, the business processing thread may send each acquired time parameter to the performance parameter storage thread for storage, or the business processing thread may send all acquired time parameters to the performance parameter storage thread for storage after the business processing is completed.
[0142] In another implementation, the performance parameter storage thread may monitor the business processing process of the business processing thread in real time, and actively pull various time parameters for storage.
[0143] Optionally, the performance parameter storage thread may store time parameters of each service processing stage. In addition, the initial time, the master station control cycle, and the wake-up time may also be stored.
[0144] The performance parameter storage thread may first record the time parameters in a cache, and then periodically refresh the time parameters to a log file or a database.
[0145] Figure 7 A flowchart of another master station performance testing method provided in an embodiment of the present application; optionally, in step S404, obtaining time parameters of each business processing stage when executing business processing may include:
[0146] S501. In the data receiving stage, a packet receiving function is called to receive data to be processed, and the data receiving start time and the data receiving end time are obtained through the target function.
[0147] For different users, the performance indicators they focus on at different stages are different, and the time parameters they use are also different.
[0148] This embodiment takes the data transmission and reception stage of the master station device as an example to illustrate the process of obtaining the time parameter.
[0149] In addition, the service processing process of the master station device is usually executed in cycles. Since the service processing flow of each cycle is the same, this embodiment takes one cycle as an example to illustrate the process of obtaining the time parameters of the master station device in one cycle.
[0150] At the sleep time T0, when the wake-up time is reached, the business processing thread calls the time acquisition function pointer p_get_time to run the time acquisition function get_time_stub to obtain the current time T_receive_start as the data reception start time.
[0151] Then, the business processing thread calls the packet receiving function to receive the data to be processed. After completing the data reception, the business processing thread calls the time acquisition function pointer p_get_time to run the time acquisition function get_time_stub to obtain the current time T_receive_end as the data reception end time.
[0152] S502: In the data processing stage, a data processing method is called to process the data to be processed and prepare for data transmission.
[0153] Next, the received data to be processed is processed and preparations are made for sending the data.
[0154] S503: In the data sending phase, the data sending method is called to send data, and the data sending start time and the data sending end time are obtained through the target function.
[0155] Then, the business processing thread continues to call the time acquisition function pointer p_get_time to run the time acquisition function get_time_stub to obtain the current time T_send_start as the data sending start time.
[0156] Then the business processing thread executes data transmission, and after the data transmission is completed, calls the time acquisition function pointer p_get_time to run the time acquisition function get_time_stub to obtain the current time T_tx_end as the data transmission end time.
[0157] In this way, the data transmission and reception process of the current cycle is completed, and the time parameters of the master station device in the current cycle are obtained.
[0158] When multiple cycles are executed in a loop, after obtaining the data sending end time of the current cycle, it jumps to calculating the wake-up time of the next cycle. That is, after obtaining the data sending end time of the current cycle, it sleeps for T0 time, reaches the wake-up time of the next cycle, and wakes up the performance indicator calculation thread again. At the same time, during the business execution process, according to the above steps, the time parameters of the master station device in the next cycle are obtained.
[0159] Therefore, the time parameters of the master device stored in the performance parameter storage thread may include time parameters of the master device in multiple cycles.
[0160] Figure 8 A flowchart of another master station performance testing method provided in an embodiment of the present application is provided. Optionally, in step S403, when the performance indicator calculation thread runs, generating a performance result of the master station device according to the time parameters and performance calculation strategy of the master station device may include:
[0161] S601 : When the performance indicator calculation thread is running, the corresponding time parameters of the master station device are read according to the performance calculation strategy.
[0162] Optionally, when the performance indicator calculation thread is running, it can determine the time parameters required by the performance calculation strategy according to the performance calculation strategy, and read the corresponding time parameters of the master station device from the performance parameter storage thread.
[0163] A performance calculation strategy refers to a performance indicator calculation instruction, or a performance indicator calculation formula. Different performance calculation strategies involve different calculation parameters. Therefore, the corresponding time parameters of the master device can be read based on the performance calculation strategy. This can be done from a log file or database.
[0164] S602: Generate a performance result of the master station device according to the corresponding time parameters of the master station device and the performance calculation strategy.
[0165] Based on the corresponding time parameters of the master station device and the performance calculation strategy, the performance results of the master station device can be calculated and stored in a log file or a database.
[0166] For example, assuming that this test focuses on the time consumed by the master station protocol stack and jitter, the corresponding performance calculation strategies are: time consumed by the master station protocol stack = T_receive_end - T_receive_start + T_tx_end - T_send_start; jitter = T_tx_end - T_wake.
[0167] Therefore, the data reception start time, data reception end time, data transmission start time and data transmission end time of the master device can be read respectively, and the time consumed by the master protocol stack can be calculated according to the above formula.
[0168] Read the data transmission end time and wake-up time of the master device respectively, and calculate the jitter of the master device according to the above formula.
[0169] Figure 9 A flow chart of another master station performance testing method provided in an embodiment of the present application; the method of the present application may also include:
[0170] S701: Run the command line configuration thread according to the configuration startup instruction.
[0171] In some embodiments, the at least one performance test thread created may further include a command line configuration thread; the command line configuration thread is used to configure information based on user input instructions, including but not limited to configuring performance calculation strategies and modifying or configuring the master station control period T0.
[0172] According to the configuration startup instruction input by the user, the command line configuration thread can be started.
[0173] S702: When the command line configuration thread is running, receive at least one performance indicator configuration information input by the user.
[0174] The user can input at least one performance indicator configuration information through the command line. The performance indicator configuration information can be composed of multiple time parameter variables through certain operation logic. The time parameter variables and operation logic used for configuring different performance calculation strategies may vary.
[0175] Assuming that this test is concerned with the time and jitter consumed by the master station protocol stack, enter the following command in the command line:
[0176] $get T_rx_tx=T_receive_end-T_receive_start+T_tx_end-T_send_start
[0177] $get jitter=T_tx_end-T_wake.
[0178] S703: Determine various performance calculation strategies based on various performance indicator configuration information, and send the performance calculation strategies to the performance indicator calculation thread.
[0179] According to the performance indicator configuration information input by the user, various performance calculation strategies can be determined, and the command line configuration thread sends the various performance calculation strategies to the performance indicator calculation thread.
[0180] Of course, the various time parameters required to be stored by the performance parameter storage thread can also be configured through the command line configuration thread.
[0181] In some embodiments, while the command line configuration thread is running, the user can also modify the previously configured performance calculation strategy in real time. For example, if the user no longer focuses on the time and jitter consumed by the master station protocol stack, but instead focuses on the time consumed by the receive protocol stack, the user can enter the command line: $get T_rx = T_receive_end - T_receive_start to generate a performance calculation strategy for calculating the time consumed by the receive protocol stack.
[0182] After the performance calculation strategy is modified, the performance indicator calculation thread can end the execution of the previously configured performance calculation strategy and use the modified performance calculation strategy to calculate the performance results in the next master station control cycle.
[0183] It is worth noting that this method does not need to create a command line configuration thread. When the command line configuration thread is not created, the performance calculation strategy can be configured by the system by default. In this way, only the calculation of fixed performance results can be achieved, and when the default performance calculation strategy changes, the application needs to be restarted and the method needs to be executed again.
[0184] This method creates a command line configuration thread, allowing users to flexibly configure the required performance calculation strategy according to their own test requirements and test scenarios of interest, thereby improving the flexibility of performance calculation.
[0185] In some embodiments, the user can dynamically adjust the configured performance calculation strategy in real time while the method is running without restarting the application, thereby improving the flexibility of the code.
[0186] Figure 10A flowchart of another master station performance testing method provided in an embodiment of the present application; the method of the present application may also include:
[0187] S801: When the command line configuration thread is running, a cycle information modification instruction input by a user is received.
[0188] In some embodiments, when the command line configuration thread is running, it can also receive a period information modification instruction input by the user, where the period information modification instruction is used to instruct to modify the current master station control period T0.
[0189] S802 : Modify the instruction according to the cycle information, determine a new master station control cycle, and send the new master station control cycle to the performance parameter storage thread.
[0190] The cycle information modification instruction may include a new master station control cycle T0 , so that the current master station control cycle T0 may be modified to the new master station control cycle T0 according to the cycle information modification instruction.
[0191] Assuming that the current master station control period T0 is 2 and the new master station control period T0 is 5, the modified new master station control period T0 is 5.
[0192] Similarly, by configuring threads through the command line, users can dynamically adjust the master control cycle while the method is running, without terminating the code, recompiling the code, or restarting the application. This method is more flexible and greatly reduces the developer's development and management costs.
[0193] It is worth noting that when the user modifies the master station control period through the command line configuration thread, since the values of various time parameters in the business processing process are related to the master station control period, then based on the modified master station control period, the calculated wake-up time and the specific values of the time parameters of each business processing stage in the business processing process will change. In other words, the modification of the master station control period will have a certain impact on the calculation results of the time parameters of the business processing thread.
[0194] Based on the modification of the master station control cycle, in the next master station control cycle, the business processing thread can use the modified master station control cycle for business processing, and the previously stored time parameters will no longer participate in the calculation of subsequent performance results. The performance indicator calculation thread can recalculate the performance results based on the new time parameters generated by the business processing thread.
[0195] Figure 11 A complete flow chart of a master station performance testing method provided in an embodiment of the present application; the various process steps involved in the method have been described in detail in the above embodiment and will not be repeated here.
[0196] Optionally, the processor of the master station device includes multiple processing cores, and the service processing thread and each performance test thread run on different processing cores respectively.
[0197] In some embodiments, the processor of the main station device to which the method of the present application is applied can be a multi-core processor, and the business processing threads and performance test threads created above can run on different processing cores respectively, that is, the business processing threads and performance test threads are separately bound to the core to ensure the real-time performance of business processing and performance testing.
[0198] It's worth noting that in this solution, the business code and test code don't require conditional compilation using conditional compilation macros. This means there's no need to release two versions: the official release and the performance test version. Instead, unified compilation options are used, resulting in a single binary release, increasing the scalability of the build process.
[0199] In traditional software development, conditional compilation macros were often used to distinguish between production releases and performance testing releases. For example, in C / C++, preprocessor directives such as #ifdef and #ifndef determine whether certain code is included in the compilation process based on different macro definitions. This requires maintaining two versions: one containing performance testing code and the production release without this test code. This approach not only increases the complexity of code maintenance but is also prone to errors. For example, incorrect macro definition configuration can result in test code remaining in the production release, impacting performance or security.
[0200] This solution uses unified compilation options and publishes only one set of binary releases, meaning that both business functions and test functions are compiled under the same set of rules. This reduces the workload of version management and avoids confusion caused by version differences.
[0201] A unified compilation approach makes project building easier to scale. When adding new functional modules or test cases, you can simply integrate the relevant code into the project according to the unified rules, without having to consider differences between different versions. This makes the project structure clearer and facilitates subsequent maintenance and upgrades.
[0202] Developers do not need to frequently switch and debug between different versions, saving time and energy, and can focus more on the quality of the code itself and functional implementation.
[0203] In summary, the master station performance testing method provided in this embodiment includes: running a main thread according to an application startup instruction; when the main thread runs, creating a business processing thread and at least one performance testing thread; obtaining and parsing user input parameters, and determining the current operating mode of the master station device based on the parsing results; if the operating mode is test mode, running the business processing thread; when the business processing thread runs, performing business processing, and obtaining at least one time parameter and waking up each performance testing thread, so that each performance testing thread stores the time parameter of the master station device and calculates the performance results of the master station device. By starting the application to execute the main thread, a business processing thread and a performance testing thread can be created respectively, and the business code runs on the business processing thread and the test code runs on the performance testing thread, thereby achieving decoupling of the business code and the test code; determining the operating mode of the master station device by parsing the user's input parameters, so that in test mode, the time parameter can be obtained through the business processing thread, and the performance testing thread can be woken up to calculate the performance results based on the obtained time parameter. Since the business code and the test code are decoupled, the conditional compilation macro isolation is not required, which enhances the scalability of the code and makes the code more maintainable, reducing the development and management costs of developers.
[0204] In addition, by creating a command line configuration thread, users can configure corresponding performance calculation strategies based on their own test needs and test scenarios during program execution, and dynamically adjust the master station control cycle without terminating program execution or recompiling the code, or restarting the application, thereby improving the flexibility of performance testing.
[0205] The following describes the equipment and storage media used to execute the master station performance testing method provided in this application. The specific implementation process and technical effects are described above and will not be repeated below.
[0206] Figure 12 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, which may be a computing device with data processing capabilities.
[0207] The device may include: a processor 801 and a storage medium 802 .
[0208] The storage medium 802 is used to store programs, and the processor 801 calls the programs stored in the storage medium 802 to execute the above method embodiment. The specific implementation methods and technical effects are similar and will not be repeated here.
[0209] Among them, the storage medium 802 stores program code, and when the program code is executed by the processor 801, the processor 801 executes various steps in the master station performance testing method according to various exemplary embodiments of the present application described in the above "Exemplary Method" section of this specification.
[0210] The processor 801 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, and can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present application can be directly embodied as being executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor.
[0211] Storage medium 802 is a kind of non-volatile computer readable storage medium, which can be used for storing non-volatile software programs, non-volatile computer executable programs and modules. Storage medium can include at least one type of storage medium, for example, can include flash memory, hard disk, multimedia card, card type storage medium, random access storage medium (Random Access Memory, RAM), static random access storage medium (Static Random Access Memory, SRAM), programmable read-only storage medium (Programmable Read Only Memory, PROM), read-only storage medium (Read Only Memory, ROM), electrically erasable programmable read-only storage medium (Electrically Erasable Programmable Read-Only Memory, EEPROM), magnetic storage medium, disk, optical disk, etc. Storage medium is any other medium that can be used to carry or store desired program code with instruction or data structure form and can be accessed by computer, but is not limited to this. The storage medium 802 in the embodiment of the present application can also be a circuit or other arbitrarily capable of realizing storage function, for storing program instructions and / or data.
[0212] Optionally, the present application also provides a program product, such as a computer-readable storage medium, comprising a program, which is used to perform the above method embodiment when executed by a processor.
[0213] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0214] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0215] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0216] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) or a processor (English: processor) to execute some steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: a USB flash drive, a mobile hard disk, a read-only storage medium (English: Read-Only Memory, abbreviated: ROM), a random access storage medium (English: Random Access Memory, abbreviated: RAM), a disk or an optical disk, and other media that can store program code.
Claims
1. A master station performance testing method, characterized in that: Applied to a master station device, the method includes: Running a main thread according to an application startup instruction, creating a business processing thread and at least one performance test thread when the main thread runs, and obtaining and parsing parameters input by the user, and determining the current operating mode of the master station device according to the parsing results; If the operating mode is the test mode, the business processing thread is run; When the business processing thread runs, it performs business processing, obtains at least one time parameter and wakes up each performance test thread, so as to store the time parameter of the master station device and calculate the performance result of the master station device through each performance test thread.
2. The method according to claim 1, characterized in that The method further comprises: If the operation mode is non-test mode, the preset time acquisition function pointer is pointed to an empty function, wherein the program code corresponding to the business processing thread includes the time acquisition function pointer; The business processing thread is run, and when the business processing thread is run, the business processing is performed.
3. The method according to claim 1, characterized in that Before obtaining at least one time parameter, the method further includes: Point the preset acquisition time function pointer to the target function; The obtaining of at least one time parameter includes: The target function is run through the acquisition time function pointer to obtain at least one time parameter.
4. The method according to claim 1, wherein The at least one performance test thread includes: a performance parameter storage thread and a performance index calculation thread; The performance parameter storage thread is used to store the time parameters of the master station device; The performance indicator calculation thread is used to calculate the performance result of the master station device.
5. The method according to claim 3, characterized in that When the business processing thread runs, the business processing is performed, and at least one time parameter is obtained and each performance test thread is awakened, so that the time parameter of the master station device is stored through each performance test thread and the performance result of the master station device is calculated, including: When the business processing thread is running, obtaining the initial time; Determining a wake-up time based on the initial time and a preset master station control cycle; When the wake-up time is reached, the performance parameter storage thread is awakened, and when the performance parameter storage thread is running, the parameters are stored, and the performance index calculation thread is awakened, and when the performance index calculation thread is running, the performance result of the master station device is generated according to the time parameter of the master station device and the performance calculation strategy; When executing business processing, the time parameters of each business processing stage are obtained, and the performance parameter storage thread stores at least one of the time parameters of each business processing stage, the master station control cycle, the initial time and the wake-up time.
6. The method according to claim 5, characterized in that When executing the business process, obtaining the time parameters of each business process stage includes: In the data receiving stage, the packet receiving function is called to receive the data to be processed, and the data receiving start time and the data receiving end time are obtained through the target function; In the data processing stage, a data processing method is called to process the data to be processed and prepare for data transmission; In the data sending phase, the data sending method is called to send data, and the data sending start time and the data sending end time are obtained through the target function.
7. The method according to claim 5, characterized in that When the performance indicator calculation thread runs, the performance result of the master station device is generated according to the time parameter of the master station device and the performance calculation strategy, including: When the performance indicator calculation thread is running, the corresponding time parameters of the master station device are read according to the performance calculation strategy; A performance result of the master station device is generated according to the corresponding time parameters of the master station device and the performance calculation strategy.
8. The method according to claim 4, characterized in that The method further comprises: Run the command line configuration thread according to the configuration startup instructions; When the command line configuration thread is running, receiving at least one performance indicator configuration information input by the user; According to each performance indicator configuration information, each performance calculation strategy is determined, and the performance calculation strategy is sent to the performance indicator calculation thread.
9. The method according to claim 8, characterized in that The method further comprises: When the command line configuration thread is running, receiving a period information modification instruction input by a user; A new master station control cycle is determined according to the cycle information modification instruction, and the new master station control cycle is sent to the performance parameter storage thread.
10. The method according to any one of claims 1 to 9, characterized in that The processor of the master station device includes multiple processing cores, and the service processing thread and each performance test thread run on different processing cores respectively.
11. An electronic device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores program instructions executable by the processor. When the electronic device is running, the processor and the storage medium communicate via the bus, and the processor executes the program instructions to implement the master station performance test method as described in any one of claims 1 to 10.
12. A computer-readable storage medium, characterized in that The storage medium stores a computer program, and when the computer program is executed by the processor, the method for testing the performance of the master station according to any one of claims 1 to 10 is implemented.