How can I parse the output of trace-cmd report using awk? - parsing

The only thing I need to see in the output is which functions were called.
Input:
ibv_rc_pingpong-759367 [005] 8391981.416466: funcgraph_entry: | ib_enum_all_devs() {
ibv_rc_pingpong-759367 [005] 8391981.416472: funcgraph_entry: + 29.337 us | ib_get_device_fw_str();
ibv_rc_pingpong-759367 [005] 8391981.416504: funcgraph_exit: + 38.787 us | }
ibv_rc_pingpong-759367 [005] 8391981.416543: funcgraph_entry: 1.191 us | ib_enum_all_devs();
ibv_rc_pingpong-759367 [005] 8391981.416621: funcgraph_entry: 1.371 us | ib_device_get_by_index();
ibv_rc_pingpong-759367 [005] 8391981.416624: funcgraph_entry: | ib_get_client_nl_info() {
ibv_rc_pingpong-759367 [005] 8391981.416628: funcgraph_entry: 0.890 us | ib_uverbs_get_nl_info();
ibv_rc_pingpong-759367 [005] 8391981.416630: funcgraph_exit: 6.174 us | }
The output should look like this:
ib_enum_all_devs() {
ib_get_device_fw_str();
}
ib_enum_all_devs();
ib_device_get_by_index();
ib_get_client_nl_info() {
ib_uverbs_get_nl_info();
}
This is what I tried:
cat myfile.dat | awk '{print $7}'
However, this gives me garbage.

Why don't you use the pipe character as a field separator?
cat myfile.dat | awk -F "|" '{print $2}'
... and as usual I've done a useless use of cat:
awk -F "|" '{print $2}' file.txt

You may use this awk:
awk -F ' \\| ' '{print $NF}' file
ib_enum_all_devs() {
ib_get_device_fw_str();
}
ib_enum_all_devs();
ib_device_get_by_index();
ib_get_client_nl_info() {
ib_uverbs_get_nl_info();
}

I would harness GNU AWK for this task following let file.txt
ibv_rc_pingpong-759367 [005] 8391981.416466: funcgraph_entry: | ib_enum_all_devs() {
ibv_rc_pingpong-759367 [005] 8391981.416472: funcgraph_entry: + 29.337 us | ib_get_device_fw_str();
ibv_rc_pingpong-759367 [005] 8391981.416504: funcgraph_exit: + 38.787 us | }
ibv_rc_pingpong-759367 [005] 8391981.416543: funcgraph_entry: 1.191 us | ib_enum_all_devs();
ibv_rc_pingpong-759367 [005] 8391981.416621: funcgraph_entry: 1.371 us | ib_device_get_by_index();
ibv_rc_pingpong-759367 [005] 8391981.416624: funcgraph_entry: | ib_get_client_nl_info() {
ibv_rc_pingpong-759367 [005] 8391981.416628: funcgraph_entry: 0.890 us | ib_uverbs_get_nl_info();
ibv_rc_pingpong-759367 [005] 8391981.416630: funcgraph_exit: 6.174 us | }
then
awk '{print substr($0, 84)}' file.txt
gives output
ib_enum_all_devs() {
ib_get_device_fw_str();
}
ib_enum_all_devs();
ib_device_get_by_index();
ib_get_client_nl_info() {
ib_uverbs_get_nl_info();
}
Explanation: you have file with fixed-width column, I simply use substr function to get part of whole line ($0) starting at 84th character.
(tested in GNU Awk 5.0.1)

Related

Docker Network: ERR_NAME_NOT_RESOLVED using FETCH API

Something weird is happening. I have this docker structure:
+------------------------+ +-------------------------+
| | | |
| | | |
| api_application | | |
| | | web_application |
| | | |
| | | |
| | | |
+------------------------+ +-------------------------+
| |
| |
| |
| |
+----------------------+
|
+
application_br
web_application - express.js
api_application - Flask
I make use of Fetch API in search.html and app.js, that last use node_fetch.
app.js example:
(async () => {
const body = req.body;
const response = await fetch('http://api_application:5000/auth', {
method: 'post',
body: JSON.stringify(body),
headers: {'Content-Type': 'application/json'}
});
const json = await response.json();
if(typeof(json)=="object"){
req.session.nome = json[0];
console.log("Logged");
res.redirect("/");
}else if(typeof(json)=="string"){
//Usuario Incorreto
console.log("Failed");
res.redirect('login');
}
})();
search.html:
<script>
fetch('http://api_application:5000/search/12345')
.then(response => response.json())
.then(data => console.log(data));
</script>
The Node_Fetch works fine, instead Fetch API (Javascript) I receive this error:
search:114 GET http://api_application:5000/search/52365
net::ERR_NAME_NOT_RESOLVED
Thats not make sense, because if I exec bash in web_application and execute curl http://api_application:5000/search/1233 I got the json response.
Ping between Containers - fine
Curl API from Web Container - fine
Is there some problem in Fetch API? Where am I wrong?

Symfony 3 & Doctrine - Complex form with OnetoMany and ManyToMany relation

I want to manage the rates of a product in multi-currency and keep historic of currency rates.
So onetomany relation:
A Rates can have many CurrencyRate.
A manyto many relation:
Many currencyRate have many currencies.
RATES :
+-----------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| rate | double | YES | | NULL | |
| timeStamp | datetime | NO | | NULL | |
| currencyRate_id | int(11) | YES | MUL | NULL | |
+-----------------+----------+------+-----+---------+----------------+
CURRENCY RATES
+-----------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| rate | double | NO | | NULL | |
| timeStamp | datetime | NO | | NULL | |
+-----------+----------+------+-----+---------+----------------+
currencyrateshascurrencies (manytomany join table)
+-----------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------+------+-----+---------+-------+
| currency_id | int(11) | NO | PRI | NULL | |
| currencyRate_id | int(11) | NO | PRI | NULL | |
+-----------------+---------+------+-----+---------+-------+
currencies
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | UNI | NULL | |
| abreviation | varchar(5) | NO | UNI | NULL | |
+-------------+--------------+------+-----+---------+----------------+
I want to generate a form from all of this.
The html form would get all available currencies with a text field to indicate the CurrencyRate.
Ex :
USD <input type="text">
EUR <input type="text">
CNY <input type="text">
...
I saw the documentation on Symfony about manytomany form. But mine is more complex with an additional onetomany relation and text field. I am totaly lost.
Thanks if you can put me on the right direction.
Best regards,
Pierre
I found the response :
First I needed to correct my Schema which didn't need a ManytoMany relation :
Rates :
+-----------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| rate | double | YES | | NULL | |
| timeStamp | datetime | NO | | NULL | |
+-----------+----------+------+-----+---------+----------------+
CURRENCY RATES
+-------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| ratio | double | NO | | NULL | |
| currency_id | int(11) | YES | MUL | NULL | |
| Rate_id | int(11) | YES | MUL | NULL | |
+-------------+---------+------+-----+---------+----------------+
Currencies
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | UNI | NULL | |
| abreviation | varchar(5) | NO | UNI | NULL | |
+-------------+--------------+------+-----+---------+----------------+
Then One Form Type
class CurrencyRateType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('currency',EntityType::class, array(
'class'=>'AppBundle:Currencies',
'choice_label' => 'abreviation',
'disabled' => true,
))
->add('ratio', TextType::class);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => CurrencyRates::class,
));
}
}
which is embedded in the final form type :
class RateType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder ->add('rate')
->add('CurrencyRate', CollectionType::class, array(
'entry_type' => CurrencyRateType::class,
'entry_options' => array('label' => false))
)
->add('save', SubmitType::class, array('label' => 'create'));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Rates::class,
));
}
}

Use split in as delimiter

I have many .txt file in one location. This txt content is as below.
%-ile | Read (ms) | Write (ms) | Total (ms)
----------------------------------------------
min | N/A | 0.018 | 0.018
25th | N/A | 0.055 | 0.055
50th | N/A | 0.059 | 0.059
75th | N/A | 0.062 | 0.062
90th | N/A | 0.070 | 0.070
95th | N/A | 0.073 | 0.073
99th | N/A | 0.094 | 0.094
3-nines | N/A | 0.959 | 0.959
4-nines | N/A | 67.552 | 67.552
5-nines | N/A | 75.349 | 75.349
6-nines | N/A | 84.994 | 84.994
7-nines | N/A | 85.632 | 85.632
I am reading 3-nines from above content and want to write a program like it Total (ms) column's value in greater than 1 with respect to 3-nines row it should print that file name.
For that I have written a program as below:
$data = get-content "*.txt" | Select-String -Pattern "3-nines"
$data | foreach {
$items = $_.split("|")
if ($items[0] -ge 1 ) {Echo $items[1]}
}
But getting below error.
Method invocation failed because [Microsoft.PowerShell.Commands.MatchInfo] doesn't contain a method named 'split'.
At line:2 char:18
+ $items = $_.split <<<< ("|")
+ CategoryInfo : InvalidOperation: (split:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Cannot index into a null array.
At line:3 char:12
+ if ($items[ <<<< 0] -lt 1 ) {Echo $items[1]}
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Could you please help here. I am very new to the powershell scripting.
Change
$items = $_.split("|")
to:
$items = ([string]$_).split("|")
The contents of the match is returned as an array and it doesn't have a split method. Casting it to a string will give you the split method.
Update: To print the filename you have to change the script a bit since the current input for Select-String is an array so you loose the filename:
Select-String -Pattern "3-nines" -Path "*.txt" | foreach {
$items = ([string]$_).split("|")
if ([double]$items[3] -ge 1 ) {
Write-Output "FileName: $($_.Filename)"
Echo $items[3]
}
}
First of all - why would you pipe to Select-String here? You can use -Path parameter and pass *.txt directly to it.
The reason split doesn't work is because you should call it agains Line property of [Microsoft.PowerShell.Commands.MatchInfo] object. I guess what you need there is a simple Where-Object:
Select-String -Pattern 3-nines -Path *.txt |
Where-Object { [double]($_.line.Split('|')[-1]) -gt 1 } |
Select-Object Path, Line
Alternatively, you can turn content of the file into objects with Import-Csv cmdlet:
foreach ($file in Get-ChildItem -Path *.txt) {
# Existing headers are terrible - replacing them...
$3nines = Import-Csv -Path $file.FullName -Delimiter '|' -Header Percent, Read, Write, Total |
Where-Object Percent -match 3-nines
if ([double]$3nines.Total -gt 1) {
$3nines | Select-Object *, #{
Name = 'Path'
Expression = { $file.FullName }
}
}
}

Invalid Variant Operation using MS Word OLE Automation only on one specific machine

I am doing some search replace work using OLE Automation. The involved code is somehow the same I posted in This question.
On only one machine I have an "Invalid Variant Operation" error. This error appeared just after upgrading from MSOffice 2003 to 2010. But this occurs only on one pc, i tested on several pcs with office 2010 and the code works great.
I am really stuck, I tried to build with Eureka log And I will paste the call stack at the end of this question.
I hope somebody already stumbled into this problem so you can suggest.
The problem occured at a customer end, there are 100 machines connected to same DB and only on one it doesn't work.
Call Stack Information:
--------------------------------------------------------------------------------------------------
|Address |Module |Unit |Class |Procedure/Method |Line |
--------------------------------------------------------------------------------------------------
|*Exception Thread: ID=776; Priority=0; Class=; [Main] |
|------------------------------------------------------------------------------------------------|
|0043554F|Project1.exe|SysUtils.pas| |DoneExceptions |17031[25]|
|00435520|Project1.exe|SysUtils.pas| |DoneExceptions |17031[25]|
|00435CAA|Project1.exe|SysUtils.pas| |DoneExceptions |17031[25]|
|770F48F0|oleaut32.dll | | |VariantClear | |
|00435B43|Project1.exe|SysUtils.pas| |DoneExceptions |17031[25]|
|0043590C|Project1.exe|SysUtils.pas| |DoneExceptions |17031[25]|
|00435B48|Project1.exe|SysUtils.pas| |DoneExceptions |17031[25]|
|00435BE4|Project1.exe|SysUtils.pas| |DoneExceptions |17031[25]|
|00407316|Project1.exe|System.pas | |_HandleFinally |14330[39]|
|00407460|Project1.exe|System.pas | |_RaiseExcept |14712[1] |
|00635EED|Project1.exe|ComObj.pas | |DispCallError |2024[13] |
|004070DA|Project1.exe|System.pas | |_HandleAnyException |13728[81]|
|77E256A3|RPCRT4.dll | | |NdrClientCall2 | |
|7C80A174|kernel32.dll | | |WideCharToMultiByte | |
|0040C4DB|Project1.exe|System.pas | |LocaleCharsFromUnicode |29632[1] |
|0040C4C0|Project1.exe|System.pas | |LocaleCharsFromUnicode |29631[0] |
|00407EFC|Project1.exe|System.pas | |CharFromWChar |17375[3] |
|00407EDC|Project1.exe|System.pas | |CharFromWChar |17372[0] |
|00407F17|Project1.exe|System.pas | |CharFromWChar |17381[1] |
|00407F08|Project1.exe|System.pas | |CharFromWChar |17380[0] |
|004090CE|Project1.exe|System.pas | |_UStrToString |22054[8] |
|00404DA4|Project1.exe|System.pas | |Move |4808[1] |
|004090ED|Project1.exe|System.pas | |_UStrToString |22061[15]|
|7C920380|ntdll.dll | | |RtlImageNtHeader | |
|00407460|Project1.exe|System.pas | |_RaiseExcept |14712[1] |
|00635EED|Project1.exe|ComObj.pas | |DispCallError |2024[13] |
|004070DA|Project1.exe|System.pas | |_HandleAnyException |13728[81]|
|00407460|Project1.exe|System.pas | |_RaiseExcept |14712[1] |
|00635EED|Project1.exe|ComObj.pas | |DispCallError |2024[13] |
|7C913247|ntdll.dll | | |RtlConvertUlongToLargeInteger| |
|00404A95|Project1.exe|System.pas | |_ReallocMem |3871[22] |
|00404A88|Project1.exe|System.pas | |_ReallocMem |3850[1] |
|00409130|Project1.exe|System.pas | |_UStrSetLength |22152[27]|
|00408198|Project1.exe|System.pas | |_UStrAsg |17715[1] |
|0040C3EF|Project1.exe|System.pas | |UTF8ToUnicodeString |28576[11]|
|00407DB8|Project1.exe|System.pas | |_UStrClr |16954[1] |
|0040C404|Project1.exe|System.pas | |UTF8ToUnicodeString |28577[12]|
|7C91E485|ntdll.dll | | |KiUserApcDispatcher | |
|7C912B04|ntdll.dll | | |RtlInterlockedPushListSList | |
|77E943DB|SHLWAPI.dll | | |SHRegGetValueW | |
|77E943E8|SHLWAPI.dll | | |SHRegGetValueW | |
|00407460|Project1.exe|System.pas | |_RaiseExcept |14712[1] |
|00635EED|Project1.exe|ComObj.pas | |DispCallError |2024[13] |
|00635E48|Project1.exe|ComObj.pas | |DispCallError |2011[0] |
|00635F20|Project1.exe|ComObj.pas | |DispatchInvokeError |2031[1] |
|00635F1C|Project1.exe|ComObj.pas | |DispatchInvokeError |2031[1] |
|00635BF9|Project1.exe|ComObj.pas | |DispatchInvoke |1895[108]|
|00635940|Project1.exe|ComObj.pas | |DispatchInvoke |1787[0] |
|00635E3B|Project1.exe|ComObj.pas | |VarDispInvoke |2002[10] |
|774CF17D|ole32.dll | | |CoCreateInstanceEx | |
|77E25AE5|RPCRT4.dll | | |IUnknown_Release_Proxy | |
|00435C7A|Project1.exe|SysUtils.pas| |DoneExceptions |17031[25]|
|00435BE4|Project1.exe|SysUtils.pas| |DoneExceptions |17031[25]|
|004627DF|Project1.exe|Classes.pas |TThread |Create |11471[28]|
|004627D0|Project1.exe|Classes.pas |TThread |Create |11471[28]|
|00501FE5|Project1.exe|ActnList.pas|TContainedAction|Execute |448[8] |
|00501FB4|Project1.exe|ActnList.pas|TContainedAction|Execute |440[0] |
|00502DA0|Project1.exe|ActnList.pas|TCustomAction |Execute |1094[7] |
|00406498|Project1.exe|System.pas | |_CallDynaInst |11592[1] |
|004626A3|Project1.exe|Classes.pas |TThread |Create |11471[28]|
|00532DA4|Project1.exe|Menus.pas |TMenuItem |Click |2525[17] |

Error Copying DBF/MDX files

I use the following code to copy dbf/mdx files from one folder to another:
procedure TfrmMain.MyCopyFile(S1, S2: string);
begin
if not FileExists(S2) then
CopyFile(PCHAR(S1), PCHAR(S2), true)
else
if Application.MessageBox(PCHAR('Overwrite existing file ' + S2 + '?'), 'File exists in folder',MB_YESNO + MB_DEFBUTTON1) = IDYES
then CopyFile(PCHAR(S1), PCHAR(S2), false)
end;
The code works fine when table name stays the same.
If I change the name of the table:
MyCopyFile(CurPath + '\orders.dbf', NewPath + '\ordly.dbf');
MyCopyFile(CurPath + '\orders.mdx', NewPath + '\ordly.mdx');
When I try to open ordly.dbf I get an error message:
Corrupt table/index header.
File: C:\DATA\2011\ORDLY.MDX
the problem is due to the mdx format stores inside the name of the data file associated (table name). because that when you rename a mdxfile the index still points to the old name of data file.
check this link to see the structure of the mdx file.
The Structure of Multiple Index files (*.mdx)
0 | Version number *1| ^
|-----------------------| |
1 | Date of creation | |
2 | YYMMDD | |
3 | | |
|-----------------------| |
4 | Data file name | File
5 | (no extension) | Header
: : |
: : |
19 | | |
|-----------------------| |
20 | Block size | |
| | |
|-----------------------| |
22 | Block size adder N | |
| | |
|-----------------------| |
24 | Production index flag | |
|-----------------------| |
25 | No. of entries in tag | | *2
|-----------------------| |
26 | Length of tag | | *3
|-----------------------| |
27 | (Reserved) | |
|-----------------------| |
28 | No.of tags in use | |
| | |
|-----------------------| |
30 | (Reserved) | |
| | |
|-----------------------| |
32 | No.of pages in tagfile| |
| | |
| | |
35 | | |
|-----------------------| |
36 | Pointer to first free | |
| page | |
| | |
39 | | |
|-----------------------| |
40 | No.of block available | |
| | |
| | |
43 | | |
|-----------------------| |
44 | Date of last update | |
| YYMMDD | |
46 | | |
|-----------------------| |
47 | (Reserved) | |
|-----------------------| |
48 | (Garbage) | |
: : |
: : |
| | | ___|=======================|
543| | _V___ / 0 | Tag header page no. |
|-----------------------| | / | |
544| Tag table entries | Tag / | |
| | Table | 3 | |
:.......................: | | |-----------------------| Tag
: : | | 4 | Tag name | table
:.......................: | | : :
: : | / : :
: : | / | |
:.......................:__|_/ 14 | |
: : | |-----------------------|
: : | 15 | Key format *4 |
: : | |-----------------------|
:.......................:__|_ 16 | Forward tag thread (<)|
: : | \ |-----------------------|
: : | \ 17 | Forward tag thread (>)|
: : | \ |-----------------------|
: : | | 18 | Backward tag thread *5|
| | | | |-----------------------|
| | | | 19 | (Reserved) |
M*N| |__V__ | |-----------------------|
|=======================| ^ | 20 | Key type *6 |
0| Pointer to root page | | | |-----------------------|
| | | | 21 | (Reserved) |
| | | | : :
3| | | | : :
|-----------------------| | | 31 | |
4| File size in pages | Tag | |-----------------------|
| | header| 32 | (Garbage) |
| | | | : :
7| | | | | |
|-----------------------| | \ N | |
8| Key format *7 | | \____|=======================|
|-----------------------| |
9| Key type *8 | |
|-----------------------| |
10| (Reserved) | |
| | |
|-----------------------| |
12| Index key length *9 | |
| | |
|-----------------------| |
14| Max.no.of keys/page | |
| | |
|-----------------------| |
16| Secondary key type *10| |
| | |
|-----------------------| |
18| Index key item length | |
| | |
|-----------------------| |
20| (Reserved) | |
| | |
| | |
|-----------------------| |
23| Unique flag | |
|-----------------------| |
| | |
: : |
: :__V__
N*M|=======================|

Resources