Pycharm添加函数说明文档

Pycharm 为函数添加函数文档注释

将光标移动到需要添加注释的函数名上后,会在左上角出现一个小灯泡的图标,点击后选择【Insert documentation string stub】,就能自动对函数的参数类型进行添加注释。

如果没有【Insert documentation string stub】选项,需要将File -> Settings -> Build,Execution,Deployment -> Python Debugger -> Collect run-time types information for code insight 和 File -> Settings -> Editor -> Smart Keys -> JSON -> Insert type placeholders in the documentation comment stub勾选上。

Collectl

collectl监控系统性能

collectl运行需要Perl,大部分的发行版都是默认安装的,只需要运行apt/yum就可以完成安装。也可以从 官网 下载源码编译安装。

collectl几乎可以监控所有子系统,包括buddyinfo,cpu,disk,inode,infiniband,lustre,memory,network,nfs,processes,quadrics,slabs,socket和tcp。
无参数运行collectl将会以简短格式显示CPU、Disk、Network的统计信息:

1
2
3
4
5
6
7
8
9
10
11
[root@centos ~]# collectl
waiting for 1 second sample...
#<--------CPU--------><----------Disks-----------><----------Network---------->
#cpu sys inter ctxsw KBRead Reads KBWrit Writes KBIn PktIn KBOut PktOut
0 0 189 402 0 0 0 0 0 1 0 0
1 0 216 421 0 0 0 0 0 6 1 4
5 1 272 448 0 0 0 0 1 14 11 11
1 1 208 423 0 0 52 7 0 4 0 2
1 0 199 410 0 0 0 0 0 4 0 2
0 0 197 407 0 0 0 0 0 2 1 2
2 1 190 395 0 0 0 0 0 4 0 2

collectl -sjmf -oT 在写入NFS安裝的文件系统时,以简短格式显示中断,內存使用和带时间戳的nfs活动:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@centos ~]# collectl -sjmf -oT 
waiting for 1 second sample...
# <Int-><-----------Memory-----------><------NFS Totals------>
#Time Cpu0 Free Buff Cach Inac Slab Map Reads Writes Meta Comm
10:22:39 438 444M 777M 311M 483M 189M 287M 0 0 0 0
10:22:40 454 444M 777M 311M 483M 189M 287M 0 0 0 0
10:22:41 540 444M 777M 311M 483M 189M 287M 0 0 0 0
10:22:42 464 444M 777M 311M 483M 189M 287M 0 0 0 0
10:22:43 432 444M 777M 311M 483M 189M 287M 0 0 0 0
10:22:44 470 444M 777M 311M 483M 189M 287M 0 0 0 0
10:22:45 454 444M 777M 311M 483M 189M 287M 0 0 0 0
10:22:46 466 444M 777M 311M 483M 189M 287M 0 0 0 0
10:22:47 470 444M 777M 311M 483M 189M 287M 0 0 0 0
10:22:48 412 444M 777M 311M 483M 189M 287M 0 0 0 0

还可以以详细格式显示相同的信息,在这种情况下,可以为每种类型的数据获取单行,代价是更多的屏幕空间:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@centos ~]# collectl -sn --verbose -oT #NETWORK 
waiting for 1 second sample...

# NETWORK SUMMARY (/sec)
#Time KBIn PktIn SizeIn MultI CmpI ErrsI KBOut PktOut SizeO CmpO ErrsO
10:29:01 0 1 40 0 0 0 0 1 138 0 0
10:29:02 0 5 44 0 0 0 0 3 142 0 0
10:29:03 0 5 44 0 0 0 1 3 362 0 0
10:29:04 4 14 350 0 0 0 2 16 147 0 0
10:29:05 0 5 44 0 0 0 0 2 131 0 0
10:29:06 0 2 40 0 0 0 0 2 506 0 0
10:29:07 0 4 45 0 0 0 0 2 131 0 0
10:29:08 0 4 45 0 0 0 0 2 131 0 0
10:29:09 0 16 54 0 0 0 10 11 957 0 0
10:29:10 0 4 45 0 0 0 0 2 131 0 0

常用参数:

1
2
3
4
5
6
7
8
9
10
11
12
13
b – buddyinfo (内存碎片)
c – CPU
d – Disk
f – NFS
i – Inode
j – Interrupts
l – Lustre
m – Memory
n – Networks
s – Sockets
t – TCP
x – Interconnect
y – Slabs (系统对象缓存)

Python查询列表内重复值的下标

Python查询列表内重复值的下标

1
2
3
4
5
6
7
8
9
10
11
12
13
#将返回seq内所有值为item项的下标
$ def listDuplicate(seq, item):
startIndex = -1
strIndexs = []
while True:
try:
strIndex = seq.index(item,startIndex+1)
except ValueError:
break
else:
strIndexs.append(strIndex)
startIndex = strIndex
return strIndexs