在本文中,我们将给您介绍关于on_member_join事件discord.py的详细内容,并且为您解答j-com事件的相关问题,此外,我们还将为您提供关于#definelist_entry(ptr,
在本文中,我们将给您介绍关于on_member_join 事件 discord.py的详细内容,并且为您解答j-com事件的相关问题,此外,我们还将为您提供关于#define list_entry(ptr, type, member) \ container_of(ptr, type, member)、c# – ComboBox.ValueMember和DisplayMember、c# – 如何将ComboBox绑定到具有深DisplayMember和ValueMember属性的通用List?、container_memory_rss & container_memory_working_set_bytes的知识。
本文目录一览:- on_member_join 事件 discord.py(j-com事件)
- #define list_entry(ptr, type, member) \ container_of(ptr, type, member)
- c# – ComboBox.ValueMember和DisplayMember
- c# – 如何将ComboBox绑定到具有深DisplayMember和ValueMember属性的通用List?
- container_memory_rss & container_memory_working_set_bytes
on_member_join 事件 discord.py(j-com事件)
听起来你需要意图。
您需要在 bot
的定义上方添加此代码:
intents = discord.Intents.default()
intents.members = True
现在,将 intents=intents
参数添加到意图位下方的机器人初始化中:
intents = discord.Intents.default()
intents.members = True
# If you have commands.Bot,add `intents = intents` in the parentheses:
bot = commands.Bot(your_options_here,intents = intents)
# If you have discord.Client(),add `intents = intents` into the parentheses:
bot = discord.Client(intents = intents)
确保在 developer portal 中启用成员意图。 您可以详细了解意图here。
#define list_entry(ptr, type, member) \ container_of(ptr, type, member)
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
该宏在 Linux 内核代码 (版本 2.6.22) 中定义如下:
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER);
分析:
(TYPE *) 0, 将 0 强制转换为 TYPE 型指针,记 p = (TYPE *) 0,p 是指向 TYPE 的指针,它的值是 0。那么 p->MEMBER 就是 MEMBER 这个元素了,而 &(p->MEMBER) 就是 MENBER 的地址,而基地址为 0,这样就巧妙的转化为了 TYPE 中的偏移量。再把结果强制转 换为 size_t 型的就 OK 了,size_t 其实也就是 int。
typedef __kernel_size_t size_t;
typedef unsigned int __kernel_size_t;
可见,该宏的作用就是求出 MEMBER 在 TYPE 中的偏移量。
关于 typeof, 这是 gcc 的 C 语言扩展保留字,用于声明变量类型.
const typeof (((type *) 0->member ) *__mptr = (ptr); 意思是声明一个与 member 同一个类型的指针常量 *__mptr, 并初始化为 ptr. 也就是该数据结构体中通用链表成员变量的地址。即 member 的入口地址
(type *)( (char *)__mptr - offsetof (type,member) ); 意思是__mptr 的地址减去 member 在该 struct 中的偏移量得到的地址,再转换成 type 型指针。该指针就是 member 的入口地址了.
在一个数据结构体变量中,通用链表结构体成员变量所在的地址(也就是 member 的入口地址)减去通用链表结构体成员变量在该数据结构体变量中的在偏移量,得到的结果就是该数据结构体变量的入口地址。
通用链表的应用实例:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/list.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("David Xie");
MODULE_DESCRIPTION("List Module");
MODULE_ALIAS("List module");
struct student
{
char name[100];
int num;
struct list_head list;
};
struct student *pstudent;
struct student *tmp_student;
struct list_head student_list;
struct list_head *pos;
int mylist_init(void)
{
int i = 0;
INIT_LIST_HEAD(&student_list);
pstudent = kmalloc(sizeof(struct student)*5,GFP_KERNEL);
memset(pstudent,0,sizeof(struct student)*5);
for(i=0;i<5;i++)
{
sprintf(pstudent[i].name,"Student%d",i+1);
pstudent[i].num = i+1;
list_add( &(pstudent[i].list), &student_list);
}
list_for_each(pos,&student_list)
{
tmp_student = list_entry(pos,struct student,list);
printk("<0>student %d name: %s\n",tmp_student->num,tmp_student->name);
}
return 0;
}
void mylist_exit(void)
{
int i ;
/* 实验:将for换成list_for_each来遍历删除结点,观察要发生的现象,并考虑解决办法 */
for(i=0;i<5;i++)
{
list_del(&(pstudent[i].list));
}
kfree(pstudent);
}
module_init(mylist_init);
module_exit(mylist_exit);
c# – ComboBox.ValueMember和DisplayMember
我试过了
ComboBox1.DataSource = dataTable; ComboBox1.ValueMember = "id"; // --> once hes here,he just jumps out the method ComboBox1.displayMember = "name";
没有编译错误,警告,没有..只是跳出来!
这是填充DataTable的查询
"Select * from \"Table\""
我检查了调试器并填充了数据表.列名称是“id”和“name”. ComboBox是空白的.我第一次填写它!
解决方法
ComboBox1.DataSource = dataTable; ComboBox1.ValueMember = "id"; ComboBox1.displayMember = "name";
相反,这是正确的顺序:
ComboBox1.ValueMember = "id"; ComboBox1.displayMember = "name"; ComboBox1.DataSource = dataTable;
注意:设置数据源应该是最后一行.
如果先设置datasource,则会触发SelectedindexChanged事件,您可能会收到强制转换错误或其他异常.
c# – 如何将ComboBox绑定到具有深DisplayMember和ValueMember属性的通用List?
public Form1() { InitializeComponent(); List<Parent> parents = new List<Parent>(); Parent p = new Parent(); p.child = new Child(); p.child.displayMember="SHOW THIS"; p.child.ValueMember = 666; parents.Add(p); comboBox1.displayMember = "child.displayMember"; comboBox1.ValueMember = "child.ValueMember"; comboBox1.DataSource = parents; } } public class Parent { public Child child { get; set; } } public class Child { public string displayMember { get; set; } public int ValueMember { get; set; } }
当我运行我的测试应用程序时,我只看到:“ComboBindingToListTest.Parent”显示在我的ComboBox中,而不是“显示它”.
如何通过一个级别或更深层的属性将ComboBox绑定到通用列表,例如child.displayMember?
提前致谢,
阿道夫
解决方法
无论父级是否可以拥有多个子级,我建议您使用匿名类型作为组合框的数据源,并使用linq填充该类型.这是一个例子:
private void Form1_Load(object sender,EventArgs e) { List<Parent> parents = new List<Parent>(); Parent p = new Parent(); p.child = new Child(); p.child.displayMember = "SHOW THIS"; p.child.ValueMember = 666; parents.Add(p); var children = (from parent in parents select new { displayMember = parent.child.displayMember,ValueMember = parent.child.ValueMember }).ToList(); comboBox1.displayMember = "displayMember"; comboBox1.ValueMember = "ValueMember"; comboBox1.DataSource = children; }
container_memory_rss & container_memory_working_set_bytes
背景
客户使用我们的产品,我们产品默认监控内存使用的container_memory_working_set_bytes相关,后来一个同事的建议下,客户改为container_memory_rss相关,最近接手这个项目,客户问我这俩有啥区别。
简介
- container_memory_rss:
- 指标名称:container_memory_rss
- 指标类型:Gauge(表示某一时刻的数值)
- 解析逻辑:该指标使用了Linux的/proc文件系统,读取了容器进程的/proc/[PID]/statm文件,其中PID是容器进程的进程ID。在该文件中,第2列表示进程的Resident Set Size (RSS),即实际驻留在物理内存中的大小。Prometheus的采集器会定期读取这个值,并将其暴露为container_memory_rss指标。
- container_memory_working_set_bytes:
- 指标名称:container_memory_working_set_bytes
- 指标类型:Gauge
- 解析逻辑:类似于container_memory_rss,该指标也使用了Linux的/proc文件系统,读取了容器进程的/proc/[PID]/statm文件。在该文件中,第6列表示进程的Working Set Size,即进程当前使用的物理内存大小。Prometheus的采集器会定期读取这个值,并将其暴露为container_memory_working_set_bytes指标。
man手册
/proc/[pid]/statm
- size:表示进程的虚拟内存空间大小(以页面为单位)。它包括进程代码段、数据段、堆、栈和共享库等。
- resident:表示进程当前驻留在物理内存中的页面数量(以页面为单位)。它指示进程当前实际使用的物理内存量。
- shared:表示进程使用的共享内存的页面数量(以页面为单位)。共享内存是多个进程之间共享的内存区域。
- data:表示进程数据段的页面数量(以页面为单位)。数据段包含了进程的全局变量、静态变量和堆分配的动态数据等。
注:单位页:OS默认一页4KB。
/proc/[pid]/status
(内容太多,截取了相关部分)
从简介和man手册中我们可以得出
container_memory_rss == VmRSS
container_memory_working_set_bytes == data
linux内存说明
理解VIRT、RES、data
让我们先抛开上面的内容,来了解下linux中的内存,那么上面的东西也就呼之欲出了。
我们来看下面的命令和几个名词
[root@cubblestone ~]# ps -aux | egrep "USER|3769" | grep -v grep
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 3769 1.1 3.1 1065188 64960 ? Sl May15 324:56 /usr/local/qcloud/YunJing/YDEyes/YDService
[root@cubblestone ~]# top -b -n1 | egrep "USER|3769"
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3769 root 20 0 1065188 65756 13556 S 0.0 3.2 324:57.70 YDService
[root@cubblestone ~]# cat /proc/3769/statm
266297 16439 3389 6073 0 251356 0
VIRT
(Virtual Memory Size,虚拟内存大小):VIRT表示进程可寻址的虚拟内存的总量,包括实际内存和虚拟内存(如共享库、映射文件等)。VIRT的值可能会比实际系统可用内存大,因为它包括了虚拟内存的总和。
VSZ
VIRT的旧称,实际是一个概念。
RES
(Resident Set Size,常驻集合大小):RES表示进程当前使用的实际物理内存的大小。它只计算进程实际占用的物理内存部分,不包括虚拟内存的部分。
RSS
RES的旧称,实际是一个概念。
data
字段表示进程数据段的页面数量,即进程已分配的数据段的大小。数据段包含了进程的全局变量、静态变量和堆分配的动态数据等。可以理解为数据段已申请的内存大小。
举例:当程序向OS申请100M内存,但实际只使用了10M时,那么VIRT增加了100M,RES增加了10M,而data的增长位于10M~100M之间。
小结:VIRT代表总的已申请的虚拟内存,包括数据段,共享库等。data表示数据段已申请的总内存。而RES表示实际占用物理的内存。所以,VIRT包含data,data包含RES。
所以真实的内存我们参考RES而不是VIRT和data,也就是container_memory_rss。
总结
监控的时候,如果想了解进程使用的实际内存,请参考container_memory_rss,即RES。
container_memory_rss == VmRSS == RSS = RES
container_memory_working_set_bytes == data
我们今天的关于on_member_join 事件 discord.py和j-com事件的分享就到这里,谢谢您的阅读,如果想了解更多关于#define list_entry(ptr, type, member) \ container_of(ptr, type, member)、c# – ComboBox.ValueMember和DisplayMember、c# – 如何将ComboBox绑定到具有深DisplayMember和ValueMember属性的通用List?、container_memory_rss & container_memory_working_set_bytes的相关信息,可以在本站进行搜索。
本文标签: