Metadata collection implementation in C ++
What I want to do is extract the name of Test_case and the duration of Test_case (unit: seconds). Below is a sample metadata.
Start| 20140618 root (6033) | tpi 1.4 | 14:53:52 10050943579848 0 |Start| 20814 SunOS 5.11 11.2 i86pc tcx4440-01 |STF_ENV| STC_NAME = os-zones |STF_ENV| STC_VERSION = 2.10.0 |STF_ENV| STC_OS_VERSION = 5.11 |STF_ENV| STF_EXECUTE_MODE = ipkg:amd64 |STF_ENV| cwd = /opt/stc/suites/os/zones/tests/os/functional |Test_Case_Start| 20858 tests/os/functional/setup | 14:53:52 10051107110387 0 |stdout| stdout| 14:53:53 SUCCESS: zone_is_running zone2stdout| zone 'zone2' is runningstdout| stdout| 14:53:53 SUCCESS: zone_is_running zone1stdout| zone 'zone1' is runningstdout| 14:53:53 zones 'zone2 zone1 ' are runningTest_Case_End| 20858 tests/os/functional/setup | PASS | 14:53:53 10052165298138 0 |
The expected result is:
tests/os/functional/setup 1
Because my metadata is relatively small (no more than 20 MB, so I choose to use vector), the source code is as follows:
#include <iostream>#include <vector>#include <string>#include <fstream>#include <cstdlib>using namespace std;/** There are not split function, you should add one by yourself */vector<string> split(const string &str, string pattern){ string :: size_type pos; vector <string> result; int size = str.size(); int i = 0; for(i = 0; i < size; i++){ pos = str.find(pattern, i); if(pos < size){ string subStr = str.substr(i, pos - i);//substr(beginPosition, length) //cout<<"i = "<<i<<" ,pos - 1 = "<<pos - 1<<endl; //cout<<str.substr(i, pos - i)<<endl; result.push_back(subStr); i = pos + pattern.size() - 1; //cout<<subStr<<endl; //cout<<"i="<<i<<endl; } } return result;}/**Duration Time = endTime - startTime*eg: Duration Time = 1:10:08 - 23:08:08 = (25 * 3600 + 10 * 60 + 8) - (23 * 3600 + 8 * 60 + 7)*/int getDurationTime(string startTime, string endTime){vector<string> startTimeVector;vector<string> endTimeVector;int startTimeSeconds = 0;int endTimeSeconds = 0;startTime = startTime+":";//1:10:08 , if we do not add ":", we can not get 08 endTime = endTime + ":";endTimeVector = split(endTime, ":");startTimeVector = split(startTime, ":");startTimeSeconds = atoi(startTimeVector[0].c_str()) * 3600 + atoi(startTimeVector[1].c_str()) * 60 + atoi(startTimeVector[2].c_str());endTimeSeconds = atoi(endTimeVector[0].c_str()) * 3600 + atoi(endTimeVector[1].c_str()) * 60 + atoi(endTimeVector[2].c_str());if(endTimeSeconds < startTimeSeconds) {endTimeSeconds = endTimeSeconds + 24 * 3600;}//cout<<"endTimeSeconds:"<<endTimeSeconds << "startTimeSeconds:"<<startTimeSeconds<<endl;//cout<<endTimeSeconds - startTimeSeconds<<endl;return endTimeSeconds - startTimeSeconds; }int main(){ vector< pair<string, int> > caseDurationVec; string journalInput = "journal.base"; string journalOutput = "journal.base.out"; ifstream infile(journalInput.c_str()); ofstream outfile(journalOutput.c_str()); string buffer; const string Case_Start = "Test_Case_Start"; const string Case_End = "Test_Case_End"; int i = 0; vector<string> resultVec; string caseStartTime = ""; string caseEndTime = ""; while(getline(infile, buffer)){ if(buffer.find(Case_Start) != buffer.npos){ resultVec = split(buffer," "); caseStartTime = resultVec[4]; } if(buffer.find(Case_End) != buffer.npos){ resultVec = split(buffer," "); caseEndTime = resultVec[6]; caseDurationVec.push_back(make_pair<string, int>(resultVec[2], getDurationTime(caseStartTime, caseEndTime))); cout<<"There are "<<i++<<"cases"<<endl; } } vector< pair<string, int> > :: iterator iter; for(iter = caseDurationVec.begin(); iter != caseDurationVec.end(); iter++) { outfile<<iter->first<<" "<<iter->second<<endl; } infile.close(); outfile.close(); //system("pause"); return 1;}
Some people know how to use the C program to implement the multi-channel AD collection of the single-chip microcomputer C8051F350?
I am also doing this, but it is more complicated than you. It is USB port communication, not only to capture the temperature to the upper computer, but also to make the corresponding output according to the upper computer command. I told you that 10 days is not enough.
The C language defines an array with a length of 200. The value of the array is deleted after each sampling, while the fastest method for last collection is retained.
For (I = 0; I <200; I ++)
A [I] = a [I + 1];
A [200] = x; // the data entered after x
Sorry, I didn't see the previous