Skip to content

Commit

Permalink
#85 platform/pallas#886 profile展示总时间,且按总时间排序
Browse files Browse the repository at this point in the history
  • Loading branch information
gier.cai committed Jun 27, 2019
1 parent 882bc2b commit 0a82761
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<el-collapse-item v-for="item in profileData.profile.shards" :key="item.id" :name="item.id">
<template slot="title">
<span style="font-weight: bold;font-size: 14px;">{{item.id.replace(/(\[.*\])(\[.*\])(\[.*\])/g, "$1$3")}}</span>
<span style="margin-right: 10px;" class="pull-right">{{item.totalTime}}ms</span>
</template>
<div class="profile-tree">
<div class="profile-tree-th">
Expand Down Expand Up @@ -41,7 +42,7 @@ export default {
[
h('span', { class: { 'profile-tree-type': true } }, data.type),
h('span', { class: { 'profile-tree-desc': true }, attrs: { title: data.description } }, data.description.length > 30 ? `${data.description.substring(0, 30)}...` : data.description),
h('span', { class: { 'pull-right': true, 'profile-tree-time': true } }, data.time.replace(/([0-9]+\.[0-9]{3})[0-9]*/, '$1')),
h('span', { class: { 'pull-right': true, 'profile-tree-time': true } }, `${Number(data.time.replace(/([0-9]+\.[0-9]*)ms/, '$1')).toFixed(3)}ms`),
],
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ export default {
isTemplateInsertVisible: false,
profileData: {
profile: {
shards: [{
searches: [],
}],
shards: [],
},
},
isProfileVisible: false,
Expand All @@ -210,7 +208,15 @@ export default {
if (data.substring(2, 7) === 'error') {
this.resultContent = JSON.stringify(JSON.parse(data), undefined, 2);
} else {
this.profileData = JSON.parse(data);
const resultData = JSON.parse(data);
this.profileData.profile.shards = resultData.profile.shards.map((obj) => {
const rObj = { ...obj };
const totalNum = obj.searches[0].query.reduce((accumulator, currentValue) =>
accumulator + Number(currentValue.time.replace(/([0-9]+\.[0-9]*)ms/, '$1')), 0);
rObj.totalTime = totalNum.toFixed(3);
return rObj;
});
this.profileData.profile.shards.sort((a, b) => Number(b.totalTime) - Number(a.totalTime));
this.isProfileVisible = true;
}
})
Expand Down

0 comments on commit 0a82761

Please sign in to comment.