1 /* 2 * This program is free software; you can redistribute it and/or modify 3 * it under the terms of the GNU General Public License, version 2, as 4 * published by the Free Software Foundation. 5 * 6 * Copyright (C) 2017 Hari Bathini, IBM Corporation 7 */ 8 9 #include "namespaces.h" 10 #include "util.h" 11 #include "event.h" 12 #include <stdlib.h> 13 #include <stdio.h> 14 #include <string.h> 15 16 struct namespaces *namespaces__new(struct namespaces_event *event) 17 { 18 struct namespaces *namespaces; 19 u64 link_info_size = ((event ? event->nr_namespaces : NR_NAMESPACES) * 20 sizeof(struct perf_ns_link_info)); 21 22 namespaces = zalloc(sizeof(struct namespaces) + link_info_size); 23 if (!namespaces) 24 return NULL; 25 26 namespaces->end_time = -1; 27 28 if (event) 29 memcpy(namespaces->link_info, event->link_info, link_info_size); 30 31 return namespaces; 32 } 33 34 void namespaces__free(struct namespaces *namespaces) 35 { 36 free(namespaces); 37 } 38