A performance statistics method and device
By converting the SO-layer API interface parameters into byte data and allocating memory space in the Android system, the problem of inaccurate performance statistics of SO-layer API interface in the Android system is solved, and efficient performance statistics data acquisition and processing is achieved.
Patent Information
- Application Number
- CN202010511357.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-08
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2040-06-08
AI Technical Summary
In Android APP programs, when the SO layer C language or C++ is written, the java layer calls the SO layer API interface through the jni layer, the difference in the parameter types of multiple API interfaces makes it impossible to directly compare and count performance data, resulting in performance statistics not Accurate and inefficient.
By obtaining the interface parameters of the SO layer API interface, converting it into byte data, building a one-dimensional array, and using the NewDirectByteBuffer function to allocate memory space in C++ storage memory, converting it to Java storage memory, obtaining performance statistics, and performing performance statistics.
It realizes accurate and efficient performance statistics of the SO layer API interface, improves data transmission efficiency, and ensures the accuracy and efficiency of performance statistics.
Smart Images

Figure CN113835989B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Android program performance analysis, and in particular to a performance statistics method and device. Background Art
[0002] In Android APP programs, the SO layer is usually used to store functional API interfaces with large computing requirements. When developers need to understand the performance of the program, they need to count the calls to each API interface in the SO layer.
[0003] However, the SO layer is written in C or C++, so the Java layer needs to call the API interface provided by the SO layer through the JNI layer. To facilitate the calling of the Java layer, the JNI layer provides a variety of calling methods, so there are multiple API interface parameters in the SO layer involved in related calls. The size of data cannot be directly compared between different parameters, making it impossible to accurately and efficiently perform performance statistics on the SO layer API interface. Summary of the invention
[0004] The present invention provides a performance statistics method and device for accurately and efficiently performing performance statistics on an SO layer API interface.
[0005] To achieve the above objectives, the embodiments of the present invention provide the following solutions:
[0006] In a first aspect, an embodiment of the present invention provides a performance statistics method, including:
[0007] Obtain the interface parameters of the SO layer API interface currently called by the first thread;
[0008] Convert the interface parameters into byte data;
[0009] Construct a one-dimensional array according to the byte data;
[0010] Call NewDirectByteBuffer function to store the one-dimensional array in C++ storage memory;
[0011] Create an env variable, and store the env variable in a thread local storage variable of the first thread;
[0012] Assign the env variable to the value of the C++ storage memory;
[0013] Convert the C++ storage memory into a Java storage memory;
[0014] According to the Java storage memory, obtaining the one-dimensional array;
[0015] According to the one-dimensional array, obtaining performance statistics in the interface parameters of the SO layer API interface;
[0016] According to the performance statistical data, a statistical thread is called to perform performance statistics of the SO layer API interface;
[0017] The converting the interface parameters into byte data includes:
[0018] Determine the data type of the interface parameter;
[0019] If the data type of the interface parameter is int data, the interface parameter is converted into a first byte data consisting of 4 bytes;
[0020] If the data type of the interface parameter is string data, convert the interface parameter into second byte data;
[0021] If the data type of the interface parameter is list <string>data, first convert the interface parameters into a number of string data, and then convert the several string data into third byte data;
[0022] If the data type of the interface parameter is map data, the key value and the value value of the interface parameter are first converted into byte data formats respectively, and then the key value and the value value in the byte data format are concatenated into the fourth byte data.
[0023] In a possible embodiment, creating an env variable and storing the env variable in a thread local storage variable of the first thread includes:
[0024] Call the virtual machine interface to create the env variable;
[0025] Creating a first variable and a first variable release monitoring function;
[0026] Calling the pthread_key_create function according to the first variable and the first variable release detection function to create the thread local storage variable of the first thread;
[0027] Store the env variable in the thread local storage variable.
[0028] In a possible embodiment, converting the C++ storage memory into a Java storage memory includes:
[0029] Create a one-dimensional array encapsulation class;
[0030] Storing the C++ storage memory and its length into the one-dimensional array encapsulation class;
[0031] Transferring the control right of the C++ storage memory to the one-dimensional array encapsulation class;
[0032] Using the move operation, the control right of the C++ storage memory is called, and the C++ storage memory is assigned to the member variable;
[0033] According to the member variable, the NewDirectByteBuffer function is called to convert the C++ storage memory into the Java storage memory.
[0034] In a possible embodiment, after converting the C++ storage memory into a Java storage memory, the method further includes:
[0035] Create a life cycle control template class;
[0036] Use the parameter for accessing the jni interface as the first member variable;
[0037] Create a second member variable of jobject type;
[0038] Create a function name variable of string type;
[0039] Instantiate the lifecycle control template class according to the first member variable, the second member variable and the function name variable to obtain a lifecycle control constructor;
[0040] Assign the first member variable to the env variable;
[0041] The second member variable is assigned a value as an object instance of the one-dimensional array encapsulation class.
[0042] In a possible embodiment, calling a statistical thread according to the performance statistical data to perform performance statistics of the SO layer API interface includes:
[0043] Create a transmission queue;
[0044] storing the performance statistics in the transmission queue;
[0045] By utilizing the upload queue, when the statistical thread is idle, the performance statistical data is transmitted to the statistical thread to perform performance statistics of the SO layer API interface.
[0046] In a second aspect, an embodiment of the present invention provides a performance statistics device, including:
[0047] An interface parameter acquisition module, used to acquire the interface parameters of the SO layer API interface currently called by the first thread;
[0048] A data conversion module, used to convert the interface parameters into byte data;
[0049] A one-dimensional array construction module, used to construct a one-dimensional array according to the byte data;
[0050] A memory allocation module, used for calling NewDirectByteBuffer function to store the one-dimensional array in C++ storage memory;
[0051] An env variable creation module, used for creating an env variable and storing the env variable in a thread local storage variable of the first thread;
[0052] A first assignment module, used for assigning the env variable to the value of the C++ storage memory;
[0053] A memory conversion module, used for converting the C++ storage memory into a Java storage memory;
[0054] A one-dimensional array acquisition module, used for acquiring the one-dimensional array according to the Java storage memory;
[0055] A performance statistics data acquisition module, used to acquire performance statistics data in the interface parameters of the SO layer API interface according to the one-dimensional array;
[0056] A performance statistics module, used to call a statistics thread to perform performance statistics of the SO layer API interface according to the performance statistics data;
[0057] The data conversion module comprises:
[0058] A data type determination module, used to determine the data type of the interface parameter;
[0059] A first conversion module, used for converting the interface parameter into first byte data consisting of 4 bytes when the data type of the interface parameter is int data;
[0060] A second conversion module, used for converting the interface parameter into second byte data when the data type of the interface parameter is string data;
[0061] The third conversion module is used to convert the data type of the interface parameter to list <string>When converting data, the interface parameters are first converted into a number of string data, and then the number of string data are converted into third byte data;
[0062] The fourth conversion module is used to convert the key value and the value value of the interface parameter into byte data format respectively when the data type of the interface parameter is map data, and then splice the key value and the value value in the byte data format into fourth byte data.
[0063] In a possible embodiment, the env variable creation module includes:
[0064] The first creation module is used to call the virtual machine interface to create the env variable;
[0065] A second creation module is used to create a first variable and a first variable release monitoring function;
[0066] A third creation module is used to call a pthread_key_create function according to the first variable and the first variable release detection function to create the thread local storage variable of the first thread;
[0067] The env variable storage module is used to store the env variable in the thread local storage variable.
[0068] In a possible embodiment, the memory conversion module includes:
[0069] One-dimensional array encapsulation class creation module, used to create one-dimensional array encapsulation class;
[0070] A first storage module, used for storing the C++ storage memory and its length into the one-dimensional array encapsulation class;
[0071] A control right transfer module, used for transferring the control right of the C++ storage memory to the one-dimensional array encapsulation class;
[0072] A second assignment module is used to use a move operation to call the control right of the C++ storage memory and assign the C++ storage memory to a member variable;
[0073] The conversion module is used to call the NewDirectByteBuffer function according to the member variable to convert the C++ storage memory into the Java storage memory.
[0074] In a possible embodiment, the device further includes:
[0075] Lifecycle control template class creation module, used to create lifecycle control template class;
[0076] A fourth creation module is used to use the parameter for accessing the jni interface as the first member variable;
[0077] The fifth creation module is used to create a second member variable of the jobject type;
[0078] The sixth creation module is used to create a function name variable of string type;
[0079] A constructor acquisition module, used to instantiate the lifecycle control template class according to the first member variable, the second member variable and the function name variable to obtain a lifecycle control constructor;
[0080] A third assignment module, used for assigning the first member variable to the env variable;
[0081] The fourth assignment module is used to assign the second member variable to the object instance of the one-dimensional array encapsulation class.
[0082] In a possible embodiment, the performance statistics module includes:
[0083] A seventh creation module, used to create a transmission queue;
[0084] A statistical data storage module, used for storing the performance statistical data in the transmission queue;
[0085] The statistics module is used to utilize the upload queue to transmit the performance statistics data to the statistics thread when the statistics thread is idle, so as to perform performance statistics of the SO layer API interface.
[0086] In a third aspect, an embodiment of the present invention provides a computer device, including:
[0087] Memory for storing computer programs;
[0088] A processor is used to execute the computer program to implement the steps of the performance statistics method as described in any one of the first aspects above.
[0089] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the performance statistics method as described in any one of the first aspects above.
[0090] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0091] The present invention first converts the acquired API interface parameters into byte data and constructs a one-dimensional array, and then allocates continuous memory space for the one-dimensional array. When transmitting from the SO layer to the Java layer, the NewDirectByteBuffer function is used to transmit data through the entire memory space, thereby improving the data transmission efficiency, so that the performance statistics of the SO layer API interface can be accurately and efficiently performed. BRIEF DESCRIPTION OF THE DRAWINGS
[0092] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0093] Figure 1 is a flow chart of a performance statistics method provided by an embodiment of the present invention;
[0094] Figure 2 It is a structural schematic diagram of a performance statistics device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0095] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention belong to the scope of protection of the embodiments of the present invention.
[0096] See also Figure 1 , Figure 1 A flowchart of a performance statistics method provided by an embodiment of the present invention specifically includes steps 101 to 110.
[0097] Step 101: Obtain interface parameters of the SO layer API interface currently called by the first thread.
[0098] The purpose of this step is to obtain relevant parameters required for performance statistics.
[0099] Specifically, the first thread is used by a caller in the current Java layer to call one or more API interfaces in the SO layer to implement some specific functions (such as instruction conversion, notification initiation, and camera opening, etc.) through interface calls.
[0100] When the first thread calls the SO layer API interface, this step deliberately leaves the interface parameters of the called API interface.
[0101] Step 102: Convert the interface parameters into byte data.
[0102] The purpose of this step is to prepare for the subsequent step of storing different types of interface parameters in the same memory space to improve transmission efficiency.
[0103] Specifically, since the data type in the Java layer is the jbyteArray type, and the corresponding data type in C++ in the SO layer is the char* type, both data are in units of one byte. Therefore, through the data type conversion in this step, the data encoding format of the interface parameter jbyteArray in the Java layer and the data encoding format of char* in the SO layer are matched one by one, which is convenient for subsequent performance statistics.
[0104] Here, the present invention also provides a better interface parameter conversion solution, the specific solution is:
[0105] The step of converting the interface parameters into byte data includes steps 21 to 25.
[0106] Step 21, determining the data type of the interface parameter.
[0107] The purpose of this step is to determine the parameter type to facilitate data conversion for different parameter types.
[0108] Specifically, common data types of API interface parameters include int, string, list, and map. Each type of data has its corresponding data declaration. Through this declaration, the data type of the interface parameter can be easily determined.
[0109] Step 22: If the data type of the interface parameter is int data, convert the interface parameter into a first byte data consisting of 4 bytes.
[0110] The purpose of this step is to provide a solution for converting interface parameters belonging to int data into byte data.
[0111] Step 23: If the data type of the interface parameter is string data, convert the interface parameter into second byte data.
[0112] The purpose of this step is to provide a solution for converting interface parameters belonging to string data into byte data.
[0113] Step 24: If the data type of the interface parameter is list <string>data, the interface parameters are first converted into a number of string data, and then the number of string data are converted into third byte data.
[0114] The purpose of this step is to provide a <string>The scheme for converting the data interface parameters into byte data.
[0115] Step 25: If the data type of the interface parameter is map data, first convert the key value and the value value of the interface parameter into byte data format respectively, and then concatenate the key value and the value value in the byte data format into fourth byte data.
[0116] The purpose of this step is to provide a solution for converting the interface parameters belonging to the map data into byte data.
[0117] Specifically, when there are multiple interface parameters, each interface parameter is first converted into byte data one by one, and then the byte data corresponding to all the interface parameters are obtained by splicing.
[0118] Step 103: construct a one-dimensional array according to the byte data.
[0119] The purpose of this step is to write the byte data into the one-dimensional array jbyteArray to facilitate subsequent calls by the Java layer.
[0120] Step 104, calling the NewDirectByteBuffer function to store the one-dimensional array in the C++ storage memory.
[0121] The purpose of this step is to allocate continuous storage memory space for the one-dimensional array jbyteArray to achieve efficient data transmission.
[0122] The specific execution code is:
[0123] NewDirectByteBuffer(buffer->data(),bufferlen).
[0124] Among them, data() is a function for obtaining data, which is used to obtain the one-dimensional array jbyteArray; buffer is the storage memory allocated by the NewDirectByteBuffer function for the one-dimensional array jbyteArray; bufferlen is the length (size) of the storage memory.
[0125] Step 105: create an env variable, and store the env variable in a thread local storage variable of the first thread.
[0126] The purpose of this step is: the env variable must be used for subsequent data transmission and must be created in advance.
[0127] Specifically, the env variable is the JNIEnv variable of the system, which is the environment variable of the jni call interface. Since the env variable is needed to call the NewDirectByteBuffer function, and the variable does not support cross-thread access, the call to the NewDirectByteBuffer function must be the env variable of the caller's thread, otherwise it will cause a program error.
[0128] This step stores the env variable in the thread-local storage variable of the first thread. When the env variable is called, it is obtained from the thread-local storage variable. In this way, when the env variable is needed anywhere, the env variables obtained by calling the interface are all the env variables of the thread itself, which will not cause program errors.
[0129] Step 106, assigning the env variable to the value of the C++ storage memory.
[0130] The purpose of this step is to transfer the data stored in the C++ storage memory to the env variable to facilitate the subsequent call of the Java layer.
[0131] The specific execution code is:
[0132] env->NewDirectByteBuffer(buffer->data(),bufferlen).
[0133] Step 107, converting the C++ storage memory into Java storage memory.
[0134] The purpose of this step is to realize data transmission from SO layer to Java layer through memory conversion.
[0135] Step 108: Obtain the one-dimensional array according to the Java storage memory.
[0136] The purpose of this step is to enable the Java layer to obtain a one-dimensional array jbyteArray by reading the Java storage memory.
[0137] Step 109: Obtain performance statistics in the interface parameters of the SO layer API interface according to the one-dimensional array.
[0138] The purpose of this step is to separate the data related to performance statistics from the one-dimensional array jbyteArray to facilitate the subsequent performance statistics.
[0139] Specifically, the performance statistics data may include data such as the name of the called function, the size of the transferred data, the time consumed by the called function when calling, and the thread ID.
[0140] This step designs a data structure to store performance statistics. This embodiment creates a data structure each time the SO layer API interface is called and stores it in a global list. <data>The data structure is then populated with related performance statistics.
[0141] The specific execution code is:
[0142] Struct data{
[0143] String funcname;
[0144] size_t len_;
[0145] Uint64_t time;
[0146] Uint64_t threaid;
[0147] }.
[0148] Among them, String funcname is the name of the called function, size_t len_ is the size of the data to be transferred, Uint64_t time is the time consumed by the called function when calling, and Uint64_t threaid is the thread id.
[0149] Step 110: Call a statistical thread based on the performance statistical data to perform performance statistics of the SO layer API interface.
[0150] The purpose of this step is to perform performance statistics on the SO layer API interface through a statistics thread specifically used for performance statistics.
[0151] Specifically, the interface parameters of the SO layer API interface are generated when the C++ layer calls. In order to ensure the accuracy of statistical data, there can only be one thread for performance statistics. When the statistical thread is called, the timing of the call can be obtained at the C++ layer. Therefore, a key threshold can be set in advance to determine whether the current call exceeds the threshold to determine whether it is allowed to be called. If it exceeds the threshold, the relevant API interface name can be obtained and printed, so that the developer can be informed that there are calls exceeding the threshold, so that detection can be performed. At the same time, the stack information of the function call can be obtained at the C++ layer, so that the entire call chain can be printed out, so that the developer can be more conveniently informed of which function entry the call was made from, so as to better find and optimize problems.
[0152] In a possible embodiment, the present invention also provides a better solution for creating and storing env variables, and the specific solution is:
[0153] The step of creating an env variable and storing the env variable in a thread local storage variable of the first thread includes steps 31 to 34.
[0154] Step 31, calling the virtual machine interface to create the env variable.
[0155] The purpose of this step is to:
[0156] The specific execution code is: Create a blank env variable for easy use when calling the function.
[0157] g_jvm->GetEnv(&env,JNI_VERSION_1_6).
[0158] Specifically, the env variable created in this step is an empty variable, and you can add a specific value to it by assigning it.
[0159] Step 32: Create a first variable and a first variable release monitoring function.
[0160] The purpose of this step is that the first variable and the first variable release monitoring function in this step are necessary elements in the thread local storage variable of the subsequent first thread.
[0161] The specific execution code is:
[0162] static pthread_key_t gjni
[0163] static void JDestructor(void*gjni).
[0164] Among them, the first variable gjni needs to be defined as a global variable that will not be released, otherwise after it is released, subsequent access to the variable will cause a program error.
[0165] After creating the first variable gjni, you need to write a first variable release monitoring function to know whether the first variable gjni is released, so that subsequent functions can determine whether they can continue to access the env variable. The Destructor function provides the timing point of the first variable release, so as to facilitate the judgment of whether other functions can continue to be executed.
[0166] Step 33: Call the pthread_key_create function according to the first variable and the first variable release detection function to create the thread local storage variable of the first thread.
[0167] The purpose of this step is to call the pthread_key_create function to create the thread-local storage variable of the first thread to store the env variable.
[0168] The specific execution code is:
[0169] pthread_key_create(&gjni,&JDestructor).
[0170] Step 34, storing the env variable in the thread local storage variable.
[0171] The purpose of this step is to store the env variable in the thread local storage variable to facilitate subsequent data transmission.
[0172] The specific execution code is:
[0173] pthread_setspecific(gjni,env).
[0174] When a thread calls the control right of C++ storage memory to control the C++ storage memory, if other callers also call the control right of C++ storage memory, it will cause program errors. In order to prevent this from happening, the present invention also provides a better control scheme, which is as follows:
[0175] The converting of the C++ storage memory into the Java storage memory includes steps 41 to 45.
[0176] Step 41, create a one-dimensional array encapsulation class.
[0177] The purpose of this step is to facilitate the encapsulation of C++ storage memory and its length, as well as the control of C++ storage memory.
[0178] Step 42, storing the C++ storage memory and its length into the one-dimensional array encapsulation class.
[0179] The purpose of this step is to avoid program errors caused by subsequent multi-threaded control.
[0180] Step 43: Transfer the control right of the C++ storage memory to the one-dimensional array encapsulation class.
[0181] The purpose of this step is to avoid program errors caused by multiple threads calling C++ to control the storage memory.
[0182] Step 44, using the move operation, calling the control right of the C++ storage memory, and assigning the C++ storage memory to the member variable.
[0183] The purpose of this step is to avoid program errors caused by multiple threads calling C++ to control the storage memory.
[0184] The specific execution codes of step 41 to step 44 are:
[0185] Class jbyteArrayIO{
[0186] jbyteArrayIO(unique_ptr<uint8_t*> buffer,size_t len):buffer_(move(buffer),len_(len).
[0187] Among them, the Move function can transfer control from one variable to another.
[0188] Here, the buffer and length of the C++ layer are passed to this class for storage, and the caller needs to transfer the control of buff to jbyteArrayIO. In order to facilitate the management of the buffer and prevent the caller from making mistakes, the unique_ptr smart pointer is used to manage buff. Since unique_ptr cannot be copied, when the caller calls, it is required to transfer the control of the buffer to it in order to call correctly. The move operation must also be used to assign the parameter buffer to the member variable buffer_.
[0189] Step 45: Call the NewDirectByteBuffer function according to the member variable to convert the C++ storage memory into the Java storage memory.
[0190] The purpose of this step is to perform memory conversion to facilitate the Java layer thread to obtain interface parameters.
[0191] The specific execution code is:
[0192] javabuffer_=env->NewDirectByteBuffer(buffer_,len_));}.
[0193] Since the present invention involves many variables and Java objects, the life cycles of these variables and Java objects must be consistent, otherwise program errors will occur. To this end, the present invention also specifically provides a solution for life cycle management to avoid program errors due to inconsistent life cycles. The specific solution is:
[0194] After converting the C++ storage memory into the Java storage memory, the method further includes steps 51 to 57.
[0195] Step 51, create a life cycle control template class.
[0196] The purpose of this step is to: construct the necessary steps for the life cycle control constructor.
[0197] The specific execution code is:
[0198] class ScopedLocal{.
[0199] Step 52: Use the parameter for accessing the jni interface as the first member variable.
[0200] The purpose of this step is to: construct the necessary steps for the life cycle control constructor.
[0201] Specifically, this step stores the parameters for accessing the jni interface in the lifecycle control template class classScopedLocal. It only needs to be obtained once when the jni interface is called for the first time and then stored. It can be used directly by reading it later, saving the time for each acquisition and improving the overall efficiency.
[0202] The specific execution code is:
[0203] JNIEnv*env_.
[0204] Step 53, create a second member variable of the jobject type.
[0205] The purpose of this step is to: construct the necessary steps for the life cycle control constructor.
[0206] Specifically, the purpose of choosing jobject is that it can be converted into other types of Java objects. It is a general term for Java objects, which can be converted to jint or other objects.
[0207] The specific execution code is:
[0208] jobject obj_.
[0209] Step 54, create a function name variable of string type.
[0210] The purpose of this step is: the function name variable contains the concatenation of the class and the function, preventing two different classes from having the same function name, and adding the class can ensure the uniqueness of each function name.
[0211] The specific execution code is:
[0212] String name_.
[0213] Step 55: Instantiate the lifecycle control template class according to the first member variable, the second member variable and the function name variable to obtain a lifecycle control constructor.
[0214] The purpose of this step is: the life cycle control constructor is used to control the life cycle of variables and Java objects.
[0215] The specific execution code is:
[0216] ScopedLocal(JNIEnv*env_,jobject obj_,String name_){.
[0217] Step 56, assigning the first member variable to the env variable.
[0218] The purpose of this step is to: construct the necessary steps for the life cycle control constructor.
[0219] The specific execution code is:
[0220] env_=env.
[0221] Step 57: assign the second member variable to the object instance of the one-dimensional array encapsulation class.
[0222] The purpose of this step is to: construct the necessary steps for the life cycle control constructor.
[0223] obj_=obj.
[0224] Specifically, through this constructor, the memory size of the jbyteArrayIO object can be obtained, so that the memory size required for data transmission can be known.
[0225] To ensure the normal operation of the program, the constructor also provides the following controls:
[0226] 1. Determine whether obj_ is empty;
[0227] 2. If obj_ is not empty, delete the local reference to obj_;
[0228] 3. Delete the obj_ variable, and then release the C++ memory and Java memory.
[0229] The specific execution code is:
[0230] ~ScopedLocal(){
[0231] if (obj_!= null);
[0232] env_->DeleteGlobalRef(obj_);
[0233] delete obj_;}.
[0234] All direct calling relationships between Java and C++ must use the ScopedLocal class defined in the above steps to encapsulate parameters, so that the interface parameters of all called API interfaces can be known and all data can be counted.
[0235] In actual applications, there may be other threads that call the API interface of the SO layer at the same time as the first thread. In this case, it is also necessary to obtain the call status of other threads to accurately count the call status of the interface parameters. However, there is only one statistical thread. In this case, statistical congestion is likely to occur, which is not conducive to the statistical process and may even cause program errors. To this end, the present invention also provides the following scheme to efficiently complete the multi-threaded data upload statistics. The specific scheme is:
[0236] In a possible embodiment, calling a statistical thread according to the performance statistical data to perform performance statistics of the SO layer API interface includes steps 61 to 63.
[0237] Step 61, create a transmission queue.
[0238] The purpose of this step is to use the transmission queue to achieve the orderly upload of performance statistics of different threads, so as to facilitate the rapid and accurate performance statistics.
[0239] Specifically, the transmission queue created in this step is unique to the first thread.
[0240] Step 62: Store the performance statistics in the transmission queue.
[0241] The purpose of this step is to store performance statistics in the transmission queue to facilitate data statistics.
[0242] Step 63: Utilize the upload queue to transmit the performance statistics data to the statistics thread when the statistics thread is idle, and perform performance statistics of the SO layer API interface.
[0243] The purpose of this step is to utilize the idle interval of the statistical thread to sequentially transmit the performance statistical data of different threads to the statistical thread, so as to facilitate the performance statistics.
[0244] Based on the same inventive concept as the method, the embodiment of the present invention also provides a performance statistics device, such as Figure 2 The structure diagram of the device embodiment is shown, which specifically includes:
[0245] The interface parameter acquisition module 701 is used to acquire the interface parameters of the SO layer API interface currently called by the first thread;
[0246] The data conversion module 702 is used to convert the interface parameters into byte data;
[0247] A one-dimensional array construction module 703 is used to construct a one-dimensional array according to the byte data;
[0248] A memory allocation module 704 is used to call the NewDirectByteBuffer function to store the one-dimensional array in the C++ storage memory;
[0249] An env variable creation module 705, used for creating an env variable and storing the env variable in a thread local storage variable of the first thread;
[0250] A first assignment module 706, used for assigning the env variable to the value of the C++ storage memory;
[0251] A memory conversion module 707, used for converting the C++ storage memory into a Java storage memory;
[0252] A one-dimensional array acquisition module 708, configured to acquire the one-dimensional array according to the Java storage memory;
[0253] The performance statistics data acquisition module 709 is used to acquire the performance statistics data in the interface parameters of the SO layer API interface according to the one-dimensional array;
[0254] The performance statistics module 710 is used to call the statistics thread according to the performance statistics data to perform performance statistics of the SO layer API interface;
[0255] The data conversion module 702 includes:
[0256] A data type determination module, used to determine the data type of the interface parameter;
[0257] A first conversion module, used for converting the interface parameter into first byte data consisting of 4 bytes when the data type of the interface parameter is int data;
[0258] A second conversion module, used for converting the interface parameter into second byte data when the data type of the interface parameter is string data;
[0259] The third conversion module is used to convert the data type of the interface parameter to list <string>When converting data, the interface parameters are first converted into a number of string data, and then the number of string data are converted into third byte data;
[0260] The fourth conversion module is used to convert the key value and the value value of the interface parameter into byte data format respectively when the data type of the interface parameter is map data, and then splice the key value and the value value in the byte data format into fourth byte data.
[0261] In a possible embodiment, the env variable creation module 705 includes:
[0262] The first creation module is used to call the virtual machine interface to create the env variable;
[0263] A second creation module is used to create a first variable and a first variable release monitoring function;
[0264] A third creation module is used to call a pthread_key_create function according to the first variable and the first variable release detection function to create the thread local storage variable of the first thread;
[0265] The env variable storage module is used to store the env variable in the thread local storage variable.
[0266] In a possible embodiment, the memory conversion module 704 includes:
[0267] One-dimensional array encapsulation class creation module, used to create one-dimensional array encapsulation class;
[0268] A first storage module, used for storing the C++ storage memory and its length into the one-dimensional array encapsulation class;
[0269] A control right transfer module, used for transferring the control right of the C++ storage memory to the one-dimensional array encapsulation class;
[0270] A second assignment module is used to use a move operation to call the control right of the C++ storage memory and assign the C++ storage memory to a member variable;
[0271] The conversion module is used to call the NewDirectByteBuffer function according to the member variable to convert the C++ storage memory into the Java storage memory.
[0272] In a possible embodiment, the device further includes:
[0273] Lifecycle control template class creation module, used to create lifecycle control template class;
[0274] A fourth creation module is used to use the parameter for accessing the jni interface as the first member variable;
[0275] The fifth creation module is used to create a second member variable of the jobject type;
[0276] The sixth creation module is used to create a function name variable of string type;
[0277] A constructor acquisition module, used to instantiate the lifecycle control template class according to the first member variable, the second member variable and the function name variable to obtain a lifecycle control constructor;
[0278] A third assignment module, used for assigning the first member variable to the env variable;
[0279] The fourth assignment module is used to assign the second member variable to the object instance of the one-dimensional array encapsulation class.
[0280] In a possible embodiment, the performance statistics module 709 includes:
[0281] A seventh creation module, used to create a transmission queue;
[0282] A statistical data storage module, used for storing the performance statistical data in the transmission queue;
[0283] The statistics module is used to utilize the upload queue to transmit the performance statistics data to the statistics thread when the statistics thread is idle, so as to perform performance statistics of the SO layer API interface.
[0284] Based on the same inventive concept as the method, an embodiment of the present invention further provides a computer device, including:
[0285] Memory for storing computer programs;
[0286] A processor is used to execute the computer program to implement the steps of the performance statistics method as described in the above method embodiment.
[0287] Based on the same inventive concept as the method, an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the performance statistics method described in the above method embodiment are implemented.
[0288] Compared with the prior art, the embodiments of the present invention have the following advantages and beneficial effects:
[0289] The embodiment of the present invention first converts the acquired API interface parameters into byte data and constructs a one-dimensional array, and then allocates continuous memory space for the one-dimensional array. When transmitting from the SO layer to the Java layer, the NewDirectByteBuffer function is used to transmit data through the entire memory space, thereby improving the data transmission efficiency, thereby enabling accurate and efficient performance statistics of the SO layer API interface.
[0290] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0291] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (devices, systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded computer, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0292] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0293] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0294] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present application.
[0295] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.< / string> < / data> < / string> < / string> < / string> < / string>
Claims
1. A performance statistics method, characterized in that: include: Obtain the interface parameters of the SO layer API interface currently called by the first thread; Convert the interface parameters into byte data; Construct a one-dimensional array according to the byte data; Call NewDirectByteBuffer function to store the one-dimensional array in C++ storage memory; Create an env variable, and store the env variable in a thread local storage variable of the first thread; Assign the env variable to the value of the C++ storage memory; Convert the C++ storage memory into a Java storage memory; According to the Java storage memory, obtaining the one-dimensional array; According to the one-dimensional array, obtaining performance statistics in the interface parameters of the SO layer API interface; According to the performance statistical data, a statistical thread is called to perform performance statistics of the SO layer API interface; The converting the interface parameters into byte data includes: Determine the data type of the interface parameter; If the data type of the interface parameter is int data, the interface parameter is converted into a first byte data consisting of 4 bytes; If the data type of the interface parameter is string data, convert the interface parameter into second byte data; If the data type of the interface parameter is list <string> data, first convert the interface parameters into a number of string data, and then convert the several string data into third byte data;< / string> If the data type of the interface parameter is map data, first convert the key value and the value value of the interface parameter into byte data format respectively, and then concatenate the key value and the value value in the byte data format into fourth byte data; The converting the C++ storage memory into the Java storage memory comprises: Create a one-dimensional array encapsulation class; Storing the C++ storage memory and its length into the one-dimensional array encapsulation class; Transferring the control right of the C++ storage memory to the one-dimensional array encapsulation class; Using the move operation, the control right of the C++ storage memory is called, and the C++ storage memory is assigned to the member variable; According to the member variable, the NewDirectByteBuffer function is called to convert the C++ storage memory into the Java storage memory.
2. The performance statistics method according to claim 1, characterized in that: The step of creating an env variable and storing the env variable in a thread local storage variable of the first thread includes: Call the virtual machine interface to create the env variable; Creating a first variable and a first variable release monitoring function; Calling the pthread_key_create function according to the first variable and the first variable release detection function to create the thread local storage variable of the first thread; Store the env variable in the thread local storage variable.
3. The performance statistics method according to claim 2, characterized in that: After converting the C++ storage memory into the Java storage memory, the method further comprises: Create a life cycle control template class; Use the parameter for accessing the jni interface as the first member variable; Create a second member variable of jobject type; Create a function name variable of string type; Instantiate the lifecycle control template class according to the first member variable, the second member variable and the function name variable to obtain a lifecycle control constructor; Assign the first member variable to the env variable; The second member variable is assigned a value as an object instance of the one-dimensional array encapsulation class.
4. The performance statistics method according to claim 1, characterized in that: The calling of the statistical thread according to the performance statistical data to perform performance statistics of the SO layer API interface includes: Create a transmission queue; storing the performance statistics in the transmission queue; By utilizing the transmission queue, when the statistical thread is idle, the performance statistical data is transmitted to the statistical thread to perform performance statistics of the SO layer API interface.
5. A performance statistics device, characterized in that: include: An interface parameter acquisition module, used to acquire the interface parameters of the SO layer API interface currently called by the first thread; A data conversion module, used to convert the interface parameters into byte data; A one-dimensional array construction module, used to construct a one-dimensional array according to the byte data; A memory allocation module, used for calling NewDirectByteBuffer function to store the one-dimensional array in C++ storage memory; An env variable creation module, used for creating an env variable and storing the env variable in a thread local storage variable of the first thread; A first assignment module, used for assigning the env variable to the value of the C++ storage memory; A memory conversion module, used for converting the C++ storage memory into a Java storage memory; The memory conversion module comprises: One-dimensional array encapsulation class creation module, used to create one-dimensional array encapsulation class; A first storage module, used for storing the C++ storage memory and its length into the one-dimensional array encapsulation class; A control right transfer module, used for transferring the control right of the C++ storage memory to the one-dimensional array encapsulation class; A second assignment module is used to use a move operation to call the control right of the C++ storage memory and assign the C++ storage memory to a member variable; A conversion module, used for calling the NewDirectByteBuffer function according to the member variable to convert the C++ storage memory into the Java storage memory; A one-dimensional array acquisition module, used for acquiring the one-dimensional array according to the Java storage memory; A performance statistics data acquisition module, used to acquire performance statistics data in the interface parameters of the SO layer API interface according to the one-dimensional array; A performance statistics module, used to call a statistics thread to perform performance statistics of the SO layer API interface according to the performance statistics data; The data conversion module comprises: A data type determination module, used to determine the data type of the interface parameter; A first conversion module, used for converting the interface parameter into first byte data consisting of 4 bytes when the data type of the interface parameter is int data; A second conversion module, used for converting the interface parameter into second byte data when the data type of the interface parameter is string data; The third conversion module is used to convert the data type of the interface parameter to list <string> When converting data, the interface parameters are first converted into a number of string data, and then the number of string data are converted into third byte data;< / string> The fourth conversion module is used to convert the key value and the value value of the interface parameter into byte data format respectively when the data type of the interface parameter is map data, and then splice the key value and the value value in the byte data format into fourth byte data.
6. The performance statistics device according to claim 5, characterized in that: The env variable creation module includes: The first creation module is used to call the virtual machine interface to create the env variable; A second creation module is used to create a first variable and a first variable release monitoring function; A third creation module is used to call a pthread_key_create function according to the first variable and the first variable release detection function to create the thread local storage variable of the first thread; The env variable storage module is used to store the env variable in the thread local storage variable.
7. A computer device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the computer program to implement the steps of the method according to any one of claims 1 to 4.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
